:root {
  --bg: #07070b;
  --panel: rgba(14, 13, 20, 0.72);
  --panel-solid: #14131c;
  --line: rgba(255, 220, 160, 0.16);
  --line-strong: rgba(255, 200, 120, 0.55);
  --text: #f3ead8;
  --muted: #b7ab95;
  --gold: #e8b65a;
  --gold-deep: #9a6a1f;
  --danger: #ff6b5e;
  --cyan: #6fe3ff;
  --radius: 14px;
  --font: "Be Vietnam Pro", system-ui, sans-serif;
  --display: "Playfair Display", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible + *, input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* Cinematic letterbox bars slide in during capture shots. */
.letterbox { position: fixed; left: 0; right: 0; height: 0; background: #000; z-index: 5; transition: height 0.6s ease; pointer-events: none; }
.letterbox.top { top: 0; }
.letterbox.bottom { bottom: 0; }
body.cinematic .letterbox { height: 11vh; }
body.cinematic #hud { opacity: 0; }

.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: linear-gradient(180deg, rgba(7, 7, 11, 0.15) 0%, rgba(7, 7, 11, 0.55) 55%, rgba(7, 7, 11, 0.9) 100%); }
.overlay.dim { background: rgba(5, 5, 8, 0.62); backdrop-filter: blur(3px); }

.menu-card { width: min(760px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px;
  backdrop-filter: blur(14px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55); }
.menu-card.small { width: min(460px, 100%); text-align: center; }
header { text-align: center; margin-bottom: 18px; }
h1 { font-family: var(--display); font-weight: 900; font-size: clamp(42px, 8vw, 72px); margin: 0; letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff3d6, var(--gold) 55%, var(--gold-deep)); -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(232, 182, 90, 0.25); }
h2 { font-family: var(--display); font-size: 32px; margin: 0 0 8px; color: var(--gold); }
header p { margin: 4px 0 0; color: var(--muted); }

fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
legend { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; padding: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.choices { display: grid; gap: 10px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choices.bots { grid-template-columns: repeat(3, 1fr); }
.choices.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.choice, .pill { position: relative; cursor: pointer; }
.choice input, .pill input { position: absolute; opacity: 0; pointer-events: none; }
.choice { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, 0.03); transition: border-color 0.2s, background 0.2s, transform 0.2s; }
.choice:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.choice:has(input:checked) { border-color: var(--gold); background: rgba(232, 182, 90, 0.12); box-shadow: inset 0 0 0 1px var(--gold), 0 0 24px rgba(232, 182, 90, 0.15); }
.choice .glyph { grid-row: span 2; font-size: 30px; width: 40px; text-align: center; }
.choice .glyph.han { font-family: KaiTi, STKaiti, "Noto Serif SC", serif; color: #e0473a; }
.choice b { font-weight: 500; }
.choice small { color: var(--muted); font-size: 12px; }
.choice .lvl { color: var(--gold); font-size: 11px; letter-spacing: 0.1em; }
.pill span { display: inline-block; padding: 9px 16px; border: 1px solid var(--line); border-radius: 999px; transition: border-color 0.2s, background 0.2s; }
.pill:hover span { border-color: var(--line-strong); }
.pill input:checked + span { border-color: var(--gold); background: rgba(232, 182, 90, 0.14); }

input[type="text"], input:not([type]) { width: 100%; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); color: var(--text); font: inherit; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 0 0 8px; }

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.menu-card.small .actions { justify-content: center; margin-top: 18px; }
.primary { padding: 12px 28px; border: 0; border-radius: 999px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #1d1405;
  background: linear-gradient(180deg, #ffe2a0, var(--gold) 60%, #c4882c); box-shadow: 0 8px 30px rgba(232, 182, 90, 0.35); transition: transform 0.15s, box-shadow 0.15s; }
.primary:disabled { opacity: 0.6; cursor: progress; }
.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 36px rgba(232, 182, 90, 0.5); }
.ghost { padding: 12px 20px; border: 1px solid var(--line); border-radius: 999px; background: transparent; }
.ghost:hover { border-color: var(--line-strong); }

/* In-game HUD */
#hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; transition: opacity 0.4s; }
.topbar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.players, .turn, .tools { pointer-events: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; backdrop-filter: blur(10px); }
.players em { color: var(--muted); margin: 0 8px; font-style: normal; font-size: 12px; }
.turn { font-weight: 500; }
.turn.thinking::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 50%; background: var(--cyan); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.2; } }
.tools { display: flex; gap: 4px; padding: 4px; }
.tools button { width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; font-size: 17px; }
.tools button:hover { background: rgba(255, 255, 255, 0.08); }
.tools button[aria-pressed="false"] { opacity: 0.4; }
.moves { position: absolute; left: 12px; bottom: 12px; width: 220px; max-height: 32vh; overflow-y: auto; margin: 0; padding: 10px 12px 10px 36px; pointer-events: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; color: var(--muted); columns: 2; column-gap: 12px; }
.moves:empty { display: none; }
.moves li { break-inside: avoid; }
.moves li:last-child { color: var(--text); }
.bubble { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(560px, calc(100% - 32px)); pointer-events: auto;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 18px; padding: 12px 18px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); animation: rise 0.35s ease; }
.bubble b { display: block; font-size: 12px; color: var(--gold); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 2px; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td:last-child, th:last-child { text-align: right; }
#lb-tabs { justify-content: center; }
#lb-body p { color: var(--muted); }

@media (max-width: 640px) {
  .menu-card { padding: 20px 16px; }
  .row, .choices.two, .choices.three { grid-template-columns: 1fr; }
  .choices.bots { grid-template-columns: 1fr 1fr; }
  .moves { display: none; }
  .players { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
