:root {
  /* -- surfaces: three elevation tiers, two blur tiers -- */
  --panel-bg: rgba(11, 17, 30, 0.78);     /* chip/bar glass: search, bars, FABs */
  --panel-raised: rgba(12, 18, 32, 0.92); /* HUD/card: tour, lesson, quest, toasts, popovers */
  --panel-modal: rgba(12, 18, 32, 0.95);  /* modal: welcome */
  --panel-border: rgba(125, 155, 205, 0.2);
  --panel-glow: inset 0 1px 0 rgba(255, 255, 255, 0.055), 0 10px 32px rgba(0, 0, 0, 0.42);
  --blur-chip: 6px;   /* bars, chips, FABs, scrubber bubble */
  --blur-panel: 12px; /* sheets, HUD cards, modals, popovers */

  /* -- ink: exactly three (DESIGN.md §4) -- */
  --text-bright: #e8eefb;
  --text: #cdd6e8;
  --text-dim: #9aa8c2;

  /* -- accents: two + the blessed pointing accent -- */
  --active: #7ab2ff; /* app blue: chrome, toggles, links */
  --warm: #ffd9a0;   /* real-sky gold: cardinals, sun events, quests, life list */
  --hot: #ffb38a;    /* pointing orange: compass-on, selection (base 255,140,100) */

  /* -- interactive blue fill ladder (alpha of 122,178,255) --
     quiet rest .06 · button rest .10 · any hover .14 · any press .18 */
  --fill-faint: rgba(122, 178, 255, 0.06);
  --fill-rest: rgba(122, 178, 255, 0.1);
  --fill-hover: rgba(122, 178, 255, 0.14);
  --fill-press: rgba(122, 178, 255, 0.18);
  --fill-primary: linear-gradient(180deg, rgba(122, 178, 255, 0.26), rgba(122, 178, 255, 0.14));
  --ring: rgba(122, 178, 255, 0.45); /* focus ring + primary-button border */

  /* -- radii (sole nested exception: #search-results li at 8px) -- */
  --r-sm: 8px;     /* inputs, bare icon buttons, nested list items */
  --r-md: 10px;    /* text buttons, tappable rows */
  --r-lg: 12px;    /* bars, toolbar, small panels, bubbles */
  --r-xl: 16px;    /* floating cards, sheets, dialogs */
  --r-sheet: 18px; /* bottom-sheet top corners */
  --r-pill: 999px; /* chips, toasts, badges */

  /* -- motion: 150-450ms, always --ease -- */
  --ease: cubic-bezier(0.22, 0.9, 0.3, 1);
  --t-press: 0.15s; /* button transform/background */
  --t-fade: 0.2s;   /* small fades, hovers, popovers */
  --t-panel: 0.3s;  /* panel/sheet enter and exit */
  --t-idle: 0.45s;  /* chrome fade, progress fills, celebration */

  /* layout tokens — the single source for safe areas and bottom clearance.
     --vvh/--kb are kept live by js/sheet.js from visualViewport (keyboard). */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --dock-clear: 64px; /* floating cards sit above this line */
  --fab-bottom: 74px; /* compass FAB baseline */
  --vvh: 100vh;
  --kb: 0px;
  font-size: 13.5px; /* the body tier — all `font: inherit` text lands here */
}

/* z-index ladder (keep this list honest):
   20 chrome bars/status · 21 FABs · 22 dock + scrubber · 23 scrim
   24-29 sheets/cards · 25 tour · 30 search dropdown stack · 30 coach marks
   40 toasts · 45 welcome · 50 loading · 60 glossary popover */

* { box-sizing: border-box; }

/* glass panels share one finish */
#search-box, #search-results, #tonight, #info, #toolbar, #status, #time-bar,
#tour-player, #welcome, #compass-btn, #tonight-btn {
  box-shadow: var(--panel-glow);
}

/* gentle entry motion for panels (browsers without @starting-style
   simply skip the animation) */
