:root {
  --bg: #0b0d12;
  --panel: #12161f;
  --panel-2: #181d28;
  --line: rgba(255, 255, 255, 0.08);
  --text: #ebe6da;
  --muted: #8d93a1;
  --strike: #ff5a5f;
  --evade: #2fd6c0;
  --parry: #f5b83d;
  --guard: #6b9cff;
  --feint: #b48cff;
  --kick: #ff9a3c;
  --stance: #ffd166;
  --you: #2fd6c0;
  --ai: #ff5a5f;
  --tw: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #1a2133 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}
b { font-weight: 700; }
button, select { font: inherit; color: inherit; }

/* ── top bar ─────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(10, 12, 17, 0.6); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { color: var(--parry); font-size: 22px; }
.brand .name { font-family: Cinzel, serif; font-weight: 800; font-size: 22px; letter-spacing: 0.18em; }
.brand .tag { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
.controls { display: flex; align-items: center; gap: 10px; }
.select { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--text);
}
button { cursor: pointer; border-radius: 9px; padding: 7px 14px; border: 1px solid var(--line); background: var(--panel-2); transition: 0.15s; }
button:hover { border-color: rgba(255, 255, 255, 0.2); }
button.primary { background: linear-gradient(180deg, #f7c65a, #e0a22a); color: #1b1305; border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }

/* ── layout ──────────────────────────────── */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px;
  max-width: 1320px; margin: 0 auto; padding: 16px 20px 40px;
}
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .brand .tag { display: none; }
}

