:root {
  --bg: #11142a;
  --bg2: #181c38;
  --card: #1d2142;
  --line: #2e3460;
  --text: #ece9f7;
  --muted: #9aa0c3;
  --accent: #ff8a3d;
  --accent2: #ffd27a;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 70% -10%, #2b2350 0%, transparent 60%), var(--bg);
  min-height: 100vh;
}
a { color: var(--accent2); }
h1, h2 { line-height: 1.15; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; }
code, pre, .code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
em { font-style: normal; color: var(--muted); font-size: .9em; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: 1180px; margin: 0 auto; padding: .9rem 1.2rem;
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: .02em; }
.brand svg { width: 30px; height: 30px; }
.top nav { display: flex; gap: 1.1rem; }
.top nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.top nav a:hover { color: var(--text); }

main { max-width: 1180px; margin: 0 auto; padding: 0 1.2rem 3rem; outline: none; }

.panel, .card, .result {
  background: linear-gradient(180deg, var(--card), var(--bg2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
}
.panel { margin: 1.2rem 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .75rem; font-weight: 700; color: var(--accent); margin: 0 0 .2rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.05rem;
  border-radius: 10px; border: 1px solid var(--line);
  background: #262b55; color: var(--text);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:hover:not(:disabled) { background: #2f3566; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #ff9c55, #f2711f); border-color: #ffb17a; color: #1b0f05; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffab6b, #ff7d2b); }
.btn.ghost { background: transparent; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

.field { display: grid; gap: .3rem; border: 0; padding: 0; margin: 0 0 .8rem; }
.field > span, .field legend { font-size: .85rem; font-weight: 700; color: var(--muted); padding: 0; }
input:not([type]), input[type=text] , #name, #join-code, #lobby-name, #invite {
  font: inherit; color: var(--text); background: #12152c; border: 1px solid var(--line);
  border-radius: 10px; padding: .6rem .75rem; min-height: 44px; width: 100%;
}
#join-code { text-transform: uppercase; letter-spacing: .2em; font-family: ui-monospace, Menlo, monospace; }
.check { display: inline-flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; margin-top: .6rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.seats { display: flex; gap: .5rem; flex-wrap: wrap; }
.seats legend { width: 100%; margin-bottom: .3rem; }
.seats label { position: relative; }
.seats input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seats span { display: grid; place-items: center; width: 52px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #12152c; font-weight: 800; }
.seats input:checked + span { background: #3a2a1a; border-color: var(--accent); color: var(--accent2); }
.seats input:focus-visible + span { outline: 3px solid var(--accent2); outline-offset: 2px; }

.hero { display: grid; grid-template-columns: minmax(300px, 440px) 1fr; gap: 2rem; align-items: center; padding-top: 1rem; }
.hero h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); letter-spacing: -.01em; }
.hero h1 span { color: var(--accent2); }
.lede { color: var(--muted); font-size: 1.08rem; margin: 0 0 1.2rem; }
.hero .card { margin-bottom: 1rem; }
.join { display: flex; gap: .6rem; align-items: flex-end; }
.join .field { flex: 1; margin: 0; }
.hero-art .scene { border-radius: 18px; box-shadow: 0 30px 80px #0008; }

.rules-text { font-size: 1.05rem; max-width: 75ch; }
.tips { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; padding: 0; list-style: none; margin: 1rem 0 0; }
.tips li { background: #14183a; border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; color: var(--muted); }
.tips b { color: var(--text); display: block; }
pre { background: #0c0e20; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; overflow-x: auto; font-size: .85rem; line-height: 1.6; }
pre .c { color: #7f87b0; }

/* scene */
.scene { display: block; width: 100%; height: auto; }
.scene .value { font: 800 22px system-ui, sans-serif; fill: #fff; text-anchor: middle; }
.scene .grow { font: 800 15px system-ui, sans-serif; fill: var(--accent2); text-anchor: start; }
.scene .bname { font: 700 17px system-ui, sans-serif; fill: #c9cde6; text-anchor: middle; letter-spacing: .04em; }
.scene .bname.mine { fill: var(--accent2); }
.scene .ember-n { font: 800 13px system-ui, sans-serif; fill: #10122a; text-anchor: middle; }
.scene .strength { font: 800 17px system-ui, sans-serif; text-anchor: middle; }
.scene .flame.lit { animation: flicker 1.6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: 50% 100%; }
.scene .halo { animation: breathe 2.4s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scale(1) skewX(-2deg); } to { transform: scale(1.04, .96) skewX(3deg); } }
@keyframes breathe { from { opacity: .7; } to { opacity: 1; } }

/* game */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: auto auto auto 1fr; grid-template-areas: "bar bar" "stage side" "bids side" "result side"; gap: 1rem; align-items: start; }
.result-area { grid-area: result; min-width: 0; }
.stage { position: relative; }
.stage-cap { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; bottom: .35rem; margin: 0; font-size: .75rem; color: #8f96bb; pointer-events: none; }
.gamebar { grid-area: bar; display: flex; justify-content: space-between; align-items: center; }
.gamebar h1 { font-size: 1.7rem; margin: 0; }
.stage { grid-area: stage; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.bids { grid-area: bids; }
.side { grid-area: side; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; min-width: 0; }
.game > .panel { grid-area: bids; margin: 0; }

.clock { position: relative; width: 58px; height: 58px; }
.clock svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.clock circle { fill: none; stroke-width: 4; }
.clock .track { stroke: #2a2f58; }
.clock .ring { stroke: var(--accent); stroke-dasharray: 100; stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.clock.low .ring { stroke: #ff5d6c; }
.clock .secs { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-variant-numeric: tabular-nums; }

.bidgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.bidcol { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .4rem; text-align: center; }
.bidname { font-weight: 800; font-size: .95rem; }
.bv { display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; border-radius: 99px; background: #12152c; border: 1px solid #8088a8; font-size: .8rem; margin-left: .2rem; }
.stepper { display: flex; align-items: center; justify-content: center; gap: .35rem; margin: .45rem 0 .3rem; }
.stepper output { min-width: 1.6em; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.step { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #262b55; color: var(--text); font: 800 1.3rem/1 system-ui, sans-serif; cursor: pointer; }
.step:hover:not(:disabled) { background: #343b72; }
.step:disabled { opacity: .35; cursor: not-allowed; }
.embers-line { font-size: .78rem; color: var(--muted); min-height: 1.2em; }
.embers-line b { color: var(--accent2); }
.bidbar { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; margin-top: .8rem; }
.pool { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; color: var(--muted); }
.pool b { color: var(--text); }
.pips { display: inline-flex; gap: 3px; flex-wrap: wrap; max-width: 220px; }
.pips i { width: 12px; height: 12px; transform: rotate(45deg); border-radius: 2px; background: #2a2f58; }
.pips i.on { background: linear-gradient(135deg, #ffd27a, #ff8a3d); box-shadow: 0 0 8px #ff8a3d88; }
.bids.locked .bidcol { opacity: .75; }

.players { list-style: none; margin: 0 0 .5rem; padding: 0; display: grid; gap: .4rem; }
.players li { display: grid; grid-template-columns: auto 1fr auto auto auto; gap: .5rem; align-items: center; padding: .5rem .6rem; border-radius: 10px; background: #14183a; border: 1px solid transparent; }
.players li.me { border-color: var(--pc); }
.players .lock { grid-column: 2 / -1; font-size: .78rem; color: var(--muted); }
.players .lock.on { color: #7be0a2; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--pc, #555a7a); display: inline-block; box-shadow: 0 0 10px var(--pc, transparent); flex: none; }
.pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; padding: .15rem .45rem; border-radius: 6px; background: #262b55; color: var(--muted); }
.k-human { background: #2b3a2a; color: #a6e3a1; }
.k-agent { background: #2a3550; color: #8ec5ff; }
.k-bot { background: #3a2c22; color: #ffc08a; }
.stat { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.stat b { color: var(--text); font-size: 1.05rem; }
.sparks i { font-style: normal; color: var(--accent2); margin-left: 2px; }
.host { font-size: .72rem; color: var(--accent2); }

.result h2 { margin-bottom: .6rem; }
.result.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 #ff8a3daa; } 100% { box-shadow: 0 0 0 18px #ff8a3d00; } }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { padding: .38rem .4rem; text-align: center; border-bottom: 1px solid #262b55; white-space: nowrap; }
thead th { font-size: .75rem; color: var(--muted); font-weight: 700; }
thead th .dot { width: 9px; height: 9px; margin-right: .3rem; vertical-align: middle; }
tbody th { text-align: left; }
td.win { background: color-mix(in srgb, var(--pc) 22%, transparent); }
td.win b { color: var(--pc); }
td small { color: var(--muted); }
td.outcome { text-align: right; font-weight: 700; }

.lobby { max-width: 640px; margin-inline: auto; }
.lobby .code { font-size: clamp(2.6rem, 9vw, 4.2rem); letter-spacing: .25em; color: var(--accent2); margin: .2rem 0 .8rem; }
.share { margin-bottom: 1rem; }
.share input { flex: 1; min-width: 0; }
.lobby-seats li { grid-template-columns: auto 1fr auto auto; }
.lobby-seats li.empty { opacity: .55; border: 1px dashed var(--line); background: transparent; }
.agent-join { margin-top: 1rem; color: var(--muted); }
.agent-join summary { cursor: pointer; font-weight: 700; color: var(--text); }

.final h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
.final h1.won { color: var(--accent2); }
.standings li { grid-template-columns: 1.6rem auto 1fr auto auto auto; font-size: 1.05rem; }
.rank { font-weight: 800; color: var(--muted); text-align: center; }
.replay .stage { margin: .6rem 0 1rem; }
.replay-nav span { min-width: 7.5em; text-align: center; font-weight: 700; }

#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 150%);
  background: #262b55; border: 1px solid var(--accent); color: var(--text);
  padding: .7rem 1.1rem; border-radius: 12px; font-weight: 600; max-width: min(92vw, 520px);
  box-shadow: 0 10px 40px #0009; transition: transform .25s ease, opacity .25s ease, visibility .25s; z-index: 10; pointer-events: none;
  opacity: 0; visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.loading { text-align: center; }

@media (max-width: 960px) {
  .game { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "bar" "stage" "bids" "result" "side"; }
  .stage-cap { position: static; transform: none; white-space: normal; padding: .3rem .7rem .4rem; background: #12142a; }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-art { order: -1; }
}
@media (max-width: 560px) {
  body { font-size: 15px; }
  main { padding: 0 .7rem 2rem; }
  .top { padding: .7rem .8rem; }
  .top nav { gap: .7rem; font-size: .9rem; }
  .panel, .card, .result { padding: 1rem; }
  .bidgrid { gap: .3rem; }
  .bidcol { padding: .5rem .15rem; }
  .bidname { font-size: .8rem; }
  .bv { display: grid; margin: .2rem auto 0; }
  .stepper { flex-direction: column-reverse; gap: .2rem; }
  .step { width: 100%; max-width: 48px; height: 36px; }
  .stepper output { font-size: 1.35rem; }
  .embers-line { font-size: .68rem; }
  .bidbar .row { width: 100%; }
  .bidbar .row .btn { flex: 1; }
  .players li { grid-template-columns: auto 1fr auto auto; }
  .players li .sparks { display: none; }
  .standings li { grid-template-columns: 1.4rem auto 1fr auto auto; }
  .standings li .sparks { display: none; }
  .gamebar h1 { font-size: 1.35rem; }
  th, td { padding: .32rem .22rem; }
  td small, .oname { display: none; }
  .hname { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  thead th .dot { width: 12px; height: 12px; margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
