/* ==========================================================================
   Ghuri — Bangladesh travel guide
   Palette is grounded in the national flag: bottle green and red, with
   neutrals carrying a slight green bias so greys never read as generic.
   ========================================================================== */

:root {
  --green:        #006A4E;
  --green-deep:   #00523C;
  --green-soft:   #E3F1EC;
  --red:          #F42A41;
  --red-soft:     #FDE7E9;

  --bg:           #F6F8F7;
  --surface:      #FFFFFF;
  --surface-2:    #F0F4F2;
  --line:         #DCE5E1;
  --line-soft:    #E8EEEB;
  --ink:          #16211D;
  --ink-2:        #4A5B55;
  --ink-3:        #7B8C86;

  --accent:       var(--green);
  --on-accent:    #FFFFFF;

  --shadow-1: 0 1px 2px rgba(10, 30, 24, .07), 0 2px 8px rgba(10, 30, 24, .06);
  --shadow-2: 0 2px 6px rgba(10, 30, 24, .10), 0 12px 32px rgba(10, 30, 24, .14);

  --r-s: 8px;
  --r-m: 12px;
  --r-l: 18px;

  --topbar-h: 60px;
  --sheet-peek: 46vh;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-bn: "Noto Sans Bengali", "Nirmala UI", "Shonar Bangla", "Vrinda", var(--font);
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --green:      #2FA37F;
    --green-deep: #1C7F61;
    --green-soft: #12241E;
    --red:        #FF5A6E;
    --red-soft:   #2A1518;

    --bg:         #0E1512;
    --surface:    #16201C;
    --surface-2:  #1D2925;
    --line:       #2A3833;
    --line-soft:  #212E29;
    --ink:        #E8EFEC;
    --ink-2:      #AEBFB9;
    --ink-3:      #7D908A;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .40), 0 2px 8px rgba(0, 0, 0, .34);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, .46), 0 12px 32px rgba(0, 0, 0, .50);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --green:      #2FA37F;
  --green-deep: #1C7F61;
  --green-soft: #12241E;
  --red:        #FF5A6E;
  --red-soft:   #2A1518;
  --bg:         #0E1512;
  --surface:    #16201C;
  --surface-2:  #1D2925;
  --line:       #2A3833;
  --line-soft:  #212E29;
  --ink:        #E8EFEC;
  --ink-2:      #AEBFB9;
  --ink-3:      #7D908A;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .40), 0 2px 8px rgba(0, 0, 0, .34);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .46), 0 12px 32px rgba(0, 0, 0, .50);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Any display rule of ours beats the browser's own [hidden] styling, so a
   panel with display:flex stays painted even while marked hidden. That put
   the saved list and the place sheet over the map on first load and swallowed
   every click meant for the buttons underneath. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

:lang(bn), .bn { font-family: var(--font-bn); }

#app { height: 100%; position: relative; }

button { font: inherit; color: inherit; }

:where(button, input, [tabindex]):focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

.muted { color: var(--ink-3); }

/* ============================ top bar ============================ */

#topbar {
  position: absolute;
  z-index: 1200;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(to bottom, var(--bg) 62%, transparent);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--ink);
  flex: none;
}
.brand svg { display: block; border-radius: 50%; }
.brand-name { font-size: 16px; }
@media (max-width: 560px) { .brand-name { display: none; } }

.search-wrap { position: relative; flex: 1 1 auto; min-width: 0; }

#q {
  width: 100%;
  height: 42px;
  padding: 0 38px 0 14px;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-1);
  -webkit-appearance: none;
  appearance: none;
}
#q::placeholder { color: var(--ink-3); }
#q::-webkit-search-cancel-button { display: none; }
#q:focus { outline: none; border-color: var(--green); box-shadow: var(--shadow-1), 0 0 0 3px var(--green-soft); }

#q-clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  font-size: 22px; line-height: 1;
}

.results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: min(58vh, 480px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
}

