:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --fg: #15202b;
  --muted: #5b6b7a;
  --card: #ffffff;
  --border: #d9e0e6;
  --accent: #e0662b;
  --ok: #1f7a4d;
  --btn: #ffffff;
  --btn-active: #15202b;
  --btn-active-fg: #ffffff;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.12);
  --map-ocean: #cfe4f2;
  --map-land: #f1ece0;
  --map-border: #b9b19c;
  --map-visited: #3fa88f;
  --map-visited-border: #1f6f5c;
  --map-grid: rgb(40 80 120 / 0.14);
  --map-glow: rgb(110 170 230 / 0.55);
  --map-dot: rgb(90 90 90 / 0.4);
  --map-dot-visited: #2f8f78;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f151b;
    --fg: #e6edf3;
    --muted: #8b9aa8;
    --card: #17202a;
    --border: #2a3643;
    --accent: #ff9255;
    --ok: #4cc38a;
    --btn: #17202a;
    --btn-active: #e6edf3;
    --btn-active-fg: #0f151b;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.5);
    --map-ocean: #12283a;
    --map-land: #2c3540;
    --map-border: #46535f;
    --map-visited: #2fa88b;
    --map-visited-border: #8be0c8;
    --map-grid: rgb(150 190 230 / 0.1);
    --map-glow: rgb(80 140 220 / 0.45);
    --map-dot: rgb(200 210 220 / 0.35);
    --map-dot-visited: #5fe0bd;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f151b;
  --fg: #e6edf3;
  --muted: #8b9aa8;
  --card: #17202a;
  --border: #2a3643;
  --accent: #ff9255;
  --ok: #4cc38a;
  --btn: #17202a;
  --btn-active: #e6edf3;
  --btn-active-fg: #0f151b;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.5);
  --map-ocean: #12283a;
  --map-land: #2c3540;
  --map-border: #46535f;
  --map-visited: #2fa88b;
  --map-visited-border: #8be0c8;
  --map-grid: rgb(150 190 230 / 0.1);
  --map-glow: rgb(80 140 220 / 0.45);
  --map-dot: rgb(200 210 220 / 0.35);
  --map-dot-visited: #5fe0bd;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

h1 { margin: 0; font-size: 1.25rem; }
h2 { margin: 0 0 0.4rem; font-size: 1rem; }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; }

.field { display: flex; flex-direction: column; font-size: 0.72rem; color: var(--muted); gap: 2px; }

select, button {
  font: inherit;
  color: var(--fg);
  background: var(--btn);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  min-height: 36px;
}

button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: 0;
}

.map-wrap {
  position: relative;
  height: 62vh;
  height: 62dvh;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
}

#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
#map:focus-visible { outline-offset: -3px; }

.map-tools { position: absolute; display: flex; gap: 6px; }
.map-tools.mode { top: 10px; left: 10px; }
.map-tools.zoom { top: 10px; right: 10px; flex-direction: column; }
.map-tools button { box-shadow: var(--shadow); min-width: 40px; min-height: 40px; }
.map-tools.mode button { padding: 0.35rem 0.8rem; }
.map-tools button[aria-pressed="true"] { background: var(--btn-active); color: var(--btn-active-fg); border-color: var(--btn-active); }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--btn-active);
  color: var(--btn-active-fg);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
  z-index: 2;
}

.message {
  position: absolute;
  inset: auto 1rem 1rem 1rem;
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sidebar { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin: 0; }
.stat { min-width: 0; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.4rem 0.5rem; box-shadow: var(--shadow); }
.stat dt { font-size: 0.7rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.stat dd { margin: 0; white-space: nowrap; }
.stat strong { font-size: 1.25rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.8rem; box-shadow: var(--shadow); }
.card p { margin: 0.2rem 0; }
.muted { color: var(--muted); }
.status.yes { color: var(--ok); font-weight: 600; }
.status.no { color: var(--muted); }

.visited-list { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow: auto; }
.place {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0.3rem 0.4rem;
  min-height: 34px;
}
.place:hover, .place.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.place .y { color: var(--muted); font-size: 0.85rem; text-align: right; }

.footnote { margin: 0; font-size: 0.75rem; color: var(--muted); }

@media (min-width: 900px) {
  body { height: 100dvh; }
  .layout { grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr); }
  .map-wrap { height: 100%; }
  .sidebar { overflow: auto; }
  .visited-list { max-height: none; }
}

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .controls { width: 100%; }
  .field { flex: 1; }
  select { width: 100%; }
}
