/* Signal Fires: a fixed dusk palette (the same in light and dark OS modes).
   One warm accent (ember) means "your action"; the storm is the cold end of the range. */
:root {
  color-scheme: dark;
  --bg: #18202f;
  --card: #222c3f;
  --card-2: #1c2536;
  --ink: #eef2f8;
  --muted: #9aa8bf;
  --soft: rgba(238, 242, 248, .08);
  --line: rgba(238, 242, 248, .14);
  --ember: #ff9a3c;
  --ember-deep: #d9631a;
  --ember-soft: rgba(255, 154, 60, .18);
  --lit: #ffd166;
  --storm: #3b4a66;
  --storm-edge: #6d86b3;
  --bad: #e06055;
  --good: #6fcf97;
  --radius: 14px;
  /* keeper colours, by seat */
  --k0: #ff9a3c;
  --k1: #5ec8d8;
  --k2: #9ad06b;
  --k3: #c79bf0;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ff9a3c;
  --tut-accent-ink: #201607;
  --tut-bubble: #222c3f;
  --tut-ink: #eef2f8;
  --tut-muted: #9aa8bf;
  --tut-dim: rgba(9, 13, 21, .66);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 4px;
  max-width: 1040px; margin: 0 auto; height: 50px;
  padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
}
.back, .icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink);
  text-decoration: none; font-size: 22px; line-height: 1; cursor: pointer;
}
.back:hover, .icon-btn:hover { background: var(--soft); }
.brand {
  flex: 1; margin: 0; text-align: center; font-size: 18px; font-weight: 750;
  letter-spacing: .07em; font-variant: small-caps;
}
.back:focus-visible, .icon-btn:focus-visible, .btn:focus-visible, .kchip:focus-visible,
.seg button:focus-visible, .menu button:focus-visible {
  outline: 3px solid var(--ember); outline-offset: 2px;
}

/* ------------------------------------------------------------- buttons */
.btn {
  min-height: 44px; padding: 0 14px; border-radius: 12px; border: 0;
  background: var(--soft); cursor: pointer; font-weight: 650; line-height: 1.1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ember); color: #1d1204; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.quiet { background: transparent; color: var(--muted); }
.btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; }
.btn .sub { font-size: 12px; font-weight: 600; opacity: .75; }

/* ------------------------------------------------------------- layout */
.app {
  max-width: 1040px; margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr);
}
.side { display: grid; gap: 10px; align-content: start; min-width: 0; }
.board-area { position: relative; min-width: 0; display: grid; gap: 8px; }
/* The page keeps its natural height on a phone: ridge, status, actions, keepers, and then empty
   space at the bottom. The shared tutorial kit's first-visit chip is fixed over that space, so
   don't push the action bar down into it, it would cover the only controls on the screen. */
@media (min-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr) 320px; gap: 26px; align-items: start; padding-top: 6px; }
  .board-area { grid-column: 1; grid-row: 1; }
  .side { grid-column: 2; grid-row: 1; gap: 14px; }
}

/* ------------------------------------------------------------- storm line */
.storm-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-top: 2px; }
.storm-line {
  display: flex; align-items: center; gap: 8px; min-height: 26px;
  font-size: 14.5px; font-weight: 650; color: var(--ink);
}
.storm-line .gauge { display: inline-flex; gap: 3px; flex: none; }
.storm-line .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); }
.storm-line .pip.on { background: var(--storm-edge); box-shadow: none; }
.storm-line.urgent .txt { color: var(--bad); }
.net { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.net .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .5; }
.net .dot.on { background: var(--good); opacity: 1; }

/* ------------------------------------------------------------- board */
.board-box { width: 100%; max-width: 720px; margin: 0 auto; }
.board { width: 100%; }
/* The ridge is the screen, but never so tall that the action bar drops off the bottom on a short
   phone or a laptop: past this it scales down inside its box and the sides letterbox. */
