/* Pelagizo — whitewash, deep-sea ink, Cycladic dome blue.
   One accent colour (bougainvillea) is kept for the share action only. */

:root {
  --whitewash: #f6f8f7;
  --paper: #ffffff;
  --ink: #0f2a44;
  --ink-soft: #56697a;
  --line: #dce3e6;
  --line-soft: #e9eef0;
  --dome: #2447c7;
  --dome-deep: #173199;
  --dome-tint: #e7ecfb;
  --limestone: #c9cfcb;
  --bougainvillea: #c8246b;
  --bougainvillea-deep: #a41a56;
  --warn: #b3261e;

  --font: "Commissioner", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --panel-width: 360px;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 20px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* Set by sheet.js on phones: height of the visible part of the sheet. */
  --peek: 200px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--whitewash);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--dome);
  outline-offset: 2px;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

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

#map {
  order: 2;
  flex: 1;
  height: 100%;
  min-width: 0;
  /* Keep Leaflet's own z-indexes inside the map, below the panel. */
  position: relative;
  z-index: 0;
  isolation: isolate;
}

.leaflet-container {
  background: #e8eef1;
  font-family: var(--font);
}

/* Cool the grey basemap towards the sea, so the blue islands read first. */
.leaflet-tile-pane {
  filter: grayscale(1) sepia(0.12) hue-rotate(170deg) saturate(1.4) brightness(1.05);
}

.leaflet-interactive:focus,
.leaflet-container svg:focus,
.leaflet-container path:focus {
  outline: none;
}

.leaflet-control-zoom.leaflet-bar {
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  overflow: hidden;
  box-shadow: none;
}
.leaflet-control-zoom a {
  color: var(--ink);
  width: 34px;
  height: 34px;
  line-height: 34px;
}

.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(246, 248, 247, 0.85) !important;
}

.leaflet-tooltip.marker-tooltip {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  box-shadow: 0 4px 14px rgba(15, 42, 68, 0.12);
  padding: 4px 8px;
}

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

#sidebar {
  order: 1;
  width: var(--panel-width);
  flex: none;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--whitewash);
  border-right: 1px solid var(--line);
  position: relative;
  z-index: 500;
}

.sheet-handle { display: none; }

.panel-head {
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  margin: 0 auto 0 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--dome);
}

.subtitle {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.lang-switch {
  display: inline-flex;
  padding: 2px;
  background: var(--line-soft);
  border-radius: 999px;
  flex: none;
}
.lang-switch button {
  appearance: none;
  border: none;
  background: transparent;
  min-width: 38px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}
.lang-switch button.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 42, 68, 0.14);
}

/* Count: the number of islands is the headline of the panel. */
.count {
  margin-top: 18px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}
.count .num {
  font-size: 52px;
  font-weight: 800;
  line-height: 0.85;
  letter-spacing: -0.04em;
  color: var(--ink);
}
.count-meta {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  line-height: 1.25;
  color: var(--ink-soft);
}
.count .of { font-weight: 700; color: var(--ink); font-size: 15px; }
.count .percent {
  margin-left: auto;
  font-size: 15px;
  font-weight: 700;
  color: var(--dome);
}

/* Tally: one tick per island, in groups by area. */
.tally {
  margin-top: 12px;
  display: flex;
  gap: 5px;
  height: 14px;
}
.tally-group {
  display: flex;
  gap: 1px;
  min-width: 0;
}
.tally-tick {
  flex: 1 1 0;
  min-width: 1px;
  background: var(--limestone);
  border-radius: 1px;
  transition: background-color 0.25s var(--ease), transform 0.25s var(--ease);
}
.tally-tick.on { background: var(--dome); }
.tally-tick.pop { transform: scaleY(1.45); }

.actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.btn:hover { border-color: var(--ink-soft); }
.btn-solid {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn-solid:hover { background: #1b3c5e; border-color: #1b3c5e; }

.sync-status {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
}
.sync-status:empty { display: none; }
.sync-status::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.sync-status[data-state="saved"] { color: var(--dome); }
.sync-status[data-state="offline"] { color: var(--warn); }

/* --- Search + list -------------------------------------------------------- */

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.search-wrap {
  position: relative;
  padding: 12px 16px 6px;
}
.search-icon {
  position: absolute;
  left: 29px;
  top: 50%;
  margin-top: 3px;
  transform: translateY(-50%);
  color: var(--ink-soft);
  pointer-events: none;
}
.search {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  font-size: 15px;
  background: var(--paper);
  -webkit-appearance: none;
  appearance: none;
}
.search::placeholder { color: var(--ink-soft); opacity: 0.8; }
.search:focus { outline: none; border-color: var(--dome); box-shadow: 0 0 0 3px var(--dome-tint); }

#list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 8px calc(24px + var(--safe-bottom));
}

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 12px 10px 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-s);
}

.chevron {
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.2s var(--ease);
  flex: none;
}
.group.collapsed .chevron { transform: rotate(-45deg); }

