:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #5f6b7a;
  --border: #d9dee5;
  --accent: #1f7a6f;
  --accent-strong: #145a51;
  --continent: #9fd8cf;
  --land: #e6e9ee;
  --sea: #eaf3fb;
  --danger: #b42318;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111820;
    --card: #1a232d;
    --text: #e6edf3;
    --muted: #9aa7b5;
    --border: #2c3a48;
    --accent: #3fb8a6;
    --accent-strong: #6fd6c5;
    --continent: #2d5d57;
    --land: #2a3541;
    --sea: #15202a;
    --danger: #f97066;
  }
}

:root[data-theme="dark"] {
  --bg: #111820;
  --card: #1a232d;
  --text: #e6edf3;
  --muted: #9aa7b5;
  --border: #2c3a48;
  --accent: #3fb8a6;
  --accent-strong: #6fd6c5;
  --continent: #2d5d57;
  --land: #2a3541;
  --sea: #15202a;
  --danger: #f97066;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Top bar ----------------------------------------------------------- */

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

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.view-tabs {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.view-tabs button {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 16px;
  font: inherit;
  cursor: pointer;
}

.view-tabs button.active {
  background: var(--accent);
  color: #fff;
}

/* --- Layout ------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px 16px;
  }
}

.card,
.map-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h2,
.map-card h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.count {
  color: var(--muted);
  font-weight: normal;
  font-size: 0.9rem;
}

/* --- Map --------------------------------------------------------------- */

.map-wrap {
  position: relative;
  background: var(--sea);
  border-radius: 6px;
  overflow: hidden;
}

#map {
  display: block;
  width: 100%;
  height: auto;
}

#map .shape {
  fill: var(--land);
  stroke: var(--card);
  stroke-width: 0.5;
  transition: fill 0.15s ease;
}

#map .shape.continent-visited {
  fill: var(--continent);
}

#map .shape.visited {
  fill: var(--accent);
}

#map .shape.clickable {
  cursor: pointer;
}

#map .shape.clickable:hover {
  stroke: var(--text);
  stroke-width: 1;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--card);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  transform: translate(-50%, -120%);
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  list-style: none;
  padding: 0;
  margin: 12px 0 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-country { background: var(--accent); }
.swatch-continent { background: var(--continent); }
.swatch-none { background: var(--land); }

.summary {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* --- Panel ------------------------------------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.visit-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 4px;
  font-size: 0.92rem;
  font-weight: 500;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

button.primary {
  padding: 9px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  justify-self: start;
}

button.primary:hover {
  background: var(--accent-strong);
}

.hint {
  color: var(--muted);
  font-weight: normal;
  font-size: 0.85rem;
}

code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 4px;
}

.message {
  margin: 0;
  font-size: 0.9rem;
  min-height: 1.2em;
  white-space: pre-line;
}

.message.error { color: var(--danger); }
.message.ok { color: var(--accent-strong); }

.visit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
}

.visit-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.visit-list .place {
  font-weight: 600;
}

.visit-list .meta {
  color: var(--muted);
  font-size: 0.85rem;
  grid-column: 1 / -1;
}

.visit-list .notes {
  grid-column: 1 / -1;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.visit-list button.delete {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--danger);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 0.85rem;
}

.visit-list .empty {
  color: var(--muted);
  border: 0;
  padding: 0;
  display: block;
}