#info, #tonight, #tour-player, #welcome, #search-results {
  transition:
    opacity var(--t-panel) var(--ease),
    transform var(--t-panel) var(--ease),
    display var(--t-panel) allow-discrete,
    overlay var(--t-panel) allow-discrete;
}
@starting-style {
  #info:not([hidden]) { opacity: 0; transform: translateY(10px); }
  #tonight:not([hidden]) { opacity: 0; transform: translateY(-8px); }
  #tour-player:not([hidden]) { opacity: 0; transform: translate(-50%, 12px); }
  #welcome:not([hidden]) { opacity: 0; transform: translate(-50%, -47%); }
  #search-results:not([hidden]) { opacity: 0; transform: translateY(-6px); }
}
/* real exits: without [hidden] end-values, allow-discrete holds the panel
   frozen for the whole transition and then pops it away */
#info[hidden] { opacity: 0; transform: translateY(10px); }
#tonight[hidden] { opacity: 0; transform: translateY(-8px); }
#tour-player[hidden] { opacity: 0; transform: translate(-50%, 12px); }
#welcome[hidden] { opacity: 0; transform: translate(-50%, -47%); }
#search-results[hidden] { opacity: 0; transform: translateY(-6px); }
#layers-sheet[hidden] { opacity: 0; transform: translate(-50%, 10px); }

button { transition: background var(--t-press) var(--ease), transform var(--t-press) var(--ease), color var(--t-press) var(--ease); }
button:active { transform: scale(0.96); }

/* slim, quiet scrollbars in panels */
#tonight, #info, #layers-sheet, .sc-sheet, .jr-sheet {
  scrollbar-width: thin;
  scrollbar-color: rgba(125, 155, 205, 0.3) transparent;
}
#tonight::-webkit-scrollbar, #info::-webkit-scrollbar,
#layers-sheet::-webkit-scrollbar, .sc-sheet::-webkit-scrollbar,
.jr-sheet::-webkit-scrollbar { width: 6px; }
#tonight::-webkit-scrollbar-thumb, #info::-webkit-scrollbar-thumb,
#layers-sheet::-webkit-scrollbar-thumb, .sc-sheet::-webkit-scrollbar-thumb,
.jr-sheet::-webkit-scrollbar-thumb {
  background: rgba(125, 155, 205, 0.28);
  border-radius: 3px;
}
#tonight::-webkit-scrollbar-track, #info::-webkit-scrollbar-track,
#layers-sheet::-webkit-scrollbar-track, .sc-sheet::-webkit-scrollbar-track,
.jr-sheet::-webkit-scrollbar-track { background: transparent; }

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea { -webkit-user-select: text; user-select: text; }

/* red night vision: tints the canvas and every control at once */
body.night {
  filter: grayscale(1) sepia(1) saturate(4) hue-rotate(-48deg) brightness(0.62) contrast(1.05);
}
/* showModal() promotes the dialog to the top layer, outside body's filter —
   re-apply it there or the dialog opens full-brightness at night */
body.night #location-dialog,
body.night #location-dialog::backdrop {
  filter: grayscale(1) sepia(1) saturate(4) hue-rotate(-48deg) brightness(0.62) contrast(1.05);
}

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.icon {
  width: 20px; /* 1:1 on the 20-unit grid — no fractional-pixel strokes */
  height: 20px;
  display: block;
}

button {
  font: inherit;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
/* hover affordances only where hover exists — taps must not leave
   sticky highlights on touch screens */
@media (hover: hover) {
  button:hover { background: var(--fill-hover); }
}
/* no 300ms double-tap-zoom hesitation on any control */
button, [role='button'], .t-tap, #search-results li, .cat-chip,
input, select, label, .term-link {
  touch-action: manipulation;
}

/* ---------------- loading ---------------- */

#loading {
  position: fixed;
  inset: 0;
  background: #050912;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.4s var(--ease);
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loading-card { text-align: center; position: relative; }
.loading-title {
  font-size: 28px;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: #e8eefb;
  margin-bottom: 12px;
  text-indent: 0.45em;
  animation: loading-breathe 2.6s ease-in-out infinite;
}
/* three stars twinkling around the wordmark while catalogs stream in */
.loading-card::before, .loading-card::after {
  content: '✦';
  position: absolute;
  color: var(--active);
  animation: loading-twinkle 1.8s ease-in-out infinite;
}
.loading-card::before { top: -34px; left: 12%; font-size: 11px; }
.loading-card::after { top: -16px; right: 6%; font-size: 15px; animation-delay: 0.7s; }
#loading-status { color: var(--text-dim); }
#loading-status.error { color: #e08080; }
@keyframes loading-breathe {
  50% { opacity: 0.75; }
}
@keyframes loading-twinkle {
  0%, 100% { opacity: 0.15; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ---------------- search ---------------- */

#search {
  position: fixed;
  top: 14px;
  left: 14px;
  width: min(290px, calc(100vw - 28px));
  z-index: 30; /* the dropdown must beat every chip and panel below it */
}
/* while searching/browsing, the location chip steps aside */
body.searching #status { opacity: 0; pointer-events: none; }
#status { transition: opacity 0.2s var(--ease); }
#search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  padding: 8px 12px;
  backdrop-filter: blur(var(--blur-chip));
}
#search-box .icon { color: var(--text-dim); flex: none; width: 15px; height: 15px; }
#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  min-width: 0;
}
#search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(var(--blur-chip));
  /* never extend under the on-screen keyboard (--vvh from js/sheet.js) */
  max-height: min(50vh, calc(var(--vvh, 100vh) - 132px));
  overflow: auto;
  overscroll-behavior: contain;
}
#search-results li {
  padding: 6px 10px;
  border-radius: 8px; /* nested: outer 12 − padding 4 */
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
#search-results li.active { background: var(--fill-hover); }
@media (hover: hover) {
  #search-results li:hover { background: var(--fill-hover); }
}
#search-results li:active { background: var(--fill-press); }
#search-results .sub { color: var(--text-dim); font-size: 12.5px; white-space: nowrap; }