.group-count {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.group-count.all-visited { color: var(--dome); }
.group-count.all-visited::after { content: " ✓"; }

.group.collapsed .island-row { display: none; }
#list.searching .group.collapsed .island-row:not(.hidden) { display: flex; }

.island-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: var(--radius-s);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.island-row:hover { background: var(--line-soft); }

/* Round check: an empty ring, filled with the dome blue when visited. */
.island-row input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 20px;
  height: 20px;
  flex: none;
  border: 1.5px solid var(--limestone);
  border-radius: 50%;
  background: var(--paper);
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.island-row input::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid var(--paper);
  border-bottom: 2px solid var(--paper);
  transform: rotate(-45deg) translate(1px, -1px) scale(0);
  transition: transform 0.18s var(--ease);
}
.island-row input:checked { background: var(--dome); border-color: var(--dome); }
.island-row input:checked::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }

.island-row .name { font-size: 15px; }
.island-row.visited .name { font-weight: 600; color: var(--dome-deep); }

.hidden { display: none !important; }

/* --- Stats modal ---------------------------------------------------------- */

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 42, 68, 0.42);
  animation: fade-in 0.2s ease;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border-radius: var(--radius-l);
  padding: 20px 22px 20px;
  box-shadow: 0 24px 60px rgba(15, 42, 68, 0.28);
  animation: rise-in 0.28s var(--ease);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-card h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.modal-close {
  appearance: none;
  display: grid;
  place-content: center;
  width: 36px;
  height: 36px;
  margin-right: -8px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.modal-close .icon { width: 18px; height: 18px; }
.modal-close:hover { background: var(--line-soft); color: var(--ink); }

.stat-block { padding: 14px 0; border-top: 1px solid var(--line-soft); }
.stat-block:first-child { border-top: none; padding-top: 4px; }
.stat-block h4 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}
.stat-hero {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.stat-hero-pct {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--dome);
  line-height: 1;
}
.stat-hero-sub { font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.stat-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
}
.stat-line span { color: var(--ink-soft); }
.stat-line strong { text-align: right; }
.stat-badge {
  display: inline-block;
  background: var(--dome-tint);
  color: var(--dome-deep);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 999px;
  margin: 0 6px 8px 0;
}
.stat-note { font-size: 14px; color: var(--ink-soft); margin: 4px 0; line-height: 1.45; }
.stat-bar {
  display: grid;
  grid-template-columns: minmax(84px, 38%) 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  padding: 4px 0;
}
.stat-bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--line-soft);
  overflow: hidden;
}
.stat-bar-fill { display: block; height: 100%; background: var(--dome); border-radius: 4px; }
.stat-bar-val {
  text-align: right;
  color: var(--ink-soft);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stats-actions {
  position: sticky;
  bottom: -20px;
  margin: 0 -22px -20px;
  padding: 14px 22px 20px;
  background: var(--paper);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line-soft);
}
.btn-share {
  appearance: none;
  border: none;
  min-height: 44px;
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--bougainvillea);
  color: var(--paper);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-share:hover { background: var(--bougainvillea-deep); }
.share-hint {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(16px); } }

/* --- Short landscape screens (phones on their side) ----------------------- */

@media (min-width: 721px) and (max-height: 560px) {
  :root { --panel-width: 320px; }
  #sidebar { overflow-y: auto; }
  .panel-head { padding: 14px 16px 12px; }
  .subtitle { display: none; }
  .count { margin-top: 10px; }
  .count .num { font-size: 38px; }
  .actions { margin-top: 10px; }
  .panel-body { flex: none; }
  #list { overflow: visible; }
}

/* --- Phones: full-screen map with a bottom sheet -------------------------- */

@media (max-width: 720px) {
  #sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: calc(100dvh - 56px);
    border-right: none;
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    box-shadow: 0 -8px 30px rgba(15, 42, 68, 0.16);
    transform: translateY(calc(100% - var(--peek)));
    transition: transform 0.32s var(--ease);
    will-change: transform;
  }
  #sidebar[data-sheet="open"] { transform: translateY(0); }
  #sidebar.dragging { transition: none; }

  .sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: grab;
    touch-action: none;
    flex: none;
  }
  .sheet-grip {
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: var(--limestone);
  }

  .panel-head {
    padding: 0 16px 14px;
    touch-action: none;
  }
  .wordmark { font-size: 21px; }
  .subtitle { display: none; }
  .count { margin-top: 10px; }
  .count .num { font-size: 42px; }
  .actions { margin-top: 12px; }
  .btn { min-height: 40px; }

  .island-row, .group-title { min-height: 46px; }
  .search { font-size: 16px; } /* 16px stops iOS from zooming on focus */

  /* The sheet covers the bottom of the map: lift the Leaflet corners. */
  .leaflet-bottom { bottom: var(--peek); }
  .leaflet-control-zoom { display: none; }

  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none;
    max-height: 90dvh;
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    padding: 16px 18px 0;
  }
  .stats-actions {
    bottom: 0;
    margin: 0 -18px;
    padding: 12px 18px calc(14px + var(--safe-bottom));
  }
  .btn-share { flex: 1; }
}

@media (max-width: 340px) {
  .panel-head { padding: 0 12px 12px; }
  .count .num { font-size: 36px; }
  .btn { padding: 7px 10px; font-size: 12.5px; }
  #backup { padding: 7px 11px; }
  #backup .label { display: none; }
  /* Only the status dot; the text stays for screen readers. */
  .sync-status { font-size: 0; gap: 0; }
  .lang-switch button { min-width: 32px; padding: 5px 8px; }
  .search-wrap { padding: 10px 12px 6px; }
  .search-icon { left: 25px; }
  .stat-bar { grid-template-columns: 76px 1fr 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
