/* Emberfall, a dark hearth: soot and warm ember light. One fixed palette, the same whether the
   phone is in light or dark mode. The accent (ember orange) always means "your move". */
:root {
  color-scheme: dark;
  --bg: #17110f;
  --surface: #241a16;
  --surface2: #30231d;
  --line: rgba(255, 226, 196, .12);
  --ink: #f4e7da;
  --muted: #a8917f;
  --ember: #ff8a3d;          /* the accent: your turn, primary buttons */
  --ember-dim: rgba(255, 138, 61, .18);
  --ember-hot: #ffb03a;
  --spark: #ffd978;
  --ash: #6b6259;
  --bad: #e0603a;
  --good: #8fbf6a;
  --radius: 14px;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ff8a3d;
  --tut-accent-ink: #1b120d;
  --tut-bubble: #30231d;
  --tut-ink: #f4e7da;
  --tut-muted: #a8917f;
  --tut-dim: rgba(8, 5, 3, .68);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation; min-height: 100vh; overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

.app {
  max-width: 560px; margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
}

/* ---------------------------------------------------------------- top bar + menu */
.topbar { display: flex; align-items: center; gap: 4px; height: 48px; }
.back, .iconbtn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 0;
}
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface2); }
.brand {
  flex: 1; text-align: center; font-size: 19px; font-weight: 750; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ember);
}
.menu {
  position: absolute; right: 12px; top: 46px; z-index: 45; min-width: 200px; padding: 6px;
  background: var(--surface); border-radius: 14px; border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55); display: flex; flex-direction: column; animation: pop .14s ease-out;
}
.menu button {
  min-height: 46px; text-align: left; padding: 0 14px; border: 0; background: none;
  border-radius: 10px; cursor: pointer; font-weight: 600;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface2); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- buttons */
