:root {
  --bg: #0b1016;
  --panel: #131b25;
  --panel-2: #1a2430;
  --line: #263344;
  --line-soft: #1c2633;
  --text: #e6edf5;
  --muted: #8495a8;
  --ice: #7cc7ff;
  --ice-dim: #2b5a80;
  --ok: #4ade80;
  --amber: #fbbf24;
  --red: #f43f5e;
  --rose: #ffc2cf;
  --violet: #a78bfa;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
h2 { font-size: .9rem; margin: 0 0 .7rem; letter-spacing: .05em; text-transform: uppercase; color: var(--ice); }
h3 { font-size: .78rem; margin: .8rem 0 .3rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
a { color: var(--ice); }
main { padding: 16px; max-width: 1500px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
main.narrow { max-width: 420px; margin-top: 10vh; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
button, input, select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
input, select { min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--ice-dim); border-color: var(--ice); }
button { cursor: pointer; background: var(--ice-dim); border-color: var(--ice-dim); font-weight: 600; }
button:hover { filter: brightness(1.15); }
button:focus-visible { outline: 2px solid var(--ice); outline-offset: 2px; }
button.ghost { background: transparent; border-color: var(--line); font-weight: 500; }
button.danger { background: transparent; border-color: #5c2232; color: #ff8fa3; }
button.small { padding: 3px 9px; font-size: .85rem; }
input.short { width: 120px; }
input.tiny { width: 72px; padding: 4px 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; }
legend { color: var(--muted); padding: 0 4px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nowrap { white-space: nowrap; flex-wrap: nowrap; }
.spacer { flex: 1; }
.right { margin-left: auto; text-align: right; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
label.inline { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--muted); }
label.radio, label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }
.muted { color: var(--muted); }
.small-text { font-size: .8rem; }
.hint { color: var(--muted); font-size: .84rem; margin: 6px 0 0; }
.mono { font-family: var(--mono); }
.ok { color: var(--ok); }
.warn-text { color: var(--amber); }
.error-text { color: var(--red); min-height: 1.2em; margin: 0; }
.center { text-align: center; }
.tag { font-size: .74rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.ally-tag { display: inline-block; font-weight: 800; font-size: .78rem; letter-spacing: .06em; padding: 1px 7px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3b4757; margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.team-badge { display: inline-block; font-weight: 700; padding: 1px 9px; border-radius: 6px; background: var(--ice-dim); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 5px 0; display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line-soft); }
ul.plain li:last-child { border-bottom: 0; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: #0e151d; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.role-chip { font-size: .74rem; padding: 2px 9px; border-radius: 99px; background: var(--ice-dim); }
.clock { font-family: var(--mono); font-size: 1.45rem; font-weight: 700; color: var(--ice); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn { font-size: .78rem; padding: 2px 8px; border-radius: 99px; }
.conn.on { background: #123524; color: var(--ok); }
.conn.off { background: #3a1520; color: var(--red); }
.sound-btn { background: #3a2a10; border-color: #6b4d18; color: var(--amber); }
.sound-btn.enabled { background: transparent; border-color: var(--line); color: var(--muted); font-weight: 500; }

/* ---------- layout ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.primary { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 72px; }
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }

/* ---------- start page ---------- */
.start-main { max-width: 760px; margin: 0 auto; padding: 8vh 16px 32px; }
.start-head { text-align: center; }
.start-brand { font-size: 2rem; font-weight: 800; color: var(--ice); }
.role-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.role-card { display: flex; flex-direction: column; gap: 8px; text-align: left; padding: 28px 24px; background: var(--panel); border: 2px solid var(--ice-dim); border-radius: 14px; font-weight: 400; }
.role-card:hover, .role-card:focus-visible { border-color: var(--ice); filter: none; background: var(--panel-2); }
.role-card.org { border-color: #4a1d2a; }
.role-card.org:hover, .role-card.org:focus-visible { border-color: var(--red); }
.role-title { font-size: 1.35rem; font-weight: 800; color: var(--text); }
.role-desc { color: var(--muted); }
.start-form { max-width: 460px; margin: 0 auto; width: 100%; }
.new-note { margin: 4px 0 0; color: var(--ice); font-weight: 600; }
.admin-link { color: var(--muted); font-size: .85rem; }

/* ---------- leader ---------- */
.ident { font-size: 1.15rem; }
/* Fixed bar (not in the page flow): when it disappears nothing else moves. */
.sound-warning { position: fixed; z-index: 40; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(760px, calc(100% - 32px)); padding: 14px; font-size: 1.1rem; font-weight: 800; background: #3a2a10; border: 2px solid var(--amber); color: var(--amber); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0, 0, 0, .6); animation: pulse 1s infinite alternate; }
.big { text-align: center; border-radius: 16px; padding: 26px 16px 22px; border: 2px solid var(--line); background: var(--panel); }
.big-label { font-size: clamp(1.1rem, 2.4vw, 1.9rem); font-weight: 800; letter-spacing: .08em; }
.big-time { font-family: var(--mono); font-weight: 800; line-height: 1; margin: 10px 0; font-size: clamp(4.5rem, 14vw, 11rem); }
.big-sub { color: var(--muted); min-height: 1.4em; }
.big.idle .big-time { color: #3b4757; }
.big.standby { border-color: #1f5e3d; }
.big.standby .big-time { color: var(--ok); font-size: clamp(3rem, 9vw, 6.5rem); }
.big.pre { border-color: var(--ice-dim); }
.big.pre.soon { border-color: var(--amber); }
.big.pre.soon .big-time { color: var(--amber); }
.big.pre.critical { border-color: var(--red); background: #2a0f17; }
.big.pre.critical .big-time { color: var(--red); animation: pulse .5s infinite alternate; }
.big.go { border-color: var(--ok); background: #0f3020; animation: flashbg .25s infinite alternate; }
.big.go .big-time, .big.go .big-label { color: var(--ok); }
.big.fill { border-color: var(--ice); }
.big.fill .big-time { color: var(--ice); }
.big.march { border-color: var(--violet); }
.big.march .big-time { color: var(--violet); }
.big.landed .big-time, .big.returning .big-time { color: var(--muted); }
.big.cancelled { border-color: var(--red); }
.big.cancelled .big-time { color: var(--red); }
.roger { margin-top: 14px; padding: 14px 40px; font-size: 1.4rem; font-weight: 900; letter-spacing: .08em; background: var(--ok); border-color: var(--ok); color: #062814; border-radius: 12px; animation: pulse .6s infinite alternate; }
.banner { text-align: center; font-weight: 700; font-size: 1.1rem; padding: 12px; border-radius: var(--radius); background: #2d2310; border: 1px solid #6b4d18; color: var(--amber); }
.banner.calm { font-weight: 500; font-size: 1rem; }
.banner.critical { background: #3a1520; border-color: var(--red); color: var(--rose); animation: pulse .6s infinite alternate; }
.warnings { display: flex; flex-direction: column; gap: 6px; }
.warn { background: #2d2310; border: 1px solid #6b4d18; color: var(--amber); padding: 8px 12px; border-radius: 8px; }
.info-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin-bottom: 10px; }
.info-grid .k { color: var(--muted); }
.castle-now { font-size: 1.15rem; }
.feed { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; font-size: .88rem; }
.feed-row { line-height: 1.35; }
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(120, 10, 30, .92); display: flex; align-items: center; justify-content: center; padding: 16px; animation: flashred .35s infinite alternate; }
.overlay-box { text-align: center; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.overlay-title { font-size: clamp(2.4rem, 8vw, 6rem); font-weight: 900; letter-spacing: .05em; color: #fff; }
.overlay-sub { font-size: 1.3rem; color: #ffe1e7; }
.overlay-btn { padding: 16px 48px; font-size: 1.4rem; font-weight: 800; background: #fff; color: #7a0a1e; border-color: #fff; border-radius: 12px; }
body.flash { animation: flashbody .3s 6 alternate; }

/* ---------- command ---------- */
.castle-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; }
.castle-label { font-weight: 700; font-size: 1.05rem; }
.seg { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg-btn { border: 0; border-right: 1px solid var(--line); border-radius: 0; background: transparent; font-weight: 700; padding: 8px 16px; }
.seg-btn:last-child { border-right: 0; }
.seg-btn.on { background: var(--ice-dim); color: #fff; }
.seg-btn.enemy.on { background: #6b1a2c; }
.actions { display: flex; flex-direction: column; gap: 14px; }
.action { display: flex; flex-direction: column; gap: 10px; }
.action + .action { border-top: 1px solid var(--line); padding-top: 14px; }
.action-title { font-weight: 800; font-size: 1.05rem; color: var(--ice); text-transform: uppercase; letter-spacing: .05em; }
.enemy-btn { width: 100%; padding: 20px; font-size: 1.6rem; font-weight: 900; letter-spacing: .06em; background: #9f1239; border: 2px solid var(--red); border-radius: 12px; color: #fff; }
.attack-btn { padding: 14px 26px; font-size: 1.15rem; font-weight: 900; letter-spacing: .05em; background: #1d4ed8; border-color: #60a5fa; border-radius: 10px; }
.attack-row { gap: 16px; }
.responder { color: var(--rose); }
.alts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.center-row { justify-content: center; }
.waves td { padding: 6px 8px; }
.orders { border-top: 1px solid var(--line); padding-top: 4px; }
.order-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.order-row:last-child { border-bottom: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { background: transparent; border-color: var(--line); font-weight: 700; padding: 4px 14px; }
.tab.on { background: var(--ice-dim); border-color: var(--ice); }
.team-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); gap: 16px; align-items: start; }
.team-card { padding: 12px 14px; }
.team-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.team-name { font-size: 1.15rem; }
.team-meta { margin-bottom: 4px; font-size: .9rem; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 2px 10px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); font-size: .86rem; }
.chip.st-ready { border-color: #1f5e3d; }
.chip.st-planned { border-color: var(--ice-dim); }
.chip.st-active { border-color: #5b4a9e; }
.chip.st-out { border-color: #6b4d18; }
.leader-row { cursor: pointer; }
.leader-row:hover td, .leader-row.open td { background: rgba(124, 199, 255, .05); }
.edit-row td { background: var(--panel-2); }
.edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 14px; }
.edit-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .82rem; }
.edit-actions { grid-column: 1 / -1; }
.add-leader { margin-top: 10px; }
.add-leader input:first-child { flex: 1; }
.access-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 12px 16px; }
.code { font-family: var(--mono); font-size: 1.2rem; font-weight: 800; letter-spacing: .1em; color: var(--ice); }
.other { padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.other:last-child { border-bottom: 0; }
.other-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.other-team { display: flex; gap: 6px; align-items: baseline; font-size: .9rem; padding: 2px 0; }
.admin-tools { display: flex; flex-direction: column; gap: 16px; }
.admin-tools > summary { cursor: pointer; font-weight: 700; color: var(--ice); padding: 8px 0; text-transform: uppercase; letter-spacing: .05em; font-size: .9rem; }
.admin-tools[open] > summary { margin-bottom: 12px; }
.admin-tools > .card { margin-bottom: 16px; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.settings label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .85rem; }
.settings button { align-self: end; justify-self: start; }
.code-box { background: #102536; border: 1px solid var(--ice-dim); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.code-box input { flex: 1; font-family: var(--mono); font-size: 1.1rem; letter-spacing: .08em; }
.log { max-height: 260px; overflow-y: auto; font-size: .84rem; }

/* ---------- countdowns ---------- */
.cd { font-family: var(--mono); font-weight: 700; }
.cd.big-cd { font-size: 1.1rem; }
.cd.soon { color: var(--amber); }
.cd.critical { color: var(--red); animation: pulse .5s infinite alternate; }
.cd.past { color: var(--muted); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #123524; color: var(--ok); border: 1px solid #1f5e3d; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #3a1520; color: var(--rose); border-color: #6b2234; }

@keyframes pulse { from { opacity: 1; } to { opacity: .6; } }
@keyframes flashbg { from { background: #0f3020; } to { background: #1b5a39; } }
@keyframes flashbody { from { background: var(--bg); } to { background: #4a1020; } }
@keyframes flashred { from { background: rgba(120, 10, 30, .92); } to { background: rgba(170, 20, 45, .95); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
}
@media (max-width: 640px) {
  .clock { font-size: 1.1rem; }
  .enemy-btn { font-size: 1.2rem; }
}
body.leader main { padding-bottom: 96px; }   /* room for the floating SOUND IS OFF bar */
