:root {
  --space: #071127;
  --space-light: #102653;
  --panel: #f7f1dd;
  --panel-soft: #fffaf0;
  --ink: #17223d;
  --muted: #526079;
  --blue: #2d74da;
  --blue-dark: #184b9b;
  --cyan: #5dd8ff;
  --yellow: #ffd45c;
  --orange: #ff8b42;
  --green: #39a875;
  --border: #22345e;
  --shadow: rgba(0, 0, 0, 0.32);
  --top-h: 62px;
  --dock-h: 104px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: var(--space);
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; min-height: 100dvh; }
}

button, input { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }

#space {
  position: fixed;
  inset: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

#space.dragging { cursor: grabbing; }

.topbar {
  position: fixed;
  z-index: 30;
  top: 0;
  left: 0;
  right: 0;
  min-height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px))
           calc(14px + env(safe-area-inset-right, 0px))
           8px
           calc(14px + env(safe-area-inset-left, 0px));
  color: #fff;
  background: linear-gradient(180deg, #243b75, #142653);
  border-bottom: 3px solid #5b82cf;
  box-shadow: 0 5px 18px var(--shadow);
}

.brand {
  min-width: 0;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 25px;
  background: #09142e;
  border: 2px solid var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(93, 216, 255, 0.38);
}