/* category browse inside the search dropdown */
.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
}
.cat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--panel-border);
  background: var(--fill-faint);
  border-radius: var(--r-pill);
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text);
}
.cat-chip svg { width: 14px; height: 14px; flex: none; }
@media (hover: hover) {
  .cat-chip:hover { background: var(--fill-hover); }
}
.cat-chip:active { background: var(--fill-press); }
.cat-back {
  width: 100%;
  text-align: left;
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 8px 10px;
}
.cat-up {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warm);
  box-shadow: 0 0 6px rgba(255, 217, 160, 0.7);
  display: inline-block;
  margin-right: 8px;
  flex: none;
}
.cat-down { opacity: 0.55; }
.cat-hint {
  padding: 4px 10px 8px;
  color: var(--text-dim);
  font-size: 11.5px;
}

/* ---------------- info panel ---------------- */

#info {
  position: fixed;
  top: 14px;
  right: calc(14px + var(--safe-r));
  width: min(280px, calc(100vw - 28px));
  max-height: min(78vh, calc(100vh - 120px));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px 16px;
  backdrop-filter: blur(var(--blur-panel));
  z-index: 20;
}
#info h2 { margin: 0 20px 2px 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-bright); }
#info-sub { color: var(--text-dim); font-size: 12.5px; margin-bottom: 10px; }
#info-close {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 17px;
  line-height: 1;
  padding: 4px 8px;
  color: var(--text-dim);
}
#info-rows { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
#info-rows dt { color: var(--text-dim); }
#info-rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#info-center {
  margin-top: 12px;
  width: 100%;
  border: 1px solid var(--panel-border);
  background: var(--fill-rest);
  padding: 8px;
}

/* ---------------- toolbar ---------------- */

#toolbar {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  padding: 4px 6px;
  backdrop-filter: blur(var(--blur-chip));
  z-index: 20;
}
#toolbar button { color: var(--text-dim); }
@media (hover: hover) {
  #toolbar button:hover { color: var(--text); }
}
#toolbar button.active {
  color: var(--active);
  background: var(--fill-rest);
  box-shadow: 0 0 14px rgba(122, 178, 255, 0.18) inset;
}

/* ---------------- status (bottom left) ---------------- */

#status {
  position: fixed;
  left: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  padding: 4px 10px 4px 4px;
  backdrop-filter: blur(var(--blur-chip));
  z-index: 20;
  font-size: 12.5px;
}
#location-btn { display: flex; align-items: center; gap: 6px; color: var(--text); }
#location-btn .icon { width: 15px; height: 15px; color: var(--text-dim); }
#fov-label { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------------- time bar ---------------- */

#time-bar {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  padding: 4px 6px;
  backdrop-filter: blur(var(--blur-chip));
  z-index: 20;
}
#rate-label {
  color: var(--text-dim);
  font-size: 12.5px;
  min-width: 52px;
  text-align: right;
  padding-right: 4px;
  font-variant-numeric: tabular-nums;
}
#time-now { font-size: 12.5px; padding: 6px 8px; }
#time-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 6px 8px;
  font: inherit;
  font-size: 12.5px;
  color-scheme: dark;
  width: 178px;
}