.res {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.res:last-child { border-bottom: 0; }
.res:hover, .res.is-on { background: var(--surface-2); }
.res-ico { flex: none; width: 26px; height: 26px; display: grid; place-items: center; font-size: 15px; border-radius: 7px; background: var(--green-soft); }
.res-txt { min-width: 0; flex: 1; }
.res-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-sub { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-dist { flex: none; align-self: center; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.res-empty, .res-busy { padding: 14px; color: var(--ink-3); font-size: 14px; }

/* ============================ map ============================ */

#map {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
}
.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.leaflet-control-attribution {
  font-size: 10.5px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  color: var(--ink-3);
}
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); }
.leaflet-top { margin-top: calc(var(--topbar-h) + env(safe-area-inset-top)); }

/* me-marker */
.me-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.3);
}
.me-dot.is-stale { background: var(--ink-3); }

.pin {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.pin svg { display: block; }

.poi-dot {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-size: 12px;
  background: var(--surface);
  border: 2px solid var(--green);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.28);
}

/* ============================ floating controls ============================ */

#mapctl {
  position: absolute;
  z-index: 1100;
  right: 12px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform .26s cubic-bezier(.22,.61,.36,1);
}
body.sheet-open #mapctl { transform: translateY(calc(-1 * var(--sheet-peek))); }

.fab {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: var(--shadow-1);
  cursor: pointer;
}
.fab:hover { background: var(--surface-2); }
.fab.is-on { background: var(--green); color: var(--on-accent); border-color: var(--green); }

.icon-btn {
  display: grid; place-items: center;
  min-width: 34px; height: 34px;
  padding: 0 8px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.ghost { background: none; border: 0; }
.icon-btn.is-on { color: var(--green); border-color: var(--green); }

/* live-tracking badge */
.livebar {
  position: absolute;
  z-index: 1060;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--green);
  border-radius: 999px;
  box-shadow: var(--shadow-1);
  white-space: nowrap;
}
body.sheet-open .livebar { display: none; }
.live-dot {
  width: 9px; height: 9px; flex: none;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* key box for the traffic layer */
.keybox { padding: 2px 6px 6px; }
.keybox p { margin: 0 0 7px; font-size: 11.5px; color: var(--ink-3); line-height: 1.45; }
.keybox a { color: var(--green); }
.keyrow { display: flex; gap: 6px; }
.keyrow input {
  flex: 1; min-width: 0; height: 32px; padding: 0 9px;
  font-size: 12.5px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-s);
}
.keyrow input:focus { outline: none; border-color: var(--green); }
.keynote { margin: 7px 0 0 !important; font-size: 11.5px; }
.keynote.is-warn { color: var(--red); }
.keynote.is-ok { color: var(--green); }

.hint {
  position: absolute;
  z-index: 1050;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 110px);
  padding: 7px 14px;
  font-size: 13px;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-1);
  text-align: center;
  transition: opacity .3s;
}
.hint.is-gone { opacity: 0; pointer-events: none; }
body.sheet-open .hint { display: none; }

/* ============================ bottom sheet ============================ */

.sheet {
  position: absolute;
  z-index: 1300;
  left: 0; right: 0; bottom: 0;
  height: var(--sheet-peek);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r-l) var(--r-l) 0 0;
  box-shadow: var(--shadow-2);
  transition: height .26s cubic-bezier(.22,.61,.36,1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.is-full { height: calc(100% - var(--topbar-h) - env(safe-area-inset-top)); }

.grip {
  flex: none;
  height: 22px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}
.grip::before {
  content: "";
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.grip:hover::before { background: var(--ink-3); }

.sheet-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 0 14px 6px;
}
.sheet-title { min-width: 0; flex: 1; }
.sheet-title h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -.01em;
  text-wrap: balance;
}
.sheet-title p { margin: 2px 0 0; font-size: 13px; }
.sheet-actions { flex: none; display: flex; gap: 6px; }
#p-close { font-size: 22px; line-height: 1; }
#p-save.is-on { color: var(--red); border-color: var(--red); }
#p-save.is-on svg path { fill: var(--red); }