.board svg {
  display: block; width: 100%; height: auto; max-height: 54vh; border-radius: var(--radius);
  background: linear-gradient(180deg, #1b2435 0%, #202b3e 62%, #243044 100%);
}
.hit { cursor: pointer; }
.site-name { font-size: 8.5px; fill: var(--muted); font-weight: 600; letter-spacing: 0; }
.site-name.here { fill: var(--ink); }
.wood-n { font-size: 11px; font-weight: 800; fill: #e8d5a8; }
.need-n { font-size: 12.5px; font-weight: 800; fill: #f0dcb4; }
.pawn-initial { font-size: 11px; font-weight: 800; fill: #121a27; }
.reach { transition: opacity .2s; }

/* ------------------------------------------------------------- status + actions */
.status { min-height: 22px; font-size: 14.5px; color: var(--muted); padding: 0 2px; }
.status.mine { color: var(--ink); }
.status.err { color: var(--bad); }
.actionbar {
  position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center;
  padding: 6px; min-height: 56px;
  background: var(--card); border-radius: 18px;
  box-shadow: 0 6px 20px rgba(6, 10, 18, .45);
}
.actionbar:empty { visibility: hidden; }
.actionbar .btn { flex: 1 1 auto; min-width: 88px; flex-direction: column; gap: 0; padding: 4px 10px; }
.actionbar .btn.wide { flex-basis: 100%; }
.turn-head {
  flex: 1 1 100%; display: flex; align-items: center; gap: 8px; padding: 2px 6px 0; min-width: 0;
}
.turn-head .who { font-weight: 750; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-head .av { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #121a27; font-size: 12px; font-weight: 800; }
.turn-head .acts { margin-left: auto; display: inline-flex; gap: 4px; flex: none; }
.turn-head .act {
  width: 12px; height: 12px; border-radius: 50%; background: var(--soft); box-shadow: inset 0 0 0 1.5px var(--line);
}
.turn-head .act.on { background: var(--ember); box-shadow: none; }
.turn-head .carry { flex: none; font-size: 12.5px; color: var(--muted); font-weight: 650; }

/* ------------------------------------------------------------- keeper chips */
.keepers { display: flex; gap: 6px; flex-wrap: wrap; }
.kchip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; flex: 1 1 140px;
  padding: 0 12px 0 6px; border: 0; border-radius: 14px; background: var(--card-2); cursor: pointer;
  text-align: left; min-width: 0; transition: box-shadow .2s, background .2s;
}
.kchip .av {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #121a27; font-size: 13px; font-weight: 800;
}
.kchip .nm { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kchip .sub { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.kchip.turn { background: var(--card); box-shadow: 0 0 0 2px var(--pc); }
.kchip.done { opacity: .62; }

/* ------------------------------------------------------------- what happened */
.feed {
  display: grid; gap: 5px; align-content: start;
  padding: 10px 12px; border-radius: 14px; background: var(--card-2); font-size: 13px;
}
.feed .head {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.feed .row { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); }
.feed .row.fresh { color: var(--ink); }
.feed .row.storm { color: var(--storm-edge); font-style: italic; }
.feed .av {
  flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc, var(--storm)); color: #121a27; font-size: 10px; font-weight: 800; margin-top: 1px;
}
.feed .row.storm .av { background: var(--storm); color: #cfe0f7; }

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(8, 12, 20, .58); padding: 14px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 420px; max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); overflow-y: auto;
  background: var(--card); border-radius: 20px; padding: 18px;
  box-shadow: 0 14px 44px rgba(4, 7, 13, .5);
  animation: pop .18s ease-out;
}
.modal.wide { max-width: 620px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 12px; font-size: 20px; text-align: center; }
.modal-head { display: flex; align-items: center; gap: 8px; margin: -6px -6px 8px 0; }
.modal-head h2 { flex: 1; margin: 0; text-align: left; }
.modal .lede { margin: -4px 0 14px; text-align: center; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { flex: 1 1 auto; }

/* menu */
.menu-overlay { background: rgba(8, 12, 20, .2); place-items: start end; padding: 50px 10px 0; }
.menu {
  min-width: 218px; background: var(--card); border-radius: 16px; padding: 6px;
  box-shadow: 0 10px 30px rgba(4, 7, 13, .5); animation: pop .15s ease-out; display: grid;
}
.menu button {
  min-height: 48px; padding: 0 14px; border: 0; background: transparent; text-align: left;
  border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 550;
}
.menu button:hover { background: var(--soft); }
@media (min-width: 1060px) { .menu-overlay { padding-right: calc((100vw - 1040px) / 2 + 8px); } }

/* setup */
.field { margin: 14px 0; }
.field-label { font-weight: 650; margin-bottom: 6px; font-size: 14px; }
.field-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--soft); }
.seg button {
  flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-weight: 650;
}
.seg button[aria-checked="true"] { background: var(--ember); color: #1d1204; }

/* info */
.info-round { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.info-keepers { display: grid; gap: 8px; }
.info-keeper { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.info-keeper .av { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #121a27; font-size: 12px; font-weight: 800; }
.info-keeper small { display: block; color: var(--muted); }
.sub-title { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 13px; max-height: 40vh; overflow-y: auto; }
.log li { display: flex; gap: 7px; align-items: flex-start; }
.log li .av { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #121a27; font-size: 10px; font-weight: 800; margin-top: 1px; }
.log li.storm-line-item { color: var(--storm-edge); font-style: italic; }
.log li.big { color: var(--lit); font-weight: 650; }

/* help */
.help-body h3 { margin: 16px 0 4px; font-size: 15px; }
.help-body h3:first-child { margin-top: 0; }
.help-body p, .help-body li { font-size: 14px; }
.help-body ul, .help-body ol { padding-left: 20px; margin: 4px 0; }
.keeper-key { list-style: none; padding: 0 !important; display: grid; gap: 8px; }
.keeper-key li { display: flex; gap: 9px; align-items: flex-start; }
.keeper-key .av {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #121a27; font-size: 12px; font-weight: 800;
}

/* game over */
.go-table { display: grid; gap: 6px; }
.go-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--soft); font-size: 13.5px; }
.go-row .av { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #121a27; font-size: 12px; font-weight: 800; }
.go-row b { margin-left: auto; font-size: 16px; }
.go-beacons { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; margin: 2px 0 6px; }
.go-beacons span { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--soft); font-size: 12px; }
.go-beacons span.lit { background: var(--ember-soft); }

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

/* Online play (online.js) */
body.is-online #btn-new, body.is-online #btn-hint { display: none; }
.menu #menu-online { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
#over-leave { display: flex; width: 100%; margin-top: 8px; }