/* ---------------- tonight panel ---------------- */

#top-row { display: flex; gap: 8px; align-items: stretch; }
#search-box { flex: 1; }
#tonight-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  padding: 7px 12px;
  backdrop-filter: blur(var(--blur-chip));
  color: var(--text);
  font-size: 13.5px;
  white-space: nowrap;
}
#tonight-btn .icon { width: 16px; height: 16px; color: var(--warm); }

#tonight {
  margin-top: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(var(--blur-panel));
  padding: 14px 16px;
  max-height: min(66vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
#tonight header { display: flex; justify-content: space-between; align-items: center; }
#tonight h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text-bright); }
#tonight .t-close { font-size: 17px; padding: 2px 8px; color: var(--text-dim); }
#tonight h4 {
  margin: 12px 0 4px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
#tonight .t-line { margin: 6px 0; color: var(--text); }
#tonight .t-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
}
#tonight .t-dim { color: var(--text-dim); text-align: right; }
#tonight .t-tap { cursor: pointer; transition: background var(--t-press) var(--ease), transform var(--t-press) var(--ease); }
@media (hover: hover) {
  #tonight .t-tap:hover { background: var(--fill-hover); transform: translateX(2px); }
}
#tonight .t-tap:active { background: var(--fill-press); }
/* touch users get a persistent "this row navigates" affordance */
@media (hover: none) {
  #tonight .t-row.t-tap::after, #tonight .t-line.t-tap::after {
    content: '›';
    color: var(--text-dim);
    margin-left: 6px;
    flex: none;
  }
}
#tonight .t-hint { color: var(--text-dim); font-size: 12.5px; font-style: italic; margin: 4px 6px; }
#tonight .t-featured {
  border: 1px solid rgba(255, 217, 160, 0.3);
  background: linear-gradient(135deg, rgba(255, 217, 160, 0.11), rgba(255, 217, 160, 0.04));
  border-radius: var(--r-md);
  padding: 8px 10px;
}
#tonight .t-featured p { margin: 4px 0 0; color: var(--text-dim); }
#tonight .t-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.t-chip {
  border: 1px solid var(--panel-border);
  background: var(--fill-rest);
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-size: 12.5px;
}
#tonight .t-foot { margin-top: 12px; color: var(--warm); font-size: 12.5px; }
#tonight .t-loading { color: var(--text-dim); padding: 8px 0; }

/* hub: School / Calendar / Journal — visible the instant the panel opens */
#tonight .t-hub {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0 2px;
}
#tonight .t-hub-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: 64px;
  border-radius: var(--r-lg);
  border: 1px solid var(--panel-border);
  background: var(--fill-faint);
  color: var(--text);
  cursor: pointer;
  transition: background var(--t-press) var(--ease);
}
#tonight .t-hub-btn:focus-visible, #tonight .t-hub-btn:active { background: var(--fill-press); }
@media (hover: hover) {
  #tonight .t-hub-btn:hover { background: var(--fill-hover); }
}
#tonight .t-hub-icon svg { width: 20px; height: 20px; display: block; }
#tonight .t-hub-btn b { font-weight: 600; font-size: 11.5px; white-space: nowrap; }
#tonight .t-hub-sub { color: var(--text-dim); font-size: 11.5px; }

/* ---------------- tour player ---------------- */

#tour-player {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--dock-clear) + env(safe-area-inset-bottom, 0px));
  width: min(480px, calc(100vw - 24px));
  background: var(--panel-raised);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-xl);
  backdrop-filter: blur(var(--blur-panel));
  padding: 12px 16px 14px;
  z-index: 25;
}
.tour-head { display: flex; justify-content: space-between; align-items: center; }
#tour-title { font-size: 16px; font-weight: 600; color: var(--text-bright); }
#tour-exit { color: var(--text-dim); font-size: 17px; padding: 2px 8px; }
#tour-caption { margin: 8px 0 10px; font-size: 13.5px; line-height: 1.5; color: var(--text); }
.tour-controls { display: flex; align-items: center; justify-content: space-between; }
.tour-controls button { font-size: 18px; padding: 2px 14px; }
.tour-controls button:disabled { opacity: 0.3; }
#tour-dots { display: flex; gap: 6px; }
.tour-dot {
  width: 7px;
  height: 7px;
  border-radius: 4px;
  background: rgba(125, 155, 205, 0.4);
  cursor: pointer;
  transition: width 0.25s var(--ease), background 0.25s var(--ease);
}
.tour-dot.on { background: var(--active); width: 18px; }