.chips {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green-deep);
  background: var(--green-soft);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.chip.alt { color: var(--red); background: var(--red-soft); }

.tabs {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 9px 11px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-3);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-on { color: var(--green); border-bottom-color: var(--green); }

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* the whole panel is meant to be selectable so it can be copied by hand */
  -webkit-user-select: text;
  user-select: text;
}
#p-name, #p-kind, .chips { -webkit-user-select: text; user-select: text; }

/* ---- route picture ---- */

.route-prev { margin: 0 0 12px; min-height: 4px; }
.route-img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
}

.wx-stamp { margin: -6px 0 10px; font-size: 11.5px; color: var(--ink-3); }
.wx-stamp.is-stale { color: var(--red); }
.wx-stamp b { font-weight: 600; }

/* ---- how people get there ---- */

.tmode {
  margin: 0 0 8px;
  padding: 9px 11px;
  background: var(--surface-2);
  border-radius: var(--r-s);
}
.tmode-h { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.tmode-i { font-size: 16px; }
.tmode-h b { font-size: 14px; }
.tmode-r {
  display: grid;
  grid-template-columns: minmax(66px, 24%) 1fr;
  gap: 4px 10px;
  padding: 2px 0;
  font-size: 13px;
}
.tmode-k { color: var(--ink-3); font-size: 12.5px; }
.tmode-v { color: var(--ink); overflow-wrap: anywhere; }
.pane { display: none; padding: 12px 14px 22px; }
.pane.is-on { display: block; }

/* ---- content blocks inside panes ---- */

.kv {
  display: grid;
  grid-template-columns: minmax(96px, 34%) 1fr;
  gap: 6px 12px;
  margin: 0 0 12px;
}
.kv dt { font-size: 13px; color: var(--ink-3); }
.kv dd { margin: 0; font-size: 14px; }

.sec-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.sec-h:first-child { margin-top: 2px; }

.list { display: flex; flex-direction: column; gap: 1px; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  background: var(--surface-2);
  border: 0;
  border-radius: var(--r-s);
  cursor: pointer;
}
.item:hover { background: var(--green-soft); }
.item-ico { flex: none; width: 28px; height: 28px; display: grid; place-items: center; font-size: 15px; background: var(--surface); border-radius: 7px; }
.item-txt { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-dist { flex: none; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.steps { counter-reset: s; margin: 0; padding: 0; list-style: none; }
.steps li {
  counter-increment: s;
  position: relative;
  padding: 7px 0 7px 32px;
  font-size: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(s);
  position: absolute;
  left: 0; top: 7px;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--green-deep);
  background: var(--green-soft);
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
}
.steps .step-d { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }

.modes { display: flex; gap: 6px; margin: 0 0 12px; }
.mode {
  flex: 1;
  padding: 8px 6px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-s);
  cursor: pointer;
}
.mode.is-on { background: var(--green-soft); border-color: var(--green); }
.mode-k { font-size: 11.5px; color: var(--ink-3); }
.mode-v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }

.note {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface-2);
  border-left: 3px solid var(--green);
  border-radius: 0 var(--r-s) var(--r-s) 0;
}
.note.warn { border-left-color: var(--red); }

.empty { padding: 22px 8px; text-align: center; color: var(--ink-3); font-size: 14px; }
.empty b { display: block; color: var(--ink-2); font-size: 15px; margin-bottom: 3px; }

.busy { display: flex; align-items: center; gap: 9px; padding: 18px 8px; color: var(--ink-3); font-size: 14px; }
.spin {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 2.4s; }
  .sheet, #mapctl { transition: none; }
}

.linkrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.linkrow a {
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green-deep);
  background: var(--green-soft);
  border-radius: var(--r-s);
  text-decoration: none;
}
.linkrow a:hover { background: var(--green); color: var(--on-accent); }

.coords { font-family: var(--mono); font-size: 12.5px; }

/* ============================ saved drawer ============================ */

/* The saved list sits where the place sheet sits: it must never cover the
   whole map, or the search results underneath become unreachable. */
.drawer {
  position: absolute;
  z-index: 1400;
  left: 0; right: 0; bottom: 0;
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r-l) var(--r-l) 0 0;
  box-shadow: var(--shadow-2);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 6px; }

.saved-row { display: flex; align-items: center; gap: 8px; }
.saved-row .item { flex: 1; }

/* ============================ toast ============================ */

.toast {
  position: absolute;
  z-index: 1500;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  font-size: 13.5px;
  color: #fff;
  background: #16211D;
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  text-align: center;
}
:root[data-theme="dark"] .toast,
:root:not([data-theme="light"]) .toast { background: #2A3833; }

/* ============================ desktop ============================ */

@media (min-width: 900px) {
  :root { --sheet-peek: 100%; }

  #topbar { width: 420px; background: none; }
  #topbar .search-wrap { flex: 1; }

  .sheet {
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + 6px);
    left: 12px;
    bottom: 12px;
    right: auto;
    width: 400px;
    height: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-l);
  }
  .sheet.is-full { height: auto; }
  .grip { display: none; }
  .sheet-head { padding-top: 14px; }

  body.sheet-open #mapctl { transform: none; }
  #mapctl { bottom: 24px; }

  .drawer {
    top: calc(var(--topbar-h) + 6px);
    left: 12px;
    right: auto;
    bottom: 12px;
    width: 400px;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: var(--r-l);
  }
  .hint { bottom: 24px; }
  .layers { right: 74px; bottom: auto; top: calc(var(--topbar-h) + 6px); left: auto; width: 300px; }
}

/* ============================ layers panel ============================ */

.layers {
  position: absolute;
  z-index: 1450;
  /* anchored left so it never sits on top of the button column on the right */
  left: 12px;
  right: auto;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: min(300px, calc(100vw - 24px));
  padding: 10px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
}

.layers-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.layers-head h2 { margin: 0; font-size: 15px; }

.lay {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 6px;
  border-radius: var(--r-s);
  cursor: pointer;
}
.lay:hover { background: var(--surface-2); }
.lay input { position: absolute; opacity: 0; width: 0; height: 0; }

.lay-sw {
  flex: none;
  position: relative;
  width: 36px; height: 20px;
  background: var(--line);
  border-radius: 999px;
  transition: background .18s;
}
.lay-sw::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .18s;
}
.lay input:checked + .lay-sw { background: var(--green); }
.lay input:checked + .lay-sw::after { transform: translateX(16px); }
.lay input:focus-visible + .lay-sw { outline: 2px solid var(--green); outline-offset: 2px; }

.lay-txt { display: flex; flex-direction: column; min-width: 0; }
.lay-txt b { font-size: 14px; font-weight: 600; }
.lay-txt i { font-size: 11.5px; font-style: normal; color: var(--ink-3); }

.lay-rule { height: 1px; margin: 8px 2px; border: 0; background: var(--line); }
.lay-note { margin: 8px 2px 0; font-size: 11px; color: var(--ink-3); line-height: 1.4; }
.dev-credit { float: right; opacity: .85; }

