:root {
  --bg: #0f0c17; --panel: #1a1626; --panel2: #221d31; --line: #2f2842; --text: #efe9dc; --muted: #9b93ad;
  --gold: #f2c14e; --ember: #ff8a3d; --red: #f85149; --green: #3fb950; --blue: #58a6ff; --violet: #b18cff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; display: flex; flex-direction: column;
  background: radial-gradient(1200px 600px at 85% -10%, rgba(255,138,61,.13), transparent 60%), var(--bg); }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.35rem; color: var(--gold); } h3 { font-size: 1.05rem; }
code, pre, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86em; }
pre { background: #0a0811; border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; white-space: pre; }
code { background: #0a0811; padding: 1px 5px; border-radius: 5px; }
pre code { background: none; padding: 0; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: rgba(15,12,23,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-family: Georgia, serif; font-weight: 700; font-size: 1.15rem; color: var(--text); white-space: nowrap; }
.torch { display: inline-block; animation: flick 2.4s infinite; }
@keyframes flick { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) scale(1.06); } }
.top nav { display: flex; gap: 14px; font-size: .92rem; overflow-x: auto; }
.top nav a { color: var(--muted); white-space: nowrap; }
.top nav a.on, .top nav a:hover { color: var(--text); text-decoration: none; }
#nav-me { color: var(--gold); }
@media (max-width: 480px) { .top { padding-left: 12px; padding-right: 12px; } .brand { font-size: 1rem; } .top nav { gap: 11px; font-size: .86rem; } .top nav .hide-sm { display: none; } }
main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 18px 14px 40px; }
.foot { text-align: center; color: var(--muted); font-size: .82rem; padding: 18px 10px 28px; border-top: 1px solid var(--line); }
.foot a { color: var(--muted); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel.tight { padding: 12px; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .tiny { font-size: .76rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--gold); text-decoration: none; }
.btn.primary { background: linear-gradient(180deg, #ffb347, var(--ember)); color: #1b0f05; border-color: transparent; font-weight: 650; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], textarea, select { width: 100%; background: #0a0811; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; }
textarea { min-height: 190px; resize: vertical; line-height: 1.45; }
label { display: block; font-size: .86rem; color: var(--muted); margin: 10px 0 4px; }

.hero-banner { text-align: center; padding: 26px 12px 10px; }
.hero-banner .num { font-family: Georgia, serif; color: var(--gold); letter-spacing: .08em; font-size: .9rem; text-transform: uppercase; }
.hero-banner h1 { font-size: 2.1rem; margin: .2em 0 .3em; }
.hero-banner p { color: var(--muted); max-width: 560px; margin: 0 auto 14px; }
.countdown { font-variant-numeric: tabular-nums; }
.steps { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 700px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.step { background: var(--panel2); border-radius: 12px; padding: 12px; }
.step b { color: var(--gold); }

.board { width: 100%; border-collapse: collapse; }
.board td, .board th { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.board th { color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.board tr.click { cursor: pointer; } .board tr.click:hover td { background: rgba(255,255,255,.03); }
.rank { font-weight: 700; color: var(--gold); width: 2.2em; }
.grid-mini { font-size: .62rem; line-height: 1.05; letter-spacing: -1px; white-space: pre; }
.score { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right !important; }
.tag { display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); vertical-align: 1px; }
.tag.house { color: var(--violet); border-color: #4a3b73; }
.tag.live { color: #fff; background: var(--red); border-color: var(--red); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.who { line-height: 1.25; } .who small { color: var(--muted); display: block; font-size: .78rem; }

/* Replay viewer */
.rp-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.rp-head h1 { font-size: 1.4rem; margin: 0; }
.rp-result { text-align: right; } .rp-result .big { font-size: 1.7rem; font-weight: 800; color: var(--gold); line-height: 1; }
.stage { position: relative; background: linear-gradient(180deg, #1d1729, #120f1b); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; overflow: hidden; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: .9rem; }
.hpbar { flex: 1 1 160px; min-width: 140px; height: 16px; background: #2a1f24; border-radius: 99px; overflow: hidden; position: relative; }
.hpbar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #d63a3a, #ff6b5a); transition: width .35s; }
.hpbar span { position: absolute; inset: 0; text-align: center; font-size: .72rem; font-weight: 700; line-height: 16px; text-shadow: 0 1px 2px #000; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 1px 6px; font-size: .8rem; }
.scene { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
@media (min-width: 720px) { .scene { grid-template-columns: 1.35fr 1fr; } }
.room { background: rgba(0,0,0,.25); border-radius: 12px; padding: 14px; min-height: 190px; }
.room .where { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.room .big-emoji { font-size: 3.6rem; line-height: 1.1; margin: 8px 0; text-align: center; }
.room .big-emoji.hit { animation: shake .4s; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.enemy-name { text-align: center; font-weight: 700; }
.ebar { height: 10px; background: #2a1f24; border-radius: 99px; overflow: hidden; margin: 6px auto; max-width: 260px; }
.ebar i { display: block; height: 100%; background: linear-gradient(90deg, #8e44ff, #c58bff); transition: width .35s; }
.intent { text-align: center; font-size: .9rem; color: #ffd8a8; background: rgba(255,138,61,.12); border: 1px solid rgba(255,138,61,.35); border-radius: 10px; padding: 6px 8px; margin-top: 8px; }
.doors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.door { background: #2a2233; border: 2px solid #3b3148; border-radius: 40px 40px 8px 8px; padding: 18px 6px 10px; text-align: center; font-size: .78rem; min-height: 112px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; }
.door b { font-size: .82rem; color: var(--text); }
.door.chosen { border-color: var(--gold); box-shadow: 0 0 18px rgba(242,193,78,.35); }
.door.empty { visibility: hidden; }
.door .hint { color: var(--gold); font-weight: 600; }
.thought { margin-top: 12px; display: flex; gap: 10px; align-items: flex-start; }
.thought .bot { font-size: 1.6rem; line-height: 1; }
.bubble { background: #f3eee2; color: #1a1626; border-radius: 4px 14px 14px 14px; padding: 8px 12px; font-size: .92rem; flex: 1; }
.bubble .cmd { display: inline-block; background: #1a1626; color: var(--gold); border-radius: 6px; padding: 0 7px; font-family: ui-monospace, monospace; font-size: .8rem; margin-right: 6px; }
.events { margin: 10px 0 0; padding: 0; list-style: none; font-size: .9rem; }
.events li { padding: 3px 0 3px 18px; position: relative; color: #d9d2c3; }
.events li::before { content: "›"; position: absolute; left: 4px; color: var(--ember); }
.map { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.floor { background: rgba(0,0,0,.25); border-radius: 10px; padding: 6px; }
.floor .fl { font-size: .66rem; color: var(--muted); text-align: center; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.cells { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; }
.cell { width: 26px; height: 26px; border-radius: 6px; background: #241e2f; display: flex; align-items: center; justify-content: center; font-size: .82rem; }
.cell.v { background: #3a304a; } .cell.died { background: #4d1717; } .cell.fled { background: #4a2a12; }
.cell.cur { outline: 2px solid var(--gold); animation: pulse 1.4s infinite; }
.cell.end { grid-column: 2; }
.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.controls input[type=range] { flex: 1 1 180px; accent-color: var(--ember); }
.controls .count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; min-width: 64px; text-align: right; }
.toggle.on { border-color: var(--gold); color: var(--gold); }
.shield { position: absolute; inset: 0; background: rgba(12,9,18,.94); z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; gap: 10px; }
.share-box { white-space: pre-wrap; font-size: 1rem; line-height: 1.35; background: #0a0811; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.over-banner { text-align: center; padding: 18px 6px; }
.over-banner .o { font-family: Georgia, serif; font-size: 1.6rem; }
.over-banner .s { font-size: 2.4rem; font-weight: 800; color: var(--gold); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--gold); color: #1b0f05; padding: 9px 16px; border-radius: 99px; font-weight: 600; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.keybox { font-family: ui-monospace, monospace; background: #0a0811; border: 1px dashed var(--gold); border-radius: 10px; padding: 10px; word-break: break-all; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button.on { border-color: var(--gold); color: var(--gold); }
.pb-card { background: var(--panel2); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.pb-card pre { white-space: pre-wrap; max-height: 170px; overflow: auto; font-size: .8rem; }
.md table { border-collapse: collapse; width: 100%; font-size: .9rem; margin: 10px 0; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.md h1 { margin-top: .4em; } .md h2 { margin-top: 1.4em; } .md h3 { margin-top: 1.1em; color: var(--text); }
.md li { margin: 3px 0; }
.mapfull { display: flex; gap: 12px; flex-wrap: wrap; }
.notice { border-left: 3px solid var(--ember); padding: 6px 10px; background: rgba(255,138,61,.08); border-radius: 0 8px 8px 0; margin: 10px 0; font-size: .9rem; }