/* ---------------- welcome ---------------- */

#welcome {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100vw - 32px));
  background: var(--panel-modal);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px 24px;
  backdrop-filter: blur(var(--blur-panel));
  z-index: 45;
}
#welcome h2 { margin: 0 0 12px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-bright); }
#welcome ul { margin: 0 0 16px; padding-left: 18px; color: var(--text); line-height: 1.5; font-size: 13.5px; }
.welcome-actions { display: flex; gap: 8px; justify-content: flex-end; }
.welcome-actions button { border: 1px solid var(--panel-border); padding: 8px 14px; }
.welcome-actions .primary { background: var(--fill-primary); border-color: var(--ring); }

/* ---------------- story cards ---------------- */

#info-story { margin: 4px 0 10px; font-size: 13px; line-height: 1.5; }
#info-story p { margin: 6px 0; color: var(--text); }
.story-hook { font-weight: 600; color: var(--warm) !important; }
.story-fact { color: var(--text-dim) !important; font-size: 12.5px; }
.story-light { color: var(--text-dim) !important; font-style: italic; font-size: 12.5px; }
.info-actions { display: flex; gap: 8px; margin-top: 12px; }
.info-actions button {
  flex: 1;
  border: 1px solid var(--panel-border);
  background: var(--fill-rest);
  padding: 8px 12px;
}
#info-center { margin-top: 0; width: auto; }
#info-spotted.on { color: var(--warm); border-color: rgba(255, 217, 160, 0.4); }

/* ---------------- compass FAB ---------------- */

#compass-btn {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(var(--fab-bottom) + env(safe-area-inset-bottom, 0px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(var(--blur-chip));
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 21;
}
#compass-btn .icon { width: 24px; height: 24px; }
#compass-btn.starting { animation: compass-pulse 1s ease-in-out infinite; }
#compass-btn.on {
  color: var(--hot);
  border-color: rgba(255, 140, 100, 0.55);
  box-shadow: 0 0 18px rgba(255, 140, 100, 0.25);
}
@keyframes compass-pulse {
  50% { box-shadow: 0 0 0 10px rgba(122, 178, 255, 0.12); }
}

/* ---------------- toasts ---------------- */

#toasts {
  position: fixed;
  top: calc(66px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 24px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-raised);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-pill);
  padding: 8px 16px;
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity var(--t-panel) var(--ease), transform var(--t-panel) var(--ease);
  pointer-events: auto;
  backdrop-filter: blur(var(--blur-panel));
  box-shadow: var(--panel-glow);
}
.toast.show { opacity: 1; transform: none; }
.toast button {
  border: 1px solid var(--panel-border);
  background: var(--fill-rest);
  padding: 4px 12px;
  border-radius: var(--r-pill);
  font-size: 12.5px;
}

.toolbar-sep {
  width: 1px;
  align-self: stretch;
  margin: 4px 3px;
  background: var(--panel-border);
}

/* ---------------- location dialog ---------------- */

#location-dialog {
  background: rgb(12, 18, 32);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px 24px;
  min-width: 280px;
  box-shadow: var(--panel-glow);
}
#location-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
#location-dialog h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
#location-dialog label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
#location-dialog input {
  width: 140px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: 6px 8px;
  font: inherit;
}
.dialog-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.dialog-row .spacer { flex: 1; }
.dialog-row button { border: 1px solid var(--panel-border); padding: 8px 16px; }
#loc-ok { background: var(--fill-primary); border-color: var(--ring); }

/* generous targets for fingers */
@media (pointer: coarse) {
  button { padding: 9px; }
  .icon { width: 22px; height: 22px; }
  #search-box { padding: 10px 14px; }
}

/* COMPACT = small phones in portrait OR any landscape phone. Height matters
   as much as width: an 812×375 phone must never get the desktop layout. */