.radar-ctl { display: flex; align-items: center; gap: 8px; padding: 4px 6px 2px; }
.radar-ctl input[type="range"] { flex: 1; min-width: 0; accent-color: var(--green); }
.radar-stamp { flex: none; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.fab-group { display: flex; flex-direction: column; gap: 1px; }
.fab-group .fab:first-child { border-radius: 23px 23px 10px 10px; }
.fab-group .fab:last-child { border-radius: 10px 10px 23px 23px; }

/* a boundary name floating over the map */
.area-label {
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-radius: 5px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.lay-group {
  margin: 4px 2px 2px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.fc-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 9px;
  padding: 4px 6px 2px;
  font-size: 10.5px;
  color: var(--ink-3);
}
.fc-key { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.fc-key i { width: 13px; height: 9px; border-radius: 2px; display: inline-block; }

#print-head { display: none; }

/* ============================ weather ============================ */

.wx-now {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--green-soft), var(--surface-2));
  border-radius: var(--r-m);
}
.wx-now-ico { font-size: 42px; line-height: 1; }
.wx-now-t { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.wx-now-d { font-size: 13.5px; color: var(--ink-2); }
.wx-now-x { margin-left: auto; text-align: right; font-size: 12px; color: var(--ink-3); line-height: 1.6; }

.wx-days { display: flex; flex-direction: column; gap: 1px; }
.wx-day {
  display: grid;
  grid-template-columns: 58px 30px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--r-s);
}
.wx-day:first-child { background: var(--green-soft); }
.wx-dow { font-size: 13px; font-weight: 600; }
.wx-dow small { display: block; font-size: 11px; font-weight: 400; color: var(--ink-3); }
.wx-ico { font-size: 19px; text-align: center; }
.wx-desc { font-size: 12.5px; color: var(--ink-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wx-rain { font-size: 11.5px; color: var(--green); font-variant-numeric: tabular-nums; }
.wx-temp { font-size: 13.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wx-temp b { font-weight: 700; }
.wx-temp span { color: var(--ink-3); }

/* ---- rain charts ---- */

.rain-sum { margin: 0 0 10px; font-size: 13px; color: var(--ink-3); }
.rain-sum b { font-size: 20px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

.rain-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  align-items: end;
  padding: 6px 2px 2px;
  background: var(--surface-2);
  border-radius: var(--r-s);
}
.rain-col { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.rain-mm { font-size: 9.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rain-track { width: 100%; height: 72px; display: flex; align-items: flex-end; }
.rain-bar { width: 100%; border-radius: 3px 3px 0 0; transition: height .3s; }
.rain-pc { font-size: 9px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.rain-day { font-size: 9.5px; color: var(--ink-3); white-space: nowrap; }

/* rainfall bands: no rain, light, moderate, heavy, very heavy */
.rain-0 { background: var(--line); }
.rain-1 { background: #9FD4F0; }
.rain-2 { background: #4FA8DC; }
.rain-3 { background: #2A6FB0; }
.rain-4 { background: #6A4BC0; }

.hrain {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 6px 2px 2px;
  background: var(--surface-2);
  border-radius: var(--r-s);
}
.hrain-strip { display: flex; gap: 2px; align-items: flex-end; min-width: max-content; }
.hrain-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 13px; }
.hrain-track { width: 100%; height: 56px; display: flex; align-items: flex-end; }
.hrain-bar { width: 100%; border-radius: 2px 2px 0 0; }
.hrain-h { font-size: 8.5px; color: var(--ink-3); height: 11px; white-space: nowrap; }
.hrain-cell.is-midnight .hrain-track { border-left: 1px solid var(--line); }
.rain-key { margin: 6px 2px 0; font-size: 11px; color: var(--ink-3); line-height: 1.45; }

.aqi-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 999px;
}
.aqi-1 { background: #DEF7E4; color: #14532D; }
.aqi-2 { background: #FEF5D3; color: #713F12; }
.aqi-3 { background: #FFE4D3; color: #7C2D12; }
.aqi-4 { background: #FFD9DD; color: #7F1D1D; }
.aqi-5 { background: #ECD9F5; color: #4C1D6B; }
:root[data-theme="dark"] .aqi-1, :root:not([data-theme="light"]) .aqi-1 { background: #11301D; color: #86EFAC; }
:root[data-theme="dark"] .aqi-2, :root:not([data-theme="light"]) .aqi-2 { background: #30260B; color: #FDE68A; }
:root[data-theme="dark"] .aqi-3, :root:not([data-theme="light"]) .aqi-3 { background: #35190C; color: #FDBA8C; }
:root[data-theme="dark"] .aqi-4, :root:not([data-theme="light"]) .aqi-4 { background: #3A1115; color: #FCA5A5; }
:root[data-theme="dark"] .aqi-5, :root:not([data-theme="light"]) .aqi-5 { background: #2A1138; color: #D8B4FE; }

/* ============================ desktop fixes ============================ */

/* These come last on purpose. The .layers base rule is defined after the main
   desktop media query, so without this the panel stays bottom-left on a wide
   screen and sits on top of the place sheet. */
@media (min-width: 900px) {
  .layers {
    left: auto;
    right: 74px;
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + 6px);
    bottom: auto;
    width: 300px;
    max-height: calc(100vh - var(--topbar-h) - 36px);
    overflow-y: auto;
  }
}

/* On a phone the panel can grow taller than the screen once the radar,
   forecast and traffic rows are all showing. */
@media (max-width: 899px) {
  .layers {
    max-height: calc(100vh - 110px - env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* ============================ printing ============================ */

@media print {
  @page { margin: 14mm 12mm; }

  /* everything that is screen furniture goes; the sheet becomes the document */
  #map, #topbar, #mapctl, #layers, #saved, #hint, #toast,
  .tabs, .grip, .sheet-actions, .leaflet-container { display: none !important; }

  html, body, #app { height: auto; background: #fff; color: #000; }

  .sheet {
    position: static !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    padding: 0 !important;
    display: block !important;
  }
  .sheet-head { display: none !important; }
  .sheet-body { overflow: visible !important; }

  /* print every tab that has been looked at, not just the visible one */
  .pane { display: block !important; padding: 0 0 10mm !important; break-inside: auto; }
  .pane:empty { display: none !important; }

  #print-head {
    display: block !important;
    margin: 0 0 6mm;
    padding-bottom: 3mm;
    border-bottom: 2px solid #006A4E;
  }
  #print-head h1 { margin: 0; font-size: 20pt; color: #00402F; }
  #print-head p { margin: 1mm 0 0; font-size: 10pt; color: #333; }
  #print-head .print-meta { font-size: 8.5pt; color: #666; }

  .chips { padding: 0 0 4mm !important; }
  .chip { border: 1px solid #bbb; background: #fff !important; color: #000 !important; }

  .sec-h { color: #000; border-bottom: 1px solid #ccc; padding-bottom: 1mm; break-after: avoid; }
  .item, .wx-day, .rain-chart, .hrain { background: #fff !important; break-inside: avoid; }
  .item { border-bottom: 1px solid #eee; border-radius: 0; }
  .wx-now { background: #f2f2f2 !important; break-inside: avoid; }
  .note { background: #f7f7f7 !important; border-left: 3px solid #006A4E; break-inside: avoid; }
  .linkrow, .busy, .spin { display: none !important; }
  .route-img { max-width: 100%; height: auto; break-inside: avoid; border: 1px solid #999; }
  .tmode { background: #f7f7f7 !important; break-inside: avoid; }
  .wx-stamp { color: #555 !important; }
  .kv { break-inside: avoid; }
  a { color: #000; text-decoration: none; }

  /* A4 leaves about 185mm of printable width. The 48-hour strip is the one
     block wide enough to run off the edge, so it is tightened to fit rather
     than clipped. */
  .hrain { overflow: visible !important; }
  .hrain-strip { gap: 1px; min-width: 0; }
  .hrain-cell { width: 10px; }
  .hrain-h { font-size: 7pt; }

  #app, .sheet, .sheet-body, .pane { overflow: visible !important; max-width: 100%; }
  .rain-chart { padding-left: 0; padding-right: 0; }
  .wx-day { grid-template-columns: 52px 24px 1fr auto; }
}