/* ── player bars ─────────────────────────── */
.pbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.pbar .who { font-family: Cinzel, serif; font-weight: 800; letter-spacing: 0.08em; min-width: 110px; }
.pbar.ai .who { color: var(--ai); }
.pbar.you .who { color: var(--you); }
.pbar .who small { display: block; font-family: Inter, sans-serif; font-weight: 500; letter-spacing: 0; color: var(--muted); font-size: 11px; }
.hp { display: flex; align-items: center; gap: 10px; flex: 1; }
.hp-segs { display: flex; gap: 3px; flex: 1; max-width: 360px; }
.hp-segs i { flex: 1; height: 12px; border-radius: 3px; background: rgba(255, 255, 255, 0.06); transition: background 0.3s, transform 0.3s; }
.pbar.ai .hp-segs i.on { background: linear-gradient(180deg, #ff7a7e, #c9373c); box-shadow: 0 0 8px rgba(255, 90, 95, 0.35); }
.pbar.you .hp-segs i.on { background: linear-gradient(180deg, #5cf0db, #1ba895); box-shadow: 0 0 8px rgba(47, 214, 192, 0.35); }
.hp-segs i.lost { animation: lost 0.6s ease-out; }
@keyframes lost { 0% { background: #fff; transform: scaleY(1.6); } 100% { transform: scaleY(1); } }
.hp b { font-size: 18px; min-width: 24px; font-variant-numeric: tabular-nums; }
.meta { color: var(--muted); font-size: 12px; display: flex; gap: 12px; align-items: center; }
.backs { display: flex; gap: 3px; }
.backs i {
  width: 14px; height: 20px; border-radius: 3px;
  background: repeating-linear-gradient(45deg, #3a2328, #3a2328 3px, #2a181c 3px, #2a181c 6px);
  border: 1px solid rgba(255, 90, 95, 0.4);
}

/* ── arena ───────────────────────────────── */
.arena-wrap { position: relative; height: 290px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
#arena { width: 100%; height: 100%; display: block; }
#banner {
  position: absolute; left: 0; right: 0; top: 42%; text-align: center; pointer-events: none;
  font-family: Cinzel, serif; font-weight: 800; font-size: 40px; letter-spacing: 0.25em;
  color: #fff; text-shadow: 0 0 24px rgba(245, 184, 61, 0.7); opacity: 0; transform: scale(0.9);
}
#banner.show { animation: banner 1.2s ease-out; }
#banner small { display: block; font: 600 13px Inter, sans-serif; letter-spacing: 0.08em; color: var(--muted); text-shadow: none; margin-top: 4px; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.3); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.98); }
}

/* ── timeline ────────────────────────────── */
.timeline { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.tl-labels { width: 84px; flex: none; border-right: 1px solid var(--line); position: relative; height: 124px; }
.tl-labels .lbl { position: absolute; left: 12px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.tl-labels .lbl.ai { top: 36px; color: var(--ai); }
.tl-labels .lbl.you { top: 84px; color: var(--you); }
.tl-view { position: relative; flex: 1; height: 124px; overflow: hidden; }
.tl-inner { position: absolute; left: 0; top: 0; height: 100%; transition: transform 0.35s cubic-bezier(0.3, 0.7, 0.3, 1); }
.tl-ticks .tk { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.tl-ticks .tk span { position: absolute; top: 4px; left: 4px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-ticks .tk.past { background: rgba(255, 255, 255, 0.04); }
.tl-ticks .tk.past span { opacity: 0.5; }
.tl-now { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 12px rgba(255, 255, 255, 0.6); transition: left 0.3s cubic-bezier(0.3, 0.7, 0.3, 1); z-index: 3; }
.tl-now span { position: absolute; bottom: 2px; left: 5px; font-size: 9px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: #fff; opacity: 0.7; }
.tl-shade { position: absolute; top: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.28); z-index: 0; }

.bar {
  position: absolute; height: 34px; border-radius: 7px; overflow: hidden; z-index: 1;
  display: flex; align-items: center; padding: 0 9px; font-size: 12px; font-weight: 700; white-space: nowrap;
  border: 1.5px solid var(--c); color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, #10131a);
  transition: width 0.25s;
}
.bar.lane-ai { top: 24px; }
.bar.lane-you { top: 72px; }
.bar .fill { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--c) 30%, transparent); z-index: -1; transition: width 0.3s; }
.bar span { position: relative; text-overflow: ellipsis; overflow: hidden; }
.bar.t-strike { --c: var(--strike); }
.bar.t-evade { --c: var(--evade); }
.bar.t-parry { --c: var(--parry); }
.bar.t-guard { --c: var(--guard); }
.bar.t-feint { --c: var(--feint); }
.bar.stagger { --c: #8a8f99; background: repeating-linear-gradient(135deg, #1b1e25, #1b1e25 5px, #23262e 5px, #23262e 10px); font-weight: 600; }
.bar.hidden {
  --c: #c7c2b8; border-style: dashed;
  background: repeating-linear-gradient(135deg, #191b22, #191b22 6px, #1f2129 6px, #1f2129 12px);
  font-family: Cinzel, serif; font-size: 14px;
}
.bar.fresh { animation: pop 0.4s ease-out; }
@keyframes pop { 0% { transform: translateY(-8px) scale(0.92); opacity: 0; } 100% { transform: none; opacity: 1; } }
.bar.ghost-bar { border-style: dashed; opacity: 0.85; background: transparent; animation: none; }
.bar.cut { opacity: 0.25; border-style: dotted; background: transparent; }

.mark {
  position: absolute; z-index: 2; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #0b0d12;
}
.mark.lane-ai { top: 31px; }
.mark.lane-you { top: 79px; }
.mark.land { background: var(--strike); box-shadow: 0 0 10px rgba(255, 90, 95, 0.7); }
.mark.q { background: #d8d2c4; }
.mark.x { background: #ffd166; }
.mark.ok { background: #fff; }

/* ── status ──────────────────────────────── */
.status { min-height: 46px; padding: 4px 4px 0; color: var(--text); }
.status .hint { color: var(--muted); font-size: 13px; margin-top: 2px; }
.status .clash { color: var(--parry); }
.status .thinking { color: var(--muted); }
.status .thinking::after { content: '…'; animation: dots 1s steps(3) infinite; }
.status .poss { color: var(--muted); }
.status .hint-warn { display: block; color: #ffd166; font-size: 12.5px; margin-top: 2px; }
.cn { font-weight: 700; }
.cn.t-strike, .c-strike { color: var(--strike); }
.cn.t-evade, .c-evade { color: var(--evade); }
.cn.t-parry, .c-parry { color: var(--parry); }
.cn.t-guard, .c-guard { color: var(--guard); }
.cn.t-feint, .c-feint { color: var(--feint); }

/* ── hand ────────────────────────────────── */
.hand { display: flex; justify-content: center; gap: 12px; padding: 12px 0 4px; min-height: 214px; flex-wrap: wrap; }
.card {
  --c: #fff;
  position: relative; width: 136px; height: 196px; border-radius: 14px; padding: 10px 11px;
  background: linear-gradient(170deg, color-mix(in srgb, var(--c) 16%, #1a1f2b) 0%, #12151d 55%);
  border: 1.5px solid color-mix(in srgb, var(--c) 70%, transparent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  cursor: pointer; user-select: none; transition: transform 0.18s, box-shadow 0.18s, opacity 0.2s;
  display: flex; flex-direction: column; animation: deal 0.35s ease-out backwards;
}
@keyframes deal { from { transform: translateY(30px); opacity: 0; } }
.card:hover { transform: translateY(-12px) rotate(-1deg); box-shadow: 0 16px 34px rgba(0, 0, 0, 0.55), 0 0 22px color-mix(in srgb, var(--c) 35%, transparent); }
.hand.locked .card { cursor: default; opacity: 0.55; filter: saturate(0.7); }
.hand.locked .card:hover { transform: translateY(-4px); }
.card.t-strike { --c: var(--strike); }
.card.t-evade { --c: var(--evade); }
.card.t-parry { --c: var(--parry); }
.card.t-guard { --c: var(--guard); }
.card.t-feint { --c: var(--feint); }
.card .top { display: flex; justify-content: space-between; align-items: flex-start; }
.card .tempo {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font: 800 19px Cinzel, serif; color: #0b0d12; background: var(--c); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 55%, transparent);
}
.card .kind { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--c); text-align: right; }
.card .key { display: block; color: var(--muted); font-weight: 600; margin-top: 2px; }
.card .icon { height: 54px; display: grid; place-items: center; margin: 6px 0 2px; color: var(--c); }
.card .icon svg { width: 46px; height: 46px; filter: drop-shadow(0 0 8px color-mix(in srgb, var(--c) 50%, transparent)); }
.card .nm { font-family: Cinzel, serif; font-weight: 800; font-size: 16px; text-align: center; letter-spacing: 0.04em; }
.card .stat { text-align: center; font-size: 12px; font-weight: 700; color: var(--c); margin: 2px 0 4px; }
.card .txt { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.35; margin-top: auto; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .pips { position: absolute; left: 0; right: 0; bottom: -7px; display: flex; justify-content: center; gap: 4px; }
.card .pips i { width: 18px; height: 5px; border-radius: 3px; background: var(--c); box-shadow: 0 0 6px var(--c); }

/* ── side panels ─────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.panel h3 { margin: 0 0 10px; font: 700 11px Inter, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.fine { color: var(--muted); font-size: 11px; margin: 10px 0 0; }
.trk { display: grid; grid-template-columns: 16px 1fr 1fr 1fr; gap: 8px 10px; align-items: center; }
.trk .tp { font: 800 12px Cinzel, serif; color: var(--muted); text-align: center; }
.trk .row { display: flex; justify-content: space-between; gap: 8px; }
.trk .pip-row { display: flex; gap: 3px; }
.trk .pip-row i { width: 9px; height: 9px; border-radius: 2px; background: var(--c); }
.trk .pip-row i.gone { background: transparent; border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.trk .nm { font-weight: 600; font-size: 12px; color: var(--c); }
.trk .t-strike { --c: var(--strike); }
.trk .t-evade { --c: var(--evade); }
.trk .t-parry { --c: var(--parry); }
.trk .t-guard { --c: var(--guard); }
.trk .t-feint { --c: var(--feint); }

.log-panel { flex: 1; display: flex; flex-direction: column; min-height: 260px; max-height: 560px; }
#log { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; font-size: 12.5px; }
#log li { padding: 6px 0; border-bottom: 1px solid var(--line); animation: slidein 0.25s ease-out; }
#log li .tk { display: inline-block; min-width: 30px; margin-right: 6px; font-size: 10px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
#log li.sys { color: var(--muted); }
#log li.hit { color: #ffd0d0; }
#log b.you { color: var(--you); }
#log b.ai { color: var(--ai); }
@keyframes slidein { from { opacity: 0; transform: translateX(8px); } }
@keyframes dots { 0% { content: ''; } 33% { content: '.'; } 66% { content: '..'; } 100% { content: '...'; } }

/* ── dialog / overlay ────────────────────── */
dialog {
  max-width: 640px; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: 16px; padding: 22px 26px;
  background: #121620; color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(4, 5, 8, 0.7); backdrop-filter: blur(3px); }
dialog h2 { font-family: Cinzel, serif; margin: 0 0 6px; letter-spacing: 0.08em; }
dialog h4 { margin: 18px 0 4px; font-size: 14px; }
dialog p, dialog li { color: #cfcabe; }
dialog .lead { color: var(--muted); }
dialog .tip { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 16px; }
dialog .right { text-align: right; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; }
.rt { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.rt th, .rt td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.rt th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.rt td:first-child { font: 800 15px Cinzel, serif; text-align: center; width: 54px; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(4, 5, 8, 0.55); backdrop-filter: blur(2px); z-index: 50; animation: fadein 0.4s; }
.overlay.hidden { display: none; }
.result-card { text-align: center; background: #121620; border: 1px solid var(--line); border-radius: 18px; padding: 30px 46px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
.result-card h2 { font: 800 42px Cinzel, serif; letter-spacing: 0.16em; margin: 0 0 6px; }
.result-card h2.win { color: var(--parry); text-shadow: 0 0 30px rgba(245, 184, 61, 0.5); }
.result-card h2.lose { color: var(--ai); }
.result-card p { color: var(--muted); margin: 0 0 20px; }
@keyframes fadein { from { opacity: 0; } }

/* ── fit the whole duel on one screen (desktop) ─────────── */
@media (min-width: 1001px) {
  body { height: 100vh; display: flex; flex-direction: column; overflow-y: auto; }
  .topbar { flex: none; padding: 10px 22px; }
  .layout { flex: 1 1 0; min-height: 0; width: 100%; padding: 10px 20px; grid-template-rows: minmax(0, 1fr); }
  .stage { min-height: 0; gap: 8px; }
  .arena-wrap { flex: 1 1 0; height: auto; min-height: 140px; max-height: 300px; }
  .hand { flex: none; min-height: 0; padding: 6px 0 10px; }
  .side { min-height: 0; }
  .log-panel { min-height: 0; max-height: none; }
  .status { min-height: 40px; }
}
@media (min-width: 1001px) and (max-height: 880px) {
  .pbar { padding: 5px 12px; }
  .card { width: 124px; height: 174px; padding: 8px 9px; border-radius: 12px; }
  .card .tempo { width: 28px; height: 28px; font-size: 16px; }
  .card .icon { height: 36px; margin: 2px 0 0; }
  .card .icon svg { width: 32px; height: 32px; }
  .card .nm { font-size: 14px; }
  .card .stat { font-size: 11px; margin: 1px 0 2px; }
  .card .txt { font-size: 10px; line-height: 1.3; -webkit-line-clamp: 3; }
  .card .kind { font-size: 9px; }
}
@media (max-width: 1000px) {
  .arena-wrap { height: 260px; }
}

/* ── extended mode: Read ─────────────────── */
:root { --read: #e8e3d3; }
.bar.t-read, .card.t-read, .trk .t-read { --c: var(--read); }
.cn.t-read, .c-read { color: var(--read); }

/* ── stance mode ─────────────────────────── */
.bar.t-kick, .card.t-kick, .trk .t-kick { --c: var(--kick); }
.cn.t-kick, .c-kick { color: var(--kick); }
.c-stance { color: var(--stance); font-weight: 600; }
.bar.stagger.broken { --c: var(--stance); color: var(--stance); }
.stance { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.stance .pips { display: flex; gap: 3px; }
.stance .pips i { width: 14px; height: 14px; transform: rotate(45deg) scale(0.75); border: 1.5px solid color-mix(in srgb, var(--stance) 55%, transparent); border-radius: 2px; transition: background 0.25s, box-shadow 0.25s; }
.stance .pips i.on { background: var(--stance); border-color: var(--stance); box-shadow: 0 0 7px color-mix(in srgb, var(--stance) 60%, transparent); }
.stance .pips i.lost { animation: lost 0.6s ease-out; }
.stance.low .pips i.on { animation: lowpulse 0.9s ease-in-out infinite alternate; }
@keyframes lowpulse { to { box-shadow: 0 0 12px var(--stance); filter: brightness(1.3); } }
.trk.cols4 { grid-template-columns: 16px 1fr 1fr 1fr 1fr; }
.mode-only { display: none; }
body[data-mode="stance"] .mode-only.stance { display: block; }
body[data-mode="extended2"] .mode-only.extended2 { display: block; }
body[data-mode="tempo4"] .mode-only.tempo4 { display: block; }
.read-btn { margin-left: 8px; padding: 2px 10px; font-size: 12px; border-color: rgba(232, 227, 211, 0.4); }
.read-btn:not([disabled]) { box-shadow: 0 0 10px rgba(232, 227, 211, 0.25); }
.read-btn[disabled] { opacity: 0.45; cursor: default; }
/* a card uncovered by a Read: glows and carries an eye */
.bar.read-hit { box-shadow: 0 0 0 1px #e8e3d3, 0 0 16px rgba(232, 227, 211, 0.55); animation: readpulse 1.6s ease-out 2; }
.bar.read-hit::after { content: '👁'; position: absolute; right: 6px; font-size: 12px; }
@keyframes readpulse { 0% { box-shadow: 0 0 0 2px #fff, 0 0 30px rgba(255, 255, 255, 0.9); } 100% { box-shadow: 0 0 0 1px #e8e3d3, 0 0 16px rgba(232, 227, 211, 0.55); } }
body[data-mode="flagship"] .mode-only.flagship { display: block; }
/* opponent's hand revealed by Read */
.seen-hand { display: flex; gap: 4px; align-items: center; animation: readpulse 1.6s ease-out 1; border-radius: 6px; padding: 2px 4px; }
.seen-hand .mini { font-style: normal; display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  color: var(--c); border: 1px solid var(--c); background: color-mix(in srgb, var(--c) 14%, #10131a); white-space: nowrap; }
.seen-hand .mini b { font-family: Cinzel, serif; }
.seen-hand .t-strike { --c: var(--strike); } .seen-hand .t-evade { --c: var(--evade); } .seen-hand .t-parry { --c: var(--parry); }
.seen-hand .t-guard { --c: var(--guard); } .seen-hand .t-feint { --c: var(--feint); } .seen-hand .t-scout, .seen-hand .t-read { --c: #e8e3d3; }
.bar.t-scout, .card.t-scout, .trk .t-scout { --c: var(--read, #e8e3d3); }
.cn.t-scout { color: var(--read, #e8e3d3); }
/* footsies (experimental spatial mode) */
body[data-mode="footsies"] .mode-only.footsies { display: block; }
body[data-mode="footsies"] .mode-only.flagship { display: block; }