@media (max-width: 760px), (max-height: 500px) {
  :root { --dock-clear: 112px; --fab-bottom: 104px; }
  #search { top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); width: calc(100vw - 20px - var(--safe-l) - var(--safe-r)); }
  /* location chip moves under the search bar — the bottom row is full */
  #status {
    bottom: auto;
    top: calc(60px + var(--safe-t));
    left: calc(10px + var(--safe-l));
    font-size: 11.5px;
  }
  /* no-JS fallback only; with the shell running, both bars live in #dock */
  #toolbar { bottom: calc(8px + var(--safe-b)); max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none; }
  #toolbar::-webkit-scrollbar { display: none; }
  #time-bar { right: 8px; bottom: calc(66px + var(--safe-b)); max-width: calc(100vw - 16px); }
  #rate-label { min-width: 38px; }
  #time-input { width: 138px; }
  #compass-btn { bottom: calc(var(--fab-bottom) + var(--safe-b)); right: calc(10px + var(--safe-r)); }
  #tour-player { bottom: calc(var(--dock-clear) + var(--safe-b)); }
  #info-rows { font-size: 12.5px; }
  /* clear of the relocated status chip */
  #toasts { top: calc(104px + var(--safe-t)); }
  /* calendar rows: title-then-detail reads better than a ragged right
     column on a narrow sheet */
  #tonight .t-ev { flex-direction: column; align-items: flex-start; gap: 2px; }
  #tonight .t-ev .t-dim { text-align: left; }
}

/* ============================================================
   DESIGN SYSTEM PASS (see docs/DESIGN.md)
   ============================================================ */

/* -- focus is always visible (keyboard users over a starfield) -- */
:focus-visible { outline: 2px solid var(--active); outline-offset: 2px; }
#search-box:focus-within {
  box-shadow: var(--panel-glow), 0 0 0 2px var(--ring);
}
/* the one un-themed UA color — garish under the night filter */
::selection { background: rgba(122, 178, 255, 0.3); color: var(--text-bright); }

/* -- stories speak in a serif: the one voice of wonder -- */
#info-story p {
  font-family: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}
.story-hook { font-size: 15.5px; line-height: 1.5; }
#info-story p:not(.story-hook) { font-size: 13.5px; }

/* -- progressive disclosure in the info card -- */
#info-rows.collapsed dt.extra, #info-rows.collapsed dd.extra { display: none; }
#info-more {
  width: 100%;
  margin-top: 6px;
  padding: 7px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 12.5px;
}
@media (hover: hover) {
  #info-more:hover { color: var(--text); background: var(--fill-hover); }
}

/* -- layers sheet (the mobile home of all sky toggles) -- */
#layers-sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--dock-clear) + env(safe-area-inset-bottom, 0px));
  width: min(420px, calc(100vw - 16px));
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-xl);
  backdrop-filter: blur(var(--blur-panel));
  box-shadow: var(--panel-glow);
  padding: 14px 16px;
  z-index: 26;
  transition: opacity var(--t-panel) var(--ease), transform var(--t-panel) var(--ease),
    display var(--t-panel) allow-discrete, overlay var(--t-panel) allow-discrete;
}
@starting-style {
  #layers-sheet:not([hidden]) { opacity: 0; transform: translate(-50%, 10px); }
}
#layers-sheet header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#layers-sheet h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text-bright); }
#layers-sheet .ls-close { font-size: 17px; color: var(--text-dim); min-width: 44px; min-height: 44px; margin: -10px -12px -10px 0; }
.ls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ls-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--fill-faint);
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: left;
}
.ls-row .icon { flex: none; }
.ls-row span:nth-of-type(1) { flex: 1; }
.ls-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(125, 155, 205, 0.35);
  flex: none;
  transition: background var(--t-press) var(--ease), box-shadow var(--t-press) var(--ease);
}
.ls-row.on { color: var(--text); border-color: rgba(122, 178, 255, 0.25); }
.ls-row.on .ls-dot { background: var(--active); box-shadow: 0 0 8px rgba(122, 178, 255, 0.6); }
#layers-btn { display: none; align-items: center; gap: 6px; }
#layers-btn .layers-label { font-size: 12.5px; }

/* -- compact time display (phones get a text button, not a date field) -- */
#time-display { font-size: 12.5px; white-space: nowrap; padding: 6px 10px; font-variant-numeric: tabular-nums; }