.brand h1 { margin: 0; color: var(--yellow); font-size: 21px; line-height: 1.05; }
.brand p { margin: 2px 0 0; color: #d6e6ff; font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

.button, .icon-button, .zoomer button {
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(#fffef8, #e8dfc4);
  border: 2px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 3px 0 #101d3d, 0 5px 10px var(--shadow);
}

.button { min-height: 40px; padding: 7px 12px; font-size: 13px; }
.button:hover, .icon-button:hover, .zoomer button:hover { background: #fff6c9; }
.button:active, .icon-button:active, .zoomer button:active { transform: translateY(2px); box-shadow: 0 1px 0 #101d3d; }
.button:focus-visible, .icon-button:focus-visible, .zoomer button:focus-visible, .stop-chip:focus-visible, .answer:focus-visible, .sheet-handle:focus-visible { outline: 4px solid var(--yellow); outline-offset: 2px; }

.hud {
  position: fixed;
  z-index: 20;
  top: calc(var(--top-h) + 10px);
  left: calc(12px + env(safe-area-inset-left, 0px));
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: min(680px, calc(100vw - 420px));
  pointer-events: none;
}

.hud-card {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 6px 10px;
  color: #fff;
  background: rgba(9, 20, 46, 0.9);
  border: 2px solid #557dc7;
  border-radius: 10px;
  box-shadow: 0 4px 12px var(--shadow);
}

.hud-card span { color: #9fc8ff; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; }
.hud-card b { color: var(--yellow); font-size: 14px; }
.hud-card.wide b { color: #fff; }

.zoomer {
  position: fixed;
  z-index: 22;
  left: calc(12px + env(safe-area-inset-left, 0px));
  top: 50%;
  display: flex;
  flex-direction: column;
  gap: 7px;
  transform: translateY(-50%);
}

.zoomer button { width: 44px; height: 44px; padding: 0; font-size: 20px; }

.guide {
  position: fixed;
  z-index: 25;
  top: calc(var(--top-h) + 10px);
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: var(--dock-h);
  width: 390px;
  max-width: calc(100vw - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  background: var(--panel);
  border: 3px solid #466ab3;
  border-radius: 18px;
  box-shadow: inset 0 0 0 3px #fff, 0 8px 24px var(--shadow);
  overscroll-behavior: contain;
}

.guide.hidden { display: none; }
.sheet-handle { display: none; }
.guide-more { display: block; }
.stop-number { display: inline-block; padding: 4px 10px; color: #fff; background: var(--blue); border-radius: 14px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .45px; }
.title-row { display: flex; align-items: center; gap: 9px; margin-top: 8px; }
.stop-icon { width: 42px; height: 42px; flex: none; display: grid; place-items: center; font-size: 25px; background: #e1efff; border: 2px solid #9cc9ff; border-radius: 12px; }
.guide h2 { margin: 0; font-size: 27px; line-height: 1.1; }
.short { margin: 9px 0 0; padding: 9px 11px; font-size: 16px; font-weight: 800; line-height: 1.42; background: #fff; border-left: 5px solid var(--cyan); border-radius: 7px; }
.body-copy { margin: 14px 0 10px; color: var(--muted); font-size: 15px; line-height: 1.58; }

.dwell { margin-top: 10px; }
.dwell-track { height: 10px; overflow: hidden; background: #cbd7e8; border: 2px solid var(--border); border-radius: 10px; }
.dwell-track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--blue)); transition: width .12s linear; }
.dwell > span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }

.remember { display: flex; gap: 8px; align-items: flex-start; padding: 9px 11px; background: #fff4b8; border: 2px solid #e4b840; border-radius: 12px; }
.remember > span { font-size: 20px; }
.remember p { margin: 0; color: #5b4711; font-size: 13.5px; line-height: 1.5; }

.question, .route-section { margin-top: 16px; padding-top: 14px; border-top: 2px solid #c2cfe2; }
.question h3, .route-section h3 { margin: 0 0 6px; color: var(--blue-dark); font-size: 14px; text-transform: uppercase; letter-spacing: .5px; }
.question > p { margin: 0 0 9px; font-size: 14px; font-weight: 800; line-height: 1.4; }
.answers { display: flex; flex-wrap: wrap; gap: 7px; }
.answer { min-height: 44px; flex: 1 1 130px; padding: 8px 10px; color: var(--ink); background: #eaf4ff; border: 2px solid #7aa9e8; border-radius: 10px; font-weight: 800; cursor: pointer; }
.answer:hover { background: #d8ecff; }
.answer.correct { color: #123f2d; background: #c8f0db; border-color: var(--green); }
.answer.try-again { color: #633614; background: #ffe3c9; border-color: var(--orange); }
.feedback { min-height: 20px; margin: 8px 0 0 !important; color: var(--green); font-size: 13px !important; }
.hint { margin: 0 0 8px; color: var(--muted); font-size: 12px; }

.stop-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stop-chip { min-height: 42px; display: flex; align-items: center; gap: 7px; min-width: 0; padding: 6px 8px; color: var(--ink); background: #fff; border: 2px solid #a6b9d6; border-radius: 12px; font-size: 11.5px; font-weight: 800; text-align: left; cursor: pointer; }
.stop-chip i { width: 22px; height: 22px; flex: none; display: grid; place-items: center; color: #fff; background: #6b82a8; border-radius: 50%; font-style: normal; font-size: 10px; }
.stop-chip.seen { background: #eef9f3; border-color: #7dc8a3; }
.stop-chip.on { background: #fff2af; border-color: #e2b32e; box-shadow: 0 0 0 2px #fff; }

.dock {
  position: fixed;
  z-index: 28;
  left: calc(12px + env(safe-area-inset-left, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid #466ab3;
  border-radius: 16px;
  box-shadow: inset 0 0 0 3px #fff, 0 7px 20px var(--shadow);
}

.mission-progress { height: 9px; background: #cbd7e8; border-bottom: 2px solid #466ab3; }
.mission-progress i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--blue), #9c78ff); transition: width .2s linear; }
.dock-row { min-height: 68px; display: flex; align-items: center; gap: 15px; padding: 9px 12px 10px; }
.transport { display: flex; gap: 7px; }
.icon-button { width: 44px; height: 44px; padding: 0; font-size: 17px; }
.speed-field { min-width: 155px; display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 800; }
.speed-field b { color: var(--ink); }
.speed-field input { width: 100%; min-height: 30px; accent-color: var(--blue); }
.toggles { margin-left: auto; display: flex; align-items: center; gap: 13px; flex-wrap: wrap; }
.toggles label { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 800; cursor: pointer; }
.toggles input { width: 17px; height: 17px; accent-color: var(--blue); }

.tooltip { position: fixed; z-index: 45; max-width: 230px; padding: 7px 10px; color: var(--ink); background: #fff8d8; border: 2px solid var(--border); border-radius: 10px; box-shadow: 0 5px 15px var(--shadow); font-size: 12px; pointer-events: none; }
.tooltip b { display: block; margin-bottom: 2px; color: var(--blue-dark); font-size: 13px; }

.modal { position: fixed; z-index: 60; inset: 0; display: grid; place-items: center; padding: calc(18px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) calc(18px + env(safe-area-inset-left, 0px)); background: rgba(2, 7, 20, .76); }
.modal[hidden] { display: none; }
.modal-card { position: relative; max-width: 650px; max-height: 86vh; overflow-y: auto; padding: 24px 28px; background: var(--panel); border: 3px solid #7ba2ef; border-radius: 18px; box-shadow: inset 0 0 0 3px #fff, 0 12px 35px #000; }
.modal-card h2 { margin: 0 34px 9px 0; color: var(--blue-dark); }
.modal-card h3 { margin: 18px 0 5px; }
.modal-card p, .modal-card li { color: var(--muted); font-size: 14.5px; line-height: 1.6; }
.modal-card ul { padding-left: 22px; }
.modal-card .small { font-size: 12px; }
.modal-close { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; color: var(--ink); background: #fff; border: 2px solid var(--border); border-radius: 50%; font-size: 21px; font-weight: 800; cursor: pointer; }

/* Phones and tablets held upright use a bottom sheet. This includes 10 and
   11-inch iPads in portrait, while landscape tablets keep the side guide. */
@media (max-width: 900px), (max-width: 1100px) and (orientation: portrait) {
  :root { --top-h: 54px; }
  .topbar {
    min-height: var(--top-h);
    padding: calc(6px + env(safe-area-inset-top, 0px))
             calc(9px + env(safe-area-inset-right, 0px))
             6px
             calc(9px + env(safe-area-inset-left, 0px));
  }
  .logo { width: 35px; height: 35px; font-size: 20px; }
  .brand h1 { font-size: 18px; }
  .brand p { display: none; }
  .button { min-height: 40px; padding: 6px 9px; font-size: 11px; }
  .hud { top: calc(var(--top-h) + 7px); left: calc(8px + env(safe-area-inset-left, 0px)); max-width: calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); gap: 5px; }
  .hud-card { padding: 4px 7px; }
  .hud-card span { font-size: 8.5px; }
  .hud-card b { font-size: 11.5px; }
  .hud-card.wide { width: 100%; max-width: 300px; }
  .zoomer { left: calc(8px + env(safe-area-inset-left, 0px)); top: calc(var(--top-h) + 68px); flex-direction: row; transform: none; }
  .zoomer button { width: 44px; height: 44px; font-size: 17px; }

  .guide { top: auto; left: calc(8px + env(safe-area-inset-left, 0px)); right: calc(8px + env(safe-area-inset-right, 0px)); bottom: var(--dock-h); width: auto; max-height: 37vh; max-height: 37dvh; padding: 0 12px 12px; border-radius: 16px; }
  .guide h2 { font-size: 21px; }
  .title-row { margin-top: 5px; }
  .stop-icon { width: 34px; height: 34px; font-size: 20px; }
  .short { padding: 6px 9px; font-size: 14px; margin-top: 6px; }
  .body-copy { font-size: 14px; }
  .guide-more { display: none; }
  .guide.open { max-height: 61vh; max-height: 61dvh; }
  .guide.open .guide-more { display: block; }
  .guide:not(.open) .short { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

  .sheet-handle { min-height: 44px; position: sticky; z-index: 3; top: 0; width: calc(100% + 24px); margin: 0 -12px 4px; padding: 8px 12px; display: flex; align-items: center; gap: 8px; color: var(--muted); background: var(--panel); border: 0; border-bottom: 2px solid #c2cfe2; font-size: 12px; font-weight: 800; cursor: pointer; }
  .grip { width: 36px; height: 5px; background: #a1afc3; border-radius: 5px; }
  .caret { margin-left: auto; font-size: 18px; }
  .guide.open .caret { transform: rotate(180deg); }

  .dock { left: calc(8px + env(safe-area-inset-left, 0px)); right: calc(8px + env(safe-area-inset-right, 0px)); bottom: calc(7px + env(safe-area-inset-bottom, 0px)); }
  .dock-row { min-height: 0; gap: 9px; padding: 7px 9px 8px; flex-wrap: wrap; }
  .icon-button { width: 44px; height: 44px; font-size: 15px; }
  .speed-field { min-width: 80px; flex: 1 1 100px; }
  .toggles { width: 100%; margin-left: 0; justify-content: space-between; gap: 6px; }
  .toggles label { min-height: 38px; font-size: 10.5px; }
}

/* Landscape iPads keep the map wide by using a slightly narrower side guide and
   denser transport row, without shrinking any touch target. */
@media (min-width: 901px) and (max-width: 1180px) and (orientation: landscape) {
  .guide { width: 348px; }
  .dock-row { gap: 10px; }
  .speed-field { min-width: 130px; }
  .toggles { gap: 8px; }
  .toggles label { min-height: 44px; font-size: 11px; }
  .hud { max-width: calc(100vw - 390px); }
}

@media (max-width: 430px) {
  .top-actions .button:first-child { display: none; }
  .guide { max-height: 34vh; }
  .guide.open { max-height: 57vh; }
  .hud-card.wide { display: none; }
  .stop-list { grid-template-columns: 1fr; }
  .toggles label { font-size: 10px; }
}

@media (max-height: 580px) and (min-width: 650px) {
  .guide { top: calc(var(--top-h) + 7px); right: calc(8px + env(safe-area-inset-right, 0px)); bottom: var(--dock-h); left: auto; width: 330px; max-height: none; padding: 12px; }
  .guide-more { display: block; }
  .sheet-handle { display: none; }
  .zoomer { top: auto; bottom: calc(var(--dock-h) + 8px); left: calc(8px + env(safe-area-inset-left, 0px)); flex-direction: column; }
}

@media (pointer: coarse) {
  .stop-chip, .answer, .toggles label { min-height: 44px; }
  .modal-close { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