.btn {
  min-height: 46px; padding: 8px 18px; border-radius: 12px; border: 0; background: var(--surface2);
  color: var(--ink); cursor: pointer; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .15s, transform .08s, opacity .15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn.primary { background: var(--ember); color: #1b120d; }
.btn.primary:hover:not(:disabled) { background: var(--ember-hot); }
.btn.go { background: var(--good); color: #13210c; }
.btn.warn { background: var(--bad); color: #fff; }
.btn.quiet { background: transparent; color: var(--muted); }
.btn.small { min-height: 38px; padding: 4px 14px; font-size: 14px; }
/* The sub-label sits on the same line, after a "·" that is part of the text (see btn() in
   render.js). `display` would be ignored here anyway: .btn is a flex container, so the <small> is
   a flex item. nowrap keeps "risk 100%" from breaking across two lines. */
.btn small { font-size: 11.5px; font-weight: 600; opacity: .8; white-space: nowrap; }

/* ---------------------------------------------------------------- score chips */
.players { display: flex; gap: 6px; flex-wrap: wrap; padding: 2px 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 12px;
  border: 0; border-radius: 20px; background: var(--surface); color: var(--ink);
  cursor: pointer; font-size: 14px; transition: box-shadow .2s, background .2s;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chip .nm { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9ch; }
.chip .sc { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ember-hot); }
.chip.turn { background: var(--surface2); box-shadow: inset 0 0 0 2px var(--pc, var(--ember)); }
.chip.me .nm { color: var(--ember); }
.chip.won .sc::after { content: " \1F3C6"; font-size: 12px; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--pc, var(--ember)); flex: none; }

/* ---------------------------------------------------------------- status */
.status-row { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 30px; }
.status { font-size: 15.5px; font-weight: 650; text-align: center; color: var(--ink); padding: 2px 4px; }
.status .thinking::after {
  content: ""; display: inline-block; width: 1.1em; text-align: left;
  animation: dots 1.2s steps(4) infinite;
}
.status .good { color: var(--good); }
.status .warn { color: var(--bad); }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.status-row .net { color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- the board */
.board {
  background: radial-gradient(120% 80% at 50% 0%, #2b1d17 0%, var(--surface) 60%, #1e1512 100%);
  border-radius: 20px; border: 1px solid var(--line);
  padding: 12px 10px 10px; margin-top: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 200, 150, .06);
}

/* the fire: one pip per breath left */
.fire { display: flex; align-items: center; gap: 8px; justify-content: center; min-height: 30px; }
.fire .flame { width: 22px; height: 22px; flex: none; filter: drop-shadow(0 0 6px rgba(255, 138, 61, .5)); }
.fire.low .flame { animation: gutter .9s ease-in-out infinite; }
@keyframes gutter { 0%, 100% { opacity: 1; transform: none; } 50% { opacity: .55; transform: scale(.9); } }
.pips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.pips i {
  width: 12px; height: 16px; border-radius: 50% 50% 45% 45%; background: var(--ember);
  box-shadow: 0 0 7px rgba(255, 138, 61, .55); display: block;
  transition: background .3s, box-shadow .3s, opacity .3s, transform .3s;
}
.pips i.spent { background: #3a2f28; box-shadow: none; opacity: .5; transform: scale(.72); }
.pips i.last { background: var(--bad); box-shadow: 0 0 10px rgba(224, 96, 58, .8); }

/* the dice you pulled */
.tray { min-height: 76px; display: grid; place-items: center; padding: 10px 0 6px; }
/* All six dice must stay on one row at 390px: 6 x 50 + 5 x 6 = 330, inside the 346 available
   after the app's and the board's side padding. Wrapping to a second row was the first thing the
   phone screenshot caught. */
.dice { display: flex; gap: 6px; justify-content: center; flex-wrap: nowrap; }
.die {
  width: 50px; height: 50px; flex: none; border-radius: 13px; border: 0; padding: 0;
  background: #f0e4d4; box-shadow: 0 3px 0 #b9a893, 0 4px 10px rgba(0, 0, 0, .4);
  display: grid; place-items: center; cursor: default;
  transition: transform .15s, box-shadow .15s, opacity .2s;
}
.die svg { width: 40px; height: 40px; display: block; }
.die.ash { background: #cfc6bb; box-shadow: 0 3px 0 #9d9389, 0 4px 10px rgba(0, 0, 0, .35); }
.die.can { cursor: pointer; }
.die.can:hover { transform: translateY(-2px); }
.die.picked {
  transform: translateY(-9px);
  box-shadow: 0 0 0 3px var(--ember), 0 8px 14px rgba(0, 0, 0, .5);
  background: #fff3e0;
}
.die.fresh { animation: tumble .42s cubic-bezier(.2, .9, .3, 1.2); }
.die.ghost { opacity: .32; }
@keyframes tumble {
  0% { transform: translateY(-16px) rotate(-120deg) scale(.7); opacity: 0; }
  60% { transform: translateY(2px) rotate(8deg) scale(1.05); opacity: 1; }
  100% { transform: none; }
}
.die.picked.fresh { animation: none; }
.dice.empty::after { content: "Pull to rake the ash"; color: var(--muted); font-size: 14px; }

/* the hearth: what you have raked out so far */
.hearth-row { display: flex; align-items: center; gap: 10px; min-height: 44px; border-top: 1px solid var(--line); padding-top: 8px; }
.hearth { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; min-width: 0; min-height: 30px; align-items: center; }
.hearth .h {
  width: 28px; height: 28px; border-radius: 8px; background: #2a1f19; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px var(--line);
}
.hearth .h svg { width: 22px; height: 22px; }
.hearth .h.new { animation: intoHearth .35s ease-out; }
@keyframes intoHearth { from { transform: translateY(-14px) scale(.8); opacity: .2; } to { transform: none; opacity: 1; } }
.hearth .none { color: var(--muted); font-size: 13px; }
.banked { font-weight: 800; font-size: 17px; color: var(--ember-hot); font-variant-numeric: tabular-nums; white-space: nowrap; }
.banked small { display: block; font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }

/* ---------------------------------------------------------------- action bar */
.actions {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  min-height: 56px; align-items: center; padding: 10px 0 4px;
}
.actions .btn { min-width: 116px; }

/* ---------------------------------------------------------------- what happened */
.feed { margin-top: 2px; }
.feed-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); padding: 0 2px 4px;
}
.feed-head button { background: none; border: 0; color: var(--ember); font-size: 12px; cursor: pointer; padding: 4px; }
.feed-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; min-height: 40px; }
.feed-list li {
  font-size: 13.5px; color: var(--muted); padding: 3px 8px; border-radius: 8px; background: var(--surface);
  overflow: hidden; text-overflow: ellipsis;
}
.feed-list li:first-child { color: var(--ink); }
.feed-list li.mine { box-shadow: inset 2px 0 0 var(--ember); }
.feed-list li.bad { color: var(--bad); }
.feed-list li.good { color: var(--good); }

/* ---------------------------------------------------------------- sheets and modals */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(6, 4, 3, .6); }
.sheet {
  position: relative; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(26px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h3 { font-size: 18px; margin-bottom: 8px; color: var(--ember); }
.sheet .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 14px 0 5px; }
.field { margin: 14px 0; }
.field .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 46px; border-radius: 12px; border: 0;
  background: var(--surface2); color: var(--ink); cursor: pointer; font-weight: 700;
}
.seg button.on { background: var(--ember); color: #1b120d; }
.actions-row { display: flex; gap: 8px; margin-top: 16px; }
.actions-row .btn { flex: 1 1 0; }

.modal-wrap { position: fixed; inset: 0; z-index: 42; background: rgba(6, 4, 3, .62); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; width: 100%;
  max-width: 600px; max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .6);
}
.over-modal { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 8px; }
.modal-head h2 { font-size: 20px; color: var(--ember); }
.modal-body { padding: 0 16px 14px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 16px; }
.modal-foot .btn { flex: 1 1 120px; }
.rules h3 { font-size: 15px; margin: 16px 0 4px; color: var(--ember-hot); }
.rules p, .rules li { font-size: 14px; }
.rules ol, .rules ul { padding-left: 20px; margin: 4px 0; }
.rules li { margin: 4px 0; }
.facekey { list-style: none; padding: 0 !important; display: grid; gap: 6px; }
.facekey li { display: flex; align-items: center; gap: 10px; }
.facekey .swatch { width: 40px; height: 40px; flex: none; border-radius: 10px; background: #f0e4d4; display: grid; place-items: center; }
.facekey .swatch.ash { background: #cfc6bb; }
.facekey .swatch svg { width: 32px; height: 32px; }

/* standings table (game info and the result card) */
.standings { width: 100%; border-collapse: collapse; font-size: 14px; }
.standings th, .standings td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.standings th:first-child, .standings td:first-child { text-align: left; }
.standings th { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; }
.standings tr.me td { color: var(--ember); font-weight: 750; }
.standings tr.win td { background: var(--ember-dim); }
.standings td .sub { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.log { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; font-size: 13px; }
.log li { padding: 5px 2px; border-bottom: 1px solid var(--line); color: var(--muted); }
.log li.mine { color: var(--ink); }
.log li.turn { color: var(--ember-hot); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.result-banner { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; margin: 0 0 10px; }
.result-banner.win { color: var(--ember); }

/* ---------------------------------------------------------------- sizes */
@media (max-width: 379px) {
  .die { width: 46px; height: 46px; border-radius: 11px; }
  .die svg { width: 35px; height: 35px; }
  .actions .btn { min-width: 100px; }
  .chip .nm { max-width: 6ch; }
}
@media (min-width: 560px) {
  .die { width: 58px; height: 58px; }
  .die svg { width: 45px; height: 45px; }
  .tray { min-height: 86px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- online (online.js) */
body.is-online #menu-new { display: none; }
/* The online row sits above How to play and carries the menu's one divider. */
.menu #menu-online { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
#over-rematch, #over-leave { flex-basis: 100%; }