/* -- tour dots: visible and tappable -- */
.tour-dot {
  width: 7px;
  height: 7px;
  box-sizing: content-box;
  padding: 9px;
  background-clip: content-box;
  background-color: rgba(125, 155, 205, 0.75);
}
.tour-dot.on { background-color: var(--active); }

/* -- comfortable touch targets everywhere on coarse pointers -- */
@media (pointer: coarse) {
  #toolbar button, #time-bar button, #location-btn, #tonight-btn,
  #info-close, #tonight .t-close, #tour-exit, .tour-controls button,
  #layers-sheet .ls-close,
  .info-actions button, #info-more, .dialog-row button,
  .welcome-actions button, .toast button {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .t-chip { padding: 10px 14px; }
  #search-results li { padding: 11px 10px; min-height: 44px; align-items: center; }
  .cat-chip { min-height: 44px; }
  .cat-back { min-height: 44px; }
  /* keep the close button clear of long object names */
  #info h2 { margin-right: 40px; }
  /* sub-16px inputs make iOS Safari zoom the page on focus, and the canvas
     (touch-action: none) then swallows the pinch needed to undo it */
  #search-input, #time-input, #location-dialog input, #location-dialog select,
  textarea {
    font-size: 16px;
  }
}

/* -- the sky owns the screen: idle chrome fades on phones -- */
@media (pointer: coarse) {
  #toolbar, #time-bar, #status, #search, .tsc {
    transition: opacity 0.45s var(--ease);
  }
  body.chrome-hidden :is(#toolbar, #time-bar, #status, #search, .tsc) {
    opacity: 0;
    pointer-events: none;
  }
  body.chrome-hidden :is(.sq-chip, #compass-btn) { opacity: 0.4; }
  /* the dock's pointer-events:auto (2,0,0) would defeat the fade rule
     above — invisible controls must never stay tappable */
  body.chrome-hidden #dock #dock-rail > *,
  body.chrome-hidden #dock #dock-row > * {
    pointer-events: none;
  }
  /* a focused search must never fade out from under the keyboard */
  body.searching.chrome-hidden #search { opacity: 1; pointer-events: auto; }
}

/* -- the toolbar condenses to [Sky] [night] [fullscreen] long before phone
      widths: the full 14-button row + time bar + status chip physically
      cannot share one row below ~1200px (tablets, landscape phones,
      half-screen windows) -- */
@media (max-width: 1100px), (max-height: 500px) {
  #toolbar [data-layer] { display: none; }
  #toolbar .toolbar-sep { display: none; }
  #layers-btn { display: inline-flex; }
  #time-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }
  #time-display { display: inline-flex; }
}
@media (min-width: 1101px) and (min-height: 501px) {
  #time-display { display: none !important; }
}

/* ============================================================
   MOBILE SHELL (js/sheet.js) — dock, bottom sheets, scrim
   ============================================================ */

/* -- scrim: one veil behind whichever sheet is open on compact -- */
#scrim {
  position: fixed;
  inset: 0;
  /* graded veil: the starfield stays alive above the sheet */
  background: linear-gradient(180deg, rgba(3, 6, 12, 0.25) 0%, rgba(3, 6, 12, 0.45) 45%, rgba(3, 6, 12, 0.65) 100%);
  z-index: 23;
  opacity: 1;
  transition: opacity 0.25s var(--ease), display 0.25s allow-discrete;
}
/* fade out AND release taps immediately — a lingering invisible scrim
   must never eat the first tap after a sheet closes */
#scrim[hidden] { display: none; opacity: 0; pointer-events: none; }
@starting-style { #scrim:not([hidden]) { opacity: 0; } }

/* -- drag grip: swipe down to dismiss (inserted by the shell on compact) -- */
.sheet-grip {
  height: 22px;
  margin: -6px -6px 0;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.sheet-grip::before {
  content: '';
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: rgba(133, 147, 173, 0.5);
}

/* -- the dock: scrubber rail + (time bar | toolbar) in one bottom band -- */
#dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 calc(8px + var(--safe-r)) calc(6px + var(--safe-b)) calc(8px + var(--safe-l));
  pointer-events: none;
}
#dock[hidden] { display: none; }
#dock > * { pointer-events: none; }
#dock #dock-rail, #dock #dock-row { pointer-events: none; }
#dock #dock-rail > *, #dock #dock-row > * { pointer-events: auto; }
#dock-row { display: flex; gap: 6px; align-items: stretch; }
/* both bars give up fixed positioning inside the dock */
#dock #time-bar {
  position: static;
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
  display: flex;
}
#dock #toolbar {
  position: static;
  transform: none;
  flex: 0 0 auto;
  max-width: none;
  overflow: visible;
}
/* compact time bar: [⏪ ⏯ ⏩] [Now when off-live] [date chip] */
#dock #rate-label { display: none; }
#dock #fullscreen-btn { display: none; }
#dock #time-display {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  justify-content: center;
}
#dock #time-bar.is-live #time-now { display: none; }
/* the scrubber rail rides just above the control row, full width.
   relative (not static): the time bubble is absolutely positioned and
   must keep anchoring to the rail, not to #dock */
