:root {
  --ink: #173D52;
  --plate: #D9D9D9;
  --icon: #E3E3E3;
  --paper: #FFFFFF;
  --danger: #8C2F2F;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #2b3a44; color: var(--ink); font-family: var(--font); overscroll-behavior: none; }
button { font: inherit; cursor: pointer; }
svg { fill: currentColor; }

.app { position: fixed; inset: 0; overflow: hidden; }

/* Map viewport ------------------------------------------------------- */
.viewport {
  position: absolute; inset: 0;
  overflow: auto; -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
}
.viewport::-webkit-scrollbar { display: none; }
.stage { position: relative; display: flex; align-items: flex-start; transform-origin: 0 0; }
.pane { position: relative; flex: none; background: #4a5a66; }
.pane + .pane { margin-left: 8px; }
.pane img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.pane img.missing { visibility: hidden; }
.pane .missing-label { position: absolute; inset: 0; display: grid; place-items: center; color: var(--icon); font-size: 14px; text-align: center; padding: 16px; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Zone overlay */
.zone-shape { stroke: #000; stroke-width: 1; cursor: pointer; }
.zone-shape:focus-visible, .zone-shape:hover { stroke: var(--paper); stroke-width: 3; }
.zone-label { fill: #fff; font-weight: 700; font-size: 48px; pointer-events: none; font-family: var(--font); }

/* Feature marks */
.feat { cursor: pointer; }
.feat .hit { fill: transparent; stroke: none; }
.feat .outline { fill: none; stroke: var(--ink); stroke-dasharray: 4 4; opacity: .85; }
.feat.done .mark { fill: var(--plate); stroke: var(--ink); stroke-width: 1.5; }
.feat.done .date { fill: var(--ink); font-weight: 600; text-anchor: middle; font-family: var(--font); pointer-events: none; }
.feat.done .who { fill: var(--ink); font-weight: 400; text-anchor: middle; font-family: var(--font); pointer-events: none; }
.feat.editing .outline { stroke: #FFD24D; stroke-dasharray: none; stroke-width: 2; }
.progress-dot { fill: #FF973D; stroke: var(--ink); stroke-width: 1; pointer-events: none; }
.draft { fill: rgba(255,210,77,.25); stroke: #FFD24D; stroke-width: 2; pointer-events: none; }
.draft-pt { fill: #FFD24D; pointer-events: none; }

/* Banner -------------------------------------------------------------- */
.banner {
  position: absolute; left: 0; top: 0; padding: calc(18px + var(--safe-t)) 54px 18px;
  background: var(--plate); color: var(--ink); border-bottom-right-radius: 4px;
  pointer-events: none;
}
.banner-title { font-size: 32px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; }
.banner-sub { font-size: 12px; font-weight: 600; margin-top: 2px; }
@media (max-width: 480px) {
  .banner { padding-left: 20px; padding-right: 24px; }
  .banner-title { font-size: 24px; }
}

/* Control plates ------------------------------------------------------ */
.plate {
  position: absolute; display: flex; gap: 12px; padding: 16px;
  background: var(--plate); border-radius: 6px;
}
.plate-home, .plate-zone { right: 12px; bottom: calc(12px + var(--safe-b)); }
.plate-zoom { left: 12px; bottom: calc(12px + var(--safe-b)); flex-direction: column; gap: 8px; padding: 10px; }
.ibtn {
  width: 58px; height: 58px; border: 0; border-radius: 6px;
  background: var(--ink); color: var(--icon); display: grid; place-items: center;
}
.ibtn svg { width: 28px; height: 28px; }
.ibtn.sm { width: 44px; height: 44px; }
.ibtn.sm svg { width: 22px; height: 22px; }
.ibtn:active { filter: brightness(1.25); }
.ibtn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.app[data-view="home"] .plate-zone { display: none; }
.app[data-view="zone"] .plate-home { display: none; }

/* Edit toolbar -------------------------------------------------------- */
.edit-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b));
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  background: var(--plate); padding: 10px 12px; border-radius: 6px; max-width: calc(100% - 200px);
}
.edit-title { font-weight: 700; font-size: 14px; margin-right: 4px; }
.tbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
  border: 2px solid var(--ink); border-radius: 6px; background: var(--paper); color: var(--ink); font-weight: 600; font-size: 14px;
}
.tbtn svg { width: 18px; height: 18px; }
.tbtn.on { background: var(--ink); color: var(--icon); }
.edit-hint { flex-basis: 100%; font-size: 12px; text-align: center; min-height: 1em; }
@media (max-width: 640px) {
  .edit-bar { bottom: calc(110px + var(--safe-b)); max-width: calc(100% - 24px); }
}
/* landscape phones: keep the edit bar between the zoom plate and the right-hand plate */
@media (max-height: 500px) and (min-width: 641px) {
  .edit-bar { left: 92px; right: 258px; transform: none; max-width: none; bottom: calc(12px + var(--safe-b)); }
  .banner { padding-top: calc(10px + var(--safe-t)); padding-bottom: 10px; }
  .banner-title { font-size: 24px; }
}

/* Settings panel ------------------------------------------------------ */
.settings {
  position: absolute; top: 0; right: 0; bottom: 0; width: 300px; max-width: 88vw;
  background: var(--plate); color: var(--ink); padding: calc(20px + var(--safe-t)) 24px calc(20px + var(--safe-b));
  overflow-y: auto; transform: translateX(100%); transition: transform .22s ease; z-index: 20;
}
.settings.open { transform: none; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.25); z-index: 15; display: none; }
.scrim.open { display: block; }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.settings h2 { margin: 0; font-size: 20px; font-weight: 700; }
.xbtn { border: 0; background: transparent; color: var(--ink); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; }
.xbtn svg { width: 22px; height: 22px; }
.srow { margin-bottom: 22px; }
.srow > label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.srow > label.chk, .chk { display: flex; margin-bottom: 0; gap: 8px; align-items: center; font-size: 13px; font-weight: 500; cursor: pointer; }
.chk input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chk-icon { width: 24px; height: 24px; flex: none; color: var(--ink); }
.chk-icon svg { width: 24px; height: 24px; display: none; }
.chk input:not(:checked) + .chk-icon .off { display: block; }
.chk input:checked + .chk-icon .on { display: block; }
.chk input:focus-visible + .chk-icon { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 3px; }
.sel, .txt, .num {
  width: 100%; height: 40px; border: 1.5px solid var(--ink); border-radius: 4px; background: var(--paper);
  color: var(--ink); padding: 0 10px; font: inherit; font-size: 15px;
}
.num { width: 88px; text-align: center; }
.wbtn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  border: 1.5px solid var(--ink); border-radius: 4px; background: var(--paper); color: var(--ink); font-weight: 600; font-size: 14px;
}
.wbtn svg { width: 18px; height: 18px; }
.wbtn.primary { background: var(--ink); color: var(--icon); }
.wbtn.danger { border-color: var(--danger); color: var(--danger); }
.wbtn:disabled { opacity: .45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.hint { font-size: 12px; margin: 0 0 8px; line-height: 1.4; }
.crew-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.crew-item { display: flex; align-items: center; justify-content: space-between; background: var(--paper); border-radius: 4px; padding: 6px 6px 6px 10px; font-size: 14px; }
.crew-item .xbtn { width: 28px; height: 28px; }
.crew-item .xbtn svg { width: 16px; height: 16px; }
.crew-add { display: flex; gap: 8px; }
.settings-foot { font-size: 11px; opacity: .7; margin-top: 12px; }

/* Dialog + toast ------------------------------------------------------ */
.dialog { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0,0,0,.35); }
.dialog[hidden] { display: none; }
.dialog-box { background: var(--plate); border-radius: 8px; padding: 20px; width: min(340px, 90vw); }
.dialog-box p { margin: 0 0 14px; font-size: 15px; line-height: 1.4; }
.dialog-box .num { width: 100%; margin-bottom: 14px; letter-spacing: .3em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: absolute; left: 50%; top: calc(14px + var(--safe-t)); transform: translateX(-50%);
  background: var(--ink); color: var(--icon); padding: 10px 16px; border-radius: 6px; font-size: 14px; z-index: 40;
  max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) { .settings { transition: none; } }

/* Phase 2 ------------------------------------------------------------- */
.ghost { position: absolute; border: 3px solid #FF973D; box-shadow: 0 0 0 2px rgba(23,61,82,.6); cursor: grab; touch-action: none; }
.ghost img { display: block; width: 100%; height: 100%; opacity: .6; pointer-events: none; -webkit-user-drag: none; }
.app[data-calib="1"] .zone-shape { pointer-events: none; }
.app[data-calib="1"] .plate-zone { display: none; }
.pane-picker { display: inline-flex; gap: 6px; }
.sync-label { font-size: 12px; margin: -10px 0 18px; opacity: .8; }
.hist { margin-top: 8px; max-height: 260px; overflow-y: auto; background: var(--paper); border-radius: 4px; padding: 6px 10px; font-size: 12px; line-height: 1.5; }
.hist-row + .hist-row { border-top: 1px solid rgba(23,61,82,.15); }
