:root {
  --bg: #0b0a0d;
  --bg-2: #141217;
  --panel: #18151b;
  --line: #2c2730;
  --ink: #f2ebdd;
  --muted: #a39b8f;
  --gold: #e9c46a;
  --gold-2: #f5d98b;
  --red: #d64545;
  --green: #7bd88f;
  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #1d1822 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100%; }
button { font: inherit; color: inherit; }
img { display: block; }

.eyebrow { margin: 0 0 4px; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.hidden { display: none !important; }
.loading { display: grid; place-items: center; min-height: 100vh; margin: 0; font-family: var(--display); color: var(--gold); letter-spacing: .1em; }

/* buttons */
.btn {
  appearance: none; border: 1px solid #3a3340; background: #221e26; color: var(--ink);
  padding: 10px 16px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1b1408; border-color: var(--gold); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--line); }
.btn.big { padding: 14px 28px; font-size: 16px; letter-spacing: .04em; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(233,196,106,.18); } }

/* title */
.title-screen { position: relative; min-height: 100vh; display: grid; place-items: center; overflow: hidden; padding: 24px 16px; }
.title-ring { position: absolute; width: min(92vmin, 760px); aspect-ratio: 1; animation: spin 140s linear infinite; }
.ring-face {
  position: absolute; left: 50%; top: 50%; width: 13%; aspect-ratio: 1; border-radius: 50%;
  border: 2px solid var(--c); box-shadow: 0 0 22px color-mix(in srgb, var(--c) 45%, transparent);
  transform: translate(-50%, -50%) rotate(calc(var(--i) * 30deg)) translateY(-44vmin) rotate(calc(var(--i) * -30deg));
  opacity: .85;
}
@media (min-width: 900px) { .ring-face { transform: translate(-50%, -50%) rotate(calc(var(--i) * 30deg)) translateY(-330px) rotate(calc(var(--i) * -30deg)); } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .title-ring { animation: none; } .btn.pulse { animation: none; } }
.title-block { position: relative; text-align: center; padding: 24px; }
.logo {
  margin: 0; font-family: var(--display); font-weight: 900; font-size: clamp(52px, 11vw, 116px);
  letter-spacing: .12em; color: var(--gold); line-height: 1;
  text-shadow: 0 0 40px rgba(233,196,106,.35);
}
.subtitle { margin: 10px 0 0; font-family: var(--display); letter-spacing: .3em; text-transform: uppercase; font-size: clamp(13px, 2.4vw, 19px); }
.tagline { color: var(--muted); margin: 14px 0 28px; }
.build { color: #6d665e; font-size: 12px; margin-top: 22px; letter-spacing: .1em; text-transform: uppercase; }

/* select */
.select-screen { max-width: 1200px; margin: 0 auto; padding: 12px 16px 32px; }
.topbar { display: grid; grid-template-columns: 100px 1fr 100px; align-items: center; margin-bottom: 12px; }
.topbar h1 { margin: 0; text-align: center; font-family: var(--display); font-size: 22px; letter-spacing: .08em; }
.select-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 24px; }
@media (max-width: 900px) { .select-body { grid-template-columns: 1fr; } .preview { order: -1; } }
.pick { min-width: 0; }
.khan-input { display: flex; gap: 8px; align-items: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.khan-input .hash { color: var(--gold); font-weight: 700; padding-left: 8px; }
.khan-input input { flex: 1; min-width: 60px; background: transparent; border: 0; color: var(--ink); font: 600 16px var(--ui); padding: 8px 4px; }
.khan-input input:focus { outline: none; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 20px; }
.error { color: #ff8a80; font-size: 13px; margin: 6px 0 0; min-height: 0; }
.dyn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 10px; }
.dyn {
  display: grid; justify-items: center; gap: 6px; padding: 12px 8px; text-align: center; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
}
.dyn img { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--c); object-fit: cover; }
.dyn:hover, .dyn.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, var(--bg-2)); }
.dyn-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.rar { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.r-uncommon { color: #7bd88f; } .r-rare { color: #6fb6ff; } .r-epic { color: #c08bff; } .r-legendary { color: var(--gold); }

.preview { display: grid; gap: 14px; align-content: start; min-width: 0; }
.warlord {
  display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 18px; padding: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 12%, var(--panel)), var(--panel) 55%);
  border: 1px solid color-mix(in srgb, var(--c) 40%, var(--line)); border-radius: 16px;
}
@media (max-width: 560px) { .warlord { grid-template-columns: 1fr; } .warlord-art { max-width: 240px; margin: 0 auto; } }
.warlord-art { width: 100%; border-radius: 10px; aspect-ratio: 1; object-fit: cover; }
.warlord h2 { margin: 0; font-family: var(--display); font-size: 26px; letter-spacing: .04em; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 12px 0; }
.stats.small { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 8px 0; }
.stat { background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px; text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ability-box { background: rgba(233,196,106,.07); border: 1px solid rgba(233,196,106,.3); border-radius: 10px; padding: 10px 12px; }
.ability-box p:last-child { margin: 4px 0 0; font-size: 13px; color: #d8cfbf; }
.ability-box.small { padding: 8px 10px; }
.ability-box .cd { color: var(--muted); font-size: 12px; }
.traits { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.traits li { display: grid; grid-template-columns: 82px minmax(0, 1fr); column-gap: 10px; font-size: 13px; }
.t-label { color: var(--muted); grid-row: span 2; }
.t-value { font-weight: 600; }
.t-effect { color: #c9bfae; font-size: 12px; }
.rival { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; }
.rival img { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--red); flex: none; }
.rival > div { flex: 1; min-width: 0; }
.rival .eyebrow { color: #ff8a80; }

/* battle */
.battle-screen { display: grid; grid-template-columns: minmax(0, 1fr) 340px; height: 100vh; height: 100dvh; }
.board-wrap { position: relative; min-height: 0; }
.board { width: 100%; height: 100%; display: block; cursor: pointer; touch-action: manipulation; }
.panel { background: var(--panel); border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.panel-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.turn { font-size: 14px; }
@media (max-width: 860px) {
  .battle-screen { grid-template-columns: 1fr; grid-template-rows: minmax(0, 58vh) auto; height: auto; min-height: 100dvh; }
  .board-wrap { height: 58vh; height: 58dvh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
}
.unit-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 120px; }
.uc-head { display: flex; gap: 12px; align-items: center; }
.uc-head img, .uc-glyph { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--c); flex: none; object-fit: cover; }
.uc-head.enemy img, .uc-head.enemy .uc-glyph { box-shadow: 0 0 0 2px var(--red); }
.uc-head.player img, .uc-head.player .uc-glyph { box-shadow: 0 0 0 2px var(--gold); }
.uc-glyph { display: grid; place-items: center; font-weight: 700; color: var(--c); background: #1d1a20; font-size: 20px; }
.uc-head b { display: block; }
.hpbar { position: relative; height: 18px; background: #0d0c0f; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-top: 10px; }
.hpbar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #4caf6a, var(--green)); }
.hpbar span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 16px; font-weight: 600; text-shadow: 0 1px 2px #000; }
.statuses { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #2a2530; border: 1px solid var(--line); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn:first-child { grid-column: span 2; }
.panel-top .turn { flex: 1; text-align: center; }
.roster { display: grid; gap: 6px; }
.ro { display: flex; gap: 6px; }
.ro-u { position: relative; flex: 1; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #1f1b22; cursor: pointer; overflow: hidden; padding: 0; }
.ro.player .ro-u { border-color: rgba(233,196,106,.45); }
.ro.enemy .ro-u { border-color: rgba(214,69,69,.45); }
.ro-u span { position: relative; z-index: 1; font-weight: 700; font-size: 13px; }
.ro-u i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--green); }
.ro.enemy .ro-u i { background: #e8615a; }
.ro-u.dead { opacity: .3; }
.ro-u.done { opacity: .6; }
.ro-u.sel { outline: 2px solid #fff; }
.log-wrap summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.log { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; color: #cfc6b8; max-height: 220px; overflow-y: auto; }
.log li:first-child { color: var(--ink); }
.banner {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%); pointer-events: none;
  font-family: var(--display); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 20px;
  color: var(--c, var(--gold)); text-shadow: 0 2px 12px #000; opacity: 0; white-space: nowrap;
}
.banner.show { animation: banner 1.6s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -8px); } 15%, 70% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.tip {
  position: absolute; pointer-events: none; white-space: pre-line; font-size: 12px; background: rgba(12,10,14,.92);
  border: 1px solid var(--line); padding: 6px 8px; border-radius: 6px; max-width: 240px; z-index: 2;
}
@media (hover: none) { .tip { display: none; } }
.overlay { position: fixed; inset: 0; background: rgba(5,4,7,.72); display: grid; place-items: center; padding: 16px; z-index: 5; backdrop-filter: blur(3px); }
.result { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; text-align: center; }
.result h2 { font-family: var(--display); font-size: 48px; margin: 4px 0 8px; letter-spacing: .08em; }
.result.win h2 { color: var(--gold); }
.result.lose h2 { color: #ff8a80; }
.result .stats { grid-template-columns: repeat(3, 1fr); }
.result .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

/* how to play */
.title-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.howto-screen { max-width: 860px; margin: 0 auto; padding: 12px 16px 40px; }
.howto { display: grid; gap: 14px; }
.ht-lead { font-size: 17px; color: var(--ink); margin: 4px 0 4px; max-width: 65ch; }
.ht-sec { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; min-width: 0; }
.ht-sec h3 { margin: 0 0 8px; font-family: var(--display); font-size: 18px; letter-spacing: .05em; color: var(--gold); }
.ht-sec p, .ht-sec li { color: #ddd4c5; max-width: 70ch; }
.ht-sec ol, .ht-sec ul { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.ht-note { color: var(--muted) !important; font-size: 13px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.sw-move { background: rgba(110,180,255,.35); border: 1px solid rgba(140,200,255,.8); }
.sw-attack { border: 2px dashed #ff5050; border-radius: 50%; }
.sw-ability { background: rgba(233,196,106,.35); border: 1px solid rgba(255,220,130,.9); }
.ht-abilities { list-style: none; padding: 0 !important; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px !important; }
.ht-abilities li { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.ht-abilities img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--c); flex: none; }
.ht-abilities b { display: block; color: var(--ink); }
.ht-abilities small { display: block; color: var(--c); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
.ht-terrain { list-style: none; padding: 0 !important; }
.ht-terrain li { display: flex; align-items: center; gap: 8px; }
.ht-terrain b { margin-right: 2px; }
.tt { width: 22px; height: 22px; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); flex: none; }
.t-hill { background: #5a4a31; } .t-forest { background: #244028; } .t-water { background: #1a3f5c; } .t-rock { background: #3f3f46; } .t-fire { background: #c85a1e; }
.ht-ring { list-style: none; padding: 0 !important; display: flex !important; flex-wrap: wrap; gap: 6px 4px !important; }
.ht-ring li { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 66px; font-size: 11px; text-align: center; position: relative; }
.ht-ring li:not(:last-child)::after { content: "▸"; position: absolute; right: -7px; top: 13px; color: var(--muted); font-size: 12px; }
.ht-ring img { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--c); }
.ht-status, .ht-keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; margin: 6px 0 0; }
.ht-status div, .ht-keys div { display: flex; align-items: center; gap: 8px; }
.ht-status dt { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: #111; font-weight: 700; font-size: 11px; flex: none; }
.ht-status dd, .ht-keys dd { margin: 0; font-size: 13px; color: #ddd4c5; }
kbd { font: 600 12px var(--ui); background: #2a2530; border: 1px solid #3a3340; border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; color: var(--ink); }
.ht-cta { display: flex; justify-content: center; margin-top: 20px; }
.guide-modal { width: min(860px, 100%); max-height: 90vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.guide-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; position: sticky; top: -16px; background: var(--panel); padding: 6px 0; z-index: 1; }
.guide-head h2 { margin: 0; font-family: var(--display); letter-spacing: .06em; }