#dock .tsc {
  position: relative;
  transform: none;
  left: auto;
  bottom: auto;
  width: 100%;
  height: 36px;
  margin: 0;
}

/* -- bottom sheets: every registered panel becomes one on compact -- */
@media (max-width: 760px), (max-height: 500px) {
  /* doubled attribute beats the single class of injected module styles;
     explicit ids beat the id rules of style.css itself */
  #tonight[data-sheet='bottom'],
  #info[data-sheet='bottom'],
  #layers-sheet[data-sheet='bottom'],
  [data-sheet='bottom'][data-sheet] {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    margin: 0;
    transform: none;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    max-height: min(82vh, calc(var(--vvh, 100vh) - 58px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: calc(14px + var(--safe-b));
    padding-left: calc(14px + var(--safe-l));
    padding-right: calc(14px + var(--safe-r));
    z-index: 28; /* above the scrim (23); DOM order breaks ties */
    backdrop-filter: blur(var(--blur-panel));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.055), 0 -12px 40px rgba(0, 0, 0, 0.5);
    transition: opacity 0.28s var(--ease), transform 0.28s var(--ease),
      display 0.28s allow-discrete, overlay 0.28s allow-discrete;
  }
  @starting-style {
    #tonight[data-sheet='bottom']:not([hidden]),
    #info[data-sheet='bottom']:not([hidden]),
    #layers-sheet[data-sheet='bottom']:not([hidden]),
    [data-sheet='bottom'][data-sheet]:not([hidden]) {
      opacity: 0;
      transform: translateY(28px);
    }
  }
  /* exits slide back down (id+attr beats the desktop id-level exit rules) */
  #tonight[data-sheet='bottom'][hidden],
  #info[data-sheet='bottom'][hidden],
  #layers-sheet[data-sheet='bottom'][hidden],
  [data-sheet='bottom'][data-sheet][hidden] {
    opacity: 0;
    transform: translateY(28px);
  }
  /* FABs step aside while a sheet is up — the sheet owns the thumb zone */
  body.sheet-open #compass-btn,
  body.sheet-open .sq-chip {
    opacity: 0;
    pointer-events: none;
  }
  /* the dock dives below the scrim while a sheet is open (z 22 < 23) */
}

/* -- landscape phones: sheets dock to the right edge instead -- */
@media (max-height: 500px) and (min-width: 500px) {
  #tonight[data-sheet='bottom'],
  #info[data-sheet='bottom'],
  #layers-sheet[data-sheet='bottom'],
  [data-sheet='bottom'][data-sheet] {
    left: auto;
    top: 0;
    bottom: 0;
    width: min(400px, 56vw);
    max-height: none;
    border-radius: var(--r-sheet) 0 0 var(--r-sheet);
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 14px;
    padding-right: calc(14px + var(--safe-r));
  }
  @starting-style {
    #tonight[data-sheet='bottom']:not([hidden]),
    #info[data-sheet='bottom']:not([hidden]),
    #layers-sheet[data-sheet='bottom']:not([hidden]),
    [data-sheet='bottom'][data-sheet]:not([hidden]) {
      opacity: 0;
      transform: translateX(28px);
    }
  }
  #tonight[data-sheet='bottom'][hidden],
  #info[data-sheet='bottom'][hidden],
  #layers-sheet[data-sheet='bottom'][hidden],
  [data-sheet='bottom'][data-sheet][hidden] {
    opacity: 0;
    transform: translateX(28px);
  }
  .sheet-grip { display: none; }
  #search { width: min(340px, 44vw); }
  #welcome { max-height: calc(100vh - 24px); overflow-y: auto; }
}
