/* Operation Ngao Salama: situation-board theme.
   Navy ground, amber reserved for injects and urgency, teal for decisions. */
:root {
  --ink: #0d2236;
  --deep: #081726;
  --panel: #133049;
  --panel-2: #194060;
  --line: #2b5073;
  --text: #eaf1f6;
  --muted: #9bb3c6;
  --amber: #ffb224;
  --amber-ink: #2a1b00;
  --teal: #38c9b6;
  --teal-ink: #05231f;
  --sky: #6db6ff;
  --red: #ff6b5e;
  --green: #5fd38d;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --font-display: Bahnschrift, "DIN Alternate", "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: 0.01em; margin: 0 0 0.4em; line-height: 1.2; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.8em; }
a { color: var(--sky); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.grow { flex: 1 1 auto; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 0.8rem; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- buttons, fields ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 5px; padding: 0.55rem 0.95rem; cursor: pointer; font-weight: 600; min-height: 42px;
}
.btn:hover:not(:disabled) { border-color: var(--sky); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--teal-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.amber { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.btn.danger { border-color: var(--red); color: var(--red); background: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn.on { background: var(--sky); color: #04213a; border-color: var(--sky); }

.field { display: block; margin-bottom: 0.9rem; }
.field > .lab { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.field > .hint { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%; background: var(--deep); border: 1px solid var(--line); border-radius: 5px;
  padding: 0.6rem 0.7rem; min-height: 42px;
}
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: #6f8aa0; }

.chip {
  display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8rem;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); margin: 0 0.25rem 0.25rem 0;
}
.chip.amber { border-color: var(--amber); color: var(--amber); }
.chip.teal { border-color: var(--teal); color: var(--teal); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #55708a; margin-right: 0.4rem; vertical-align: middle; }
.dot.on { background: var(--green); }
.dot.warn { background: var(--amber); }
.dot.off { background: var(--red); }

/* ---------- step cards ---------- */
.card {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 1.1rem 1.25rem 1rem 1.6rem; overflow: hidden;
}
.card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 9px; background: var(--sky); }
.card.k-inject::before { background: repeating-linear-gradient(135deg, var(--amber) 0 8px, #4a3300 8px 16px); width: 12px; }
.card.k-decision::before { background: var(--teal); }
.card.k-debrief::before, .card.k-end::before { background: var(--green); }
.card.k-phase::before { background: var(--panel-2); }
.card-tag { display: flex; gap: 0.8rem; align-items: baseline; margin-bottom: 0.35rem; color: var(--muted); font-size: 0.9rem; }
.card-tag .tagtext { font-weight: 700; color: var(--text); }
.card.k-inject .tagtext { color: var(--amber); }
.card.k-decision .tagtext { color: var(--teal); }
.card-tag .at { font-variant-numeric: tabular-nums; margin-left: auto; font-family: var(--font-display); }
.card-title { font-size: 1.5rem; }
.prompt { font-size: 1.15rem; font-weight: 600; margin: 0.4rem 0 0.5rem; }
.blist { margin: 0.2rem 0 0.6rem; padding-left: 1.2rem; }
.blist li { margin-bottom: 0.35rem; }
.blist.subs { color: var(--muted); }

.optlist { list-style: none; padding: 0; margin: 0.6rem 0 0; }
.optlist li { display: flex; gap: 0.7rem; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 5px; margin-bottom: 0.4rem; background: var(--deep); }
.optlist .k { font-family: var(--font-display); color: var(--teal); min-width: 1.4em; font-weight: 700; }

/* ---------- answer forms ---------- */
.choice { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.75rem 0.85rem; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 0.5rem; background: var(--deep); cursor: pointer; }
.choice:hover { border-color: var(--sky); }
.choice input { margin-top: 0.3rem; width: 20px; height: 20px; accent-color: var(--teal); flex: none; }
.choice.sel { border-color: var(--teal); background: #0b2d33; }
.ranklist { list-style: none; padding: 0; margin: 0 0 0.8rem; counter-reset: r; }
.ranklist li { display: flex; gap: 0.6rem; align-items: center; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 0.4rem; background: var(--deep); }
.ranklist .pos { font-family: var(--font-display); font-size: 1.2rem; color: var(--teal); min-width: 1.5em; text-align: center; }
.ranklist .lbl { flex: 1; }
.ranklist .mv { display: flex; flex-direction: column; gap: 0.2rem; }
.ranklist .mv button { min-height: 30px; min-width: 40px; padding: 0 0.5rem; }
.scalerow { display: flex; gap: 0.5rem; margin-bottom: 0.4rem; }
.scalerow label { position: relative; flex: 1; text-align: center; border: 1px solid var(--line); border-radius: 6px; padding: 0.8rem 0; cursor: pointer; background: var(--deep); font-family: var(--font-display); font-size: 1.4rem; }
.scalerow input { position: absolute; opacity: 0; }
.scalerow label.sel { background: var(--teal); color: var(--teal-ink); border-color: var(--teal); }
.scaleends { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.8rem; }
.notice { border: 1px solid var(--line); border-left: 4px solid var(--sky); background: var(--panel); border-radius: 5px; padding: 0.7rem 0.9rem; margin: 0.8rem 0; }
.notice.ok { border-left-color: var(--green); }
.notice.warn { border-left-color: var(--amber); }
.notice.bad { border-left-color: var(--red); }

/* ---------- timer ---------- */
.timer { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 1.6rem; padding: 0.1rem 0.7rem; border: 2px solid var(--teal); color: var(--teal); border-radius: 6px; min-width: 5.2ch; text-align: center; }
.timer.warn { border-color: var(--amber); color: var(--amber); }
.timer.over { border-color: var(--red); color: var(--red); }
.timer.idle { border-color: var(--line); color: var(--muted); }

/* ---------- results ---------- */
.results h3 { margin-top: 1rem; }
.bar { margin-bottom: 0.7rem; }
.bar-label { display: flex; gap: 0.5rem; justify-content: space-between; margin-bottom: 0.2rem; }
.bar-track { background: var(--deep); border-radius: 4px; height: 18px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; background: var(--sky); width: 0; transition: width 0.5s ease; }
.bar.best .bar-fill { background: var(--green); }
.bar.must .bar-fill { background: var(--green); }
.bar.weak .bar-fill { background: #5d7488; }
.bar-n { font-variant-numeric: tabular-nums; font-weight: 700; }
.bar-teams { margin-top: 0.25rem; }
.ans-card { border: 1px solid var(--line); border-radius: 6px; padding: 0.7rem 0.85rem; margin-bottom: 0.6rem; background: var(--deep); }
.ans-card.pinned { border-color: var(--amber); }
.ans-head { display: flex; gap: 0.5rem; align-items: baseline; margin-bottom: 0.3rem; flex-wrap: wrap; }
.ans-head b { font-family: var(--font-display); font-size: 1.05rem; }
.ans-field { margin: 0.2rem 0; }
.ans-field span.k { color: var(--muted); font-size: 0.85rem; margin-right: 0.4rem; }
.ans-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.score-ctl { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--line); align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); min-width: 32px; min-height: 30px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--teal); color: var(--teal-ink); font-weight: 700; }
.model { border: 1px solid var(--green); border-radius: 6px; padding: 0.8rem 1rem; margin-top: 1rem; background: #0e2d27; }
.model h3 { color: var(--green); }
.legal-chip { display: inline-block; background: #0b241f; border: 1px solid #2c6b55; border-radius: 4px; padding: 0.05rem 0.5rem; font-size: 0.82rem; margin: 0 0.3rem 0.3rem 0; }

/* ---------- tables, tabs, modal, toast ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tbl th, .tbl td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.tbl tr.me td { background: #0f3a4a; }
.tbl td.r, .tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--line); margin-bottom: 0.8rem; overflow-x: auto; }
.tab { background: transparent; border: 0; border-bottom: 3px solid transparent; padding: 0.55rem 0.8rem; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tab.on { color: var(--text); border-bottom-color: var(--teal); }
.modal-back { position: fixed; inset: 0; background: rgba(4, 12, 20, 0.8); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1.4rem; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; }
.qr { background: #fff; padding: 12px; border-radius: 6px; display: inline-block; line-height: 0; }
.qr svg { width: 100%; height: auto; display: block; }
#toasts { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 60; display: grid; gap: 0.4rem; width: min(92vw, 520px); pointer-events: none; }
.toast { background: var(--deep); border: 1px solid var(--teal); border-left-width: 6px; border-radius: 5px; padding: 0.6rem 0.9rem; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.toast.amber { border-color: var(--amber); }
.toast.bad { border-color: var(--red); }

/* ---------- team (mobile first) ---------- */
.team-shell { max-width: 720px; margin: 0 auto; padding: 0 0.9rem 5rem; }
.team-top { position: sticky; top: 0; z-index: 10; background: var(--deep); border-bottom: 1px solid var(--line); margin: 0 -0.9rem 1rem; padding: 0.6rem 0.9rem; display: flex; gap: 0.7rem; align-items: center; }
.team-top .who { min-width: 0; flex: 1; }
.team-top .who b { font-family: var(--font-display); font-size: 1.1rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.join-wrap { max-width: 480px; margin: 0 auto; padding: 2rem 1rem; }
.brand { display: flex; gap: 0.8rem; align-items: center; margin-bottom: 1.4rem; }
.brand img { width: 44px; height: 44px; }
.brand h1 { margin: 0; font-size: 1.5rem; }
.brand p { margin: 0; color: var(--muted); }
.banner { position: sticky; top: 0; z-index: 20; background: var(--amber); color: var(--amber-ink); padding: 0.5rem 0.9rem; font-weight: 700; text-align: center; }
.waiting { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.waiting b { color: var(--text); font-size: 1.3rem; display: block; margin-bottom: 0.4rem; font-family: var(--font-display); }

/* ---------- facilitator console ---------- */
.fac-top { display: flex; gap: 0.8rem; align-items: center; padding: 0.6rem 1rem; background: var(--deep); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.fac-top h1 { font-size: 1.15rem; margin: 0; }
.code-chip { font-family: var(--font-display); letter-spacing: 0.15em; font-size: 1.3rem; border: 1px dashed var(--amber); color: var(--amber); padding: 0 0.6rem; border-radius: 5px; cursor: pointer; background: transparent; }
.fac-grid { display: grid; grid-template-columns: 290px minmax(0, 1fr) minmax(360px, 440px); gap: 1rem; padding: 1rem; align-items: start; }
.fac-col { min-width: 0; }
.fac-nav { max-height: calc(100vh - 100px); overflow: auto; position: sticky; top: 70px; }
.fac-nav details { margin-bottom: 0.6rem; }
.fac-nav summary { cursor: pointer; font-family: var(--font-display); font-weight: 600; padding: 0.3rem 0; }
.navitem { display: flex; gap: 0.4rem; align-items: center; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 5px; padding: 0.3rem 0.4rem; cursor: pointer; color: var(--text); font-size: 0.9rem; }
.navitem:hover { background: var(--panel); }
.navitem.cur { background: var(--panel-2); border-color: var(--teal); }
.navitem.done { color: var(--muted); }
.navitem.skipped .nt { text-decoration: line-through; color: #6f8aa0; }
.navitem .nt { flex: 1; min-width: 0; }
.navitem .badge { font-variant-numeric: tabular-nums; font-size: 0.78rem; color: var(--muted); }
.navitem input[type="checkbox"] { accent-color: var(--teal); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 0.9rem 1rem; margin-bottom: 1rem; }
.panel h3 { margin-bottom: 0.5rem; }
.progress { height: 10px; background: var(--deep); border-radius: 5px; border: 1px solid var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--teal); transition: width 0.4s ease; }
.ctl-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0.5rem 0; }
.ctl-row select { width: auto; }

/* ---------- display wall ---------- */
body.display { font-size: clamp(16px, 1.45vw, 36px); overflow: hidden; height: 100vh; }
.wall { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.wall-top { display: flex; gap: 1.2rem; align-items: center; padding: 0.7rem 1.6rem; background: var(--deep); border-bottom: 2px solid var(--line); }
.wall-top .ttl { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }
.wall-clock { margin-left: auto; text-align: right; line-height: 1.05; }
.wall-clock .t { font-family: var(--font-display); font-size: 2.3rem; font-variant-numeric: tabular-nums; color: var(--amber); }
.wall-clock .l { color: var(--muted); font-size: 0.8rem; }
.wall-join { text-align: right; line-height: 1.1; }
.wall-join .c { font-family: var(--font-display); font-size: 1.6rem; letter-spacing: 0.14em; color: var(--text); }
.wall-main { min-height: 0; padding: 1.4rem 1.8rem; overflow: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.2rem; align-content: start; }
.wall-main.two { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.wall .card-title { font-size: 2.1rem; }
.wall .card p, .wall .card li { font-size: 1.2rem; }
.wall .prompt { font-size: 1.6rem; }
.wall .optlist li { font-size: 1.1rem; }
.wall .timer { font-size: 3.4rem; padding: 0.1rem 1rem; }
.wall .qr { width: 15rem; }
.wall .bar-label { font-size: 1.15rem; }
.wall .bar-track { height: 26px; }
.wall-lobby { display: grid; grid-template-columns: 1fr auto; gap: 3rem; align-items: center; padding: 3rem; }
.wall-lobby h1 { font-size: 3.4rem; }
.wall-flash { background: var(--amber); color: var(--amber-ink); font-weight: 700; font-size: 1.5rem; padding: 0.7rem 1.6rem; }
.lb-row { display: grid; grid-template-columns: 2.2rem 1fr 6rem; gap: 0.8rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); font-size: 1.3rem; align-items: center; }
.lb-row .rk { font-family: var(--font-display); color: var(--amber); }
.lb-row .sc { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-display); }

/* ---------- report ---------- */
body.report { background: #f4f6f8; color: #14212e; }
.rep { max-width: 940px; margin: 0 auto; background: #fff; padding: 2.2rem 2.6rem; line-height: 1.5; }
.rep h1, .rep h2, .rep h3 { color: #0d2236; }
.rep h2 { border-bottom: 2px solid #0d2236; padding-bottom: 0.2rem; margin-top: 1.8rem; }
.rep table { width: 100%; border-collapse: collapse; margin: 0.6rem 0 1rem; font-size: 0.92rem; }
.rep th, .rep td { border: 1px solid #c8d3dc; padding: 0.35rem 0.5rem; text-align: left; vertical-align: top; }
.rep th { background: #e8eef3; }
.rep .tag { display: inline-block; font-size: 0.78rem; padding: 0 0.45rem; border-radius: 3px; border: 1px solid #9fb3c6; margin-right: 0.3rem; }
.rep .good { color: #12683a; }
.rep .gap { color: #a3321f; }
.rep [contenteditable] { outline: 1px dashed #9fb3c6; min-height: 3rem; padding: 0.4rem; }
.rep-bar { max-width: 940px; margin: 1rem auto; display: flex; gap: 0.6rem; }
.rep .bar-track { background: #e8eef3; border-color: #c8d3dc; }
.rep .bar-fill { background: #2e7bbd; }

@media (max-width: 1180px) {
  .fac-grid { grid-template-columns: 1fr; }
  .fac-nav { position: static; max-height: 320px; }
}
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .card-title { font-size: 1.3rem; }
  .card { padding-left: 1.4rem; }
}
@media (prefers-reduced-motion: reduce) {
  .bar-fill, .progress > div { transition: none; }
}
@media print {
  body.report { background: #fff; }
  .rep { padding: 0; max-width: none; }
  .rep-bar, #toasts { display: none !important; }
  .rep h2 { break-after: avoid; }
  .rep table, .rep tr { break-inside: avoid; }
  .rep [contenteditable] { outline: none; }
}

/* report overrides: light, print-friendly */
.rep .chip { background: #eef3f7; color: #34506a; border-color: #c8d3dc; }
.rep h4 { font-family: var(--font-display); font-size: 1.05rem; color: #0d2236; }
.rep .small { color: #3a4f63; }
.rep .notice { background: #fff; color: #14212e; }

/* ---- v2 additions ---- */
.kindrow { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.kind { display: flex; flex-direction: column; gap: 0.2rem; padding: 0.8rem; border: 2px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--deep); position: relative; }
.kind input { position: absolute; opacity: 0; }
.kind.sel { border-color: var(--teal); background: #0b2d33; }
.kind b { font-family: var(--font-display); font-size: 1.15rem; }
.ans-main { font-size: 1.05rem; }
.spot { border: 2px solid var(--amber); border-radius: 8px; padding: 1rem 1.2rem; background: var(--panel); }
.spot .who { font-family: var(--font-display); font-size: 1.6rem; }
.wall .spot .who { font-size: 2.6rem; }
.wall .spot .ans-main, .wall .spot .ans-field, .wall .spot li { font-size: 1.6rem; }
.step-list .navitem .nt { font-size: 0.9rem; }
.bigbtn { width: 100%; min-height: 56px; font-size: 1.1rem; }
.answer-row { display: block; width: 100%; text-align: left; background: var(--deep); border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.7rem; margin-bottom: 0.4rem; cursor: pointer; }
.answer-row.cur { border-color: var(--amber); background: #2b2410; }
.answer-row .pv { display: block; color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
