/* =========================================================
   Makruk 3D — Thai Chess Academy & Beginner Studio
   Visual language: midnight lacquer, aged teak, ivory & gold.
   ========================================================= */

:root {
  --text-scale: 1;
  --bg-deep: #080604;
  --bg: #100b07;
  --bg-soft: #171009;
  --panel: rgba(27, 18, 12, 0.76);
  --panel-solid: #1b120c;
  --panel-lift: rgba(43, 29, 19, 0.66);
  --line: rgba(220, 186, 116, 0.18);
  --line-strong: rgba(220, 186, 116, 0.36);
  --gold: #d6b36a;
  --gold-bright: #f3d58e;
  --gold-deep: #a77b32;
  --cream: #f4e9d2;
  --cream-dim: #d5c5a8;
  --muted: #a7957d;
  --faint: #776a58;
  --green: #6fe0a0;
  --green-deep: #1f7a4d;
  --red: #ff7866;
  --red-deep: #9e382b;
  --blue: #91c4e8;
  --shadow-xl: 0 40px 100px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 22px 56px rgba(0, 0, 0, 0.38);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.28);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-display: "Cormorant Garamond", "Noto Serif Thai", Georgia, serif;
  --font-body: "Manrope", "Noto Sans Thai", system-ui, sans-serif;
  --font-thai: "Noto Serif Thai", "Noto Sans Thai", serif;
  --max-width: 1540px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}


html[data-text-size="small"] { --text-scale: 0.9; }
html[data-text-size="medium"] { --text-scale: 1; }
html[data-text-size="large"] { --text-scale: 1.2; }
html[data-text-size="xlarge"] { --text-scale: 1.4; }

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--cream);
  background:
    radial-gradient(ellipse at 14% -5%, rgba(214, 179, 106, 0.14), transparent 36%),
    radial-gradient(ellipse at 92% 78%, rgba(116, 44, 29, 0.18), transparent 43%),
    radial-gradient(ellipse at 50% 120%, rgba(84, 52, 25, 0.24), transparent 58%),
    linear-gradient(145deg, #080604 0%, #120c07 46%, #0a0705 100%);
  font-family: var(--font-body);
  font-size: calc(15px * var(--text-scale));
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible + .switch-track {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

::selection {
  color: #160f09;
  background: var(--gold-bright);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.16;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: 0.06;
  background-image:
    linear-gradient(30deg, transparent 48%, rgba(214, 179, 106, 0.55) 49%, rgba(214, 179, 106, 0.55) 51%, transparent 52%),
    linear-gradient(-30deg, transparent 48%, rgba(214, 179, 106, 0.35) 49%, rgba(214, 179, 106, 0.35) 51%, transparent 52%);
  background-size: 46px 80px;
  mask-image: radial-gradient(ellipse at center, black, transparent 78%);
}

/* ----------------------------- Shell ----------------------------- */

.app-shell {
  width: min(100%, var(--max-width));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 26px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  min-height: 76px;
  padding: 12px 14px 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(46, 31, 19, 0.62), rgba(17, 12, 8, 0.72)),
    radial-gradient(circle at 15% 0%, rgba(214, 179, 106, 0.1), transparent 42%);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 244, 218, 0.05);
  backdrop-filter: blur(18px) saturate(120%);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
  position: relative;
  z-index: 10;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(214, 179, 106, 0.35), transparent);
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-seal {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 50%;
  color: var(--gold-bright);
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 233, 178, 0.16), transparent 35%),
    linear-gradient(145deg, #3b2718, #17100a);
  border: 1px solid rgba(214, 179, 106, 0.42);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34), inset 0 0 0 4px rgba(8, 5, 3, 0.52);
}

.brand-seal::before,
.brand-seal::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(214, 179, 106, 0.25);
  border-radius: 50%;
}

.brand-seal::after {
  inset: 10px;
  border-style: dashed;
}

.brand-seal span {
  position: relative;
  z-index: 1;
  font-family: var(--font-thai);
  font-size: calc(24px * var(--text-scale));
  line-height: 1;
  transform: translateY(1px);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.eyebrow,
.micro-label {
  display: block;
  color: var(--gold);
  font-size: calc(9px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.22em;
  line-height: 1.3;
  text-transform: uppercase;
}

.brand-line {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand-line strong {
  font-family: var(--font-display);
  font-size: clamp(25px, 2vw, 32px);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1;
  color: var(--cream);
  white-space: nowrap;
}

.brand-subtitle {
  display: inline-block;
  max-width: 370px;
  overflow: hidden;
  color: var(--muted);
  font-size: calc(11.5px * var(--text-scale));
  font-weight: 500;
  letter-spacing: 0.045em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.lang-toggle {
  height: 42px;
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 5, 3, 0.35);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease;
}

.lang-toggle:hover {
  border-color: var(--line-strong);
  background: rgba(7, 5, 3, 0.5);
}

.lang-option {
  min-width: 34px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--faint);
  font-size: calc(10px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.12em;
  transition: color 200ms ease, background 200ms ease, box-shadow 200ms ease;
}

.lang-option.is-active {
  color: #1a120b;
  background: linear-gradient(145deg, #f3d58e, #d6b36a);
  box-shadow: 0 3px 12px rgba(214, 179, 106, 0.18);
}

.lang-divider {
  width: 1px;
  height: 15px;
  background: var(--line);
}

.icon-button {
  height: 42px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--cream-dim);
  background: rgba(7, 5, 3, 0.34);
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.icon-button:hover {
  color: var(--gold-bright);
  border-color: var(--line-strong);
  background: rgba(7, 5, 3, 0.5);
}

.icon-button[aria-pressed="false"] {
  color: var(--faint);
}

.icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.icon-sound-off,
.icon-button[aria-pressed="false"] .icon-sound-on {
  display: none;
}

.icon-button[aria-pressed="false"] .icon-sound-off {
  display: block;
}

.icon-label {
  font-size: calc(11px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.03em;
}

.button {
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: calc(12px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: transform 180ms var(--ease), border-color 180ms ease, background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-gold {
  color: #1b120a;
  background: linear-gradient(145deg, #f0d493 0%, #d4ad5e 48%, #b88a3e 100%);
  border-color: rgba(255, 238, 190, 0.4);
  box-shadow: 0 8px 20px rgba(184, 138, 62, 0.18), inset 0 1px 0 rgba(255, 249, 227, 0.4);
}

.button-gold:hover {
  box-shadow: 0 12px 26px rgba(184, 138, 62, 0.27), inset 0 1px 0 rgba(255, 249, 227, 0.5);
}

.button-primary {
  color: #1b120a;
  background: linear-gradient(145deg, #f0d493 0%, #d4ad5e 48%, #b88a3e 100%);
  border-color: rgba(255, 240, 196, 0.25);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.button-quiet {
  color: var(--cream-dim);
  border-color: var(--line);
  background: rgba(8, 5, 3, 0.28);
}

.button-quiet:hover {
  color: var(--gold-bright);
  border-color: var(--line-strong);
  background: rgba(8, 5, 3, 0.45);
}

.button-icon {
  font-size: calc(13px * var(--text-scale));
}

.button-rules {
  padding-inline: 17px;
}

/* ----------------------------- Workspace ----------------------------- */

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

.arena {
  min-width: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(35, 23, 14, 0.47), rgba(14, 10, 7, 0.43)),
    radial-gradient(circle at 50% 0%, rgba(214, 179, 106, 0.08), transparent 45%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 244, 218, 0.04);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.arena-head {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px;
}

.turn-cluster {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.turn-stone {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  position: relative;
  border: 1px solid rgba(255, 248, 226, 0.14);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, #fff7e5, #d2b780 43%, #7d5a2d 76%, #3c2a14 100%);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.34), inset 0 0 0 3px rgba(17, 11, 6, 0.34);
  transition: background 280ms ease, box-shadow 280ms ease;
}

.turn-stone.is-black {
  background:
    radial-gradient(circle at 34% 28%, #6e5741, #2a1c13 38%, #120c08 68%, #060403 100%);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.44), inset 0 0 0 3px rgba(214, 179, 106, 0.12), 0 0 0 2px rgba(214, 179, 106, 0.05);
}

html[data-piece-finish="ruby"] .turn-stone.is-black {
  background:
    radial-gradient(circle at 34% 28%, #ffb2a3, #b4232c 38%, #6d0f16 70%, #2a0508 100%);
  box-shadow: 0 5px 12px rgba(74, 5, 12, 0.5), inset 0 0 0 3px rgba(255, 226, 214, 0.14), 0 0 0 2px rgba(214, 179, 106, 0.06);
}

.turn-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.turn-copy strong {
  color: var(--cream);
  font-size: calc(14px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1.25;
}

.arena-chips {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  min-height: 28px;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(7, 5, 3, 0.27);
  font-size: calc(10px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.045em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
}

.chip-warning {
  color: #ffb2a7;
  border-color: rgba(255, 120, 102, 0.35);
  background: rgba(158, 56, 43, 0.2);
}

.chip-thinking {
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.33);
  background: rgba(214, 179, 106, 0.09);
}

.chip-level {
  padding-left: 6px;
  margin-left: 2px;
  border-left: 1px solid rgba(214, 179, 106, 0.3);
  color: rgba(255, 244, 218, 0.72);
  font-size: 0.92em;
  font-variant-numeric: tabular-nums;
}

.thinking-glass {
  width: 11px;
  height: 14px;
  position: relative;
  display: inline-block;
  flex: 0 0 11px;
  color: currentColor;
}

.thinking-glass::before,
.thinking-glass::after {
  content: "";
  width: 0;
  height: 0;
  position: absolute;
  left: 0;
  border-left: 5.5px solid transparent;
  border-right: 5.5px solid transparent;
}

.thinking-glass::before {
  top: 0;
  border-top: 6px solid currentColor;
  opacity: 0.8;
}

.thinking-glass::after {
  bottom: 0;
  border-bottom: 6px solid currentColor;
  opacity: 0.8;
}

.thinking-glass i {
  width: 2px;
  height: 2px;
  position: absolute;
  left: 4.5px;
  top: 2px;
  border-radius: 50%;
  background: currentColor;
  animation: sand-fall 1.5s infinite ease-in;
}

.thinking-glass i:nth-child(2) {
  animation-delay: 0.75s;
}

@keyframes sand-fall {
  0% { opacity: 0; transform: translateY(0); }
  18% { opacity: 1; }
  72% { opacity: 1; transform: translateY(8px); }
  100% { opacity: 0; transform: translateY(8px); }
}

/* ----------------------------- 3D stage ----------------------------- */

.board-stage {
  width: 100%;
  height: clamp(440px, 70vh, 840px);
  min-height: 420px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(214, 179, 106, 0.23);
  border-radius: calc(var(--radius-xl) - 8px);
  background:
    radial-gradient(circle at 50% 47%, rgba(139, 89, 42, 0.2), transparent 37%),
    radial-gradient(circle at 50% 110%, rgba(0, 0, 0, 0.56), transparent 55%),
    linear-gradient(160deg, #1b120c 0%, #0b0805 58%, #060403 100%);
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 242, 210, 0.05);
  isolation: isolate;
}

.board-stage::before {
  content: "";
  position: absolute;
  inset: 14px;
  z-index: 1;
  pointer-events: none;
  border: 1px solid rgba(214, 179, 106, 0.08);
  border-radius: 18px;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
  position: absolute;
  inset: 0;
  touch-action: none;
  cursor: grab;
}

#scene:active {
  cursor: grabbing;
}

.stage-vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: var(--stage-vignette-opacity, 1);
  transition: opacity 320ms ease;
  background:
    linear-gradient(90deg, rgba(4, 3, 2, 0.32), transparent 14%, transparent 86%, rgba(4, 3, 2, 0.32)),
    linear-gradient(180deg, rgba(4, 3, 2, 0.27), transparent 17%, transparent 78%, rgba(4, 3, 2, 0.36));
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.2);
}

.stage-toolbar {
  position: absolute;
  top: 17px;
  left: 17px;
  right: 17px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.stage-tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.stage-tool-group .stage-button {
  pointer-events: auto;
}

.stage-button.is-active {
  color: #1b120a;
  border-color: #f3d58e;
  background: linear-gradient(145deg, #f3d58e, #d6b36a);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.stage-button.is-active svg {
  fill: currentColor;
}

#scene.is-pan-mode {
  cursor: move;
}

#scene.is-pan-mode:active {
  cursor: grabbing;
}

.stage-button,
.assist-pill {
  min-height: 32px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(214, 179, 106, 0.18);
  border-radius: 999px;
  color: var(--cream-dim);
  background: rgba(10, 7, 4, 0.58);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: calc(9px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.stage-button {
  pointer-events: auto;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.stage-button:hover {
  color: var(--gold-bright);
  border-color: var(--line-strong);
  background: rgba(10, 7, 4, 0.76);
}

.stage-button svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

.replay-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 4;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border: 1px solid rgba(214, 179, 106, 0.3);
  border-radius: 999px;
  color: var(--cream-dim);
  background: rgba(10, 7, 4, 0.82);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 244, 218, 0.06);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.replay-bar[hidden] {
  display: none;
}

.replay-step {
  padding: 0 7px;
  color: var(--gold-bright);
  font-size: calc(9px * var(--text-scale));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.replay-divider {
  width: 1px;
  height: 17px;
  background: rgba(214, 179, 106, 0.24);
}

.replay-button,
.replay-exit {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.18);
  border-radius: 50%;
  color: var(--gold);
  background: rgba(214, 179, 106, 0.05);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.replay-button:hover:not(:disabled),
.replay-exit:hover {
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.5);
  background: rgba(214, 179, 106, 0.14);
}

.replay-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.replay-play {
  width: 31px;
  height: 31px;
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.46);
  background: rgba(214, 179, 106, 0.13);
}

.replay-exit {
  font-size: 12px;
  color: var(--muted);
}

.view-toggle {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  pointer-events: auto;
}

.view-toggle[hidden] {
  display: none;
}

.view-toggle.is-raised {
  bottom: 70px;
}

.view-toggle.is-active {
  color: #1b120a;
  border-color: rgba(243, 213, 142, 0.9);
  background: linear-gradient(145deg, #f3d58e, #d6b36a);
}

.assist-pill {
  transition: opacity 180ms ease, border-color 180ms ease;
}

.assist-pill.is-off {
  opacity: 0.48;
}

.assist-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(111, 224, 160, 0.8);
}

.assist-pill.is-off .assist-dot {
  background: var(--faint);
  box-shadow: none;
}

.scene-loader {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  color: var(--muted);
  background:
    radial-gradient(circle at center, rgba(25, 17, 11, 0.82), rgba(7, 5, 3, 0.94)),
    #090604;
  font-size: calc(11px * var(--text-scale));
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: opacity 420ms ease, visibility 420ms ease;
}

.scene-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.33);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: var(--font-thai);
  font-size: calc(26px * var(--text-scale));
  background: rgba(214, 179, 106, 0.05);
  box-shadow: inset 0 0 0 6px rgba(214, 179, 106, 0.04);
  animation: breathe 2.2s infinite ease-in-out;
}

.loader-line {
  width: 90px;
  height: 1px;
  overflow: hidden;
  position: relative;
  background: rgba(214, 179, 106, 0.15);
}

.loader-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  animation: loaderSweep 1.65s infinite ease-in-out;
}

@keyframes loaderSweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); box-shadow: inset 0 0 0 6px rgba(214, 179, 106, 0.04), 0 0 0 rgba(214, 179, 106, 0); }
  50% { transform: scale(1.035); box-shadow: inset 0 0 0 6px rgba(214, 179, 106, 0.06), 0 0 30px rgba(214, 179, 106, 0.08); }
}

.scene-fallback {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 30px;
  text-align: center;
  background: #0c0805;
}

.scene-fallback strong {
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: calc(23px * var(--text-scale));
}

.scene-fallback span {
  color: var(--muted);
  font-size: calc(12px * var(--text-scale));
}

/* ----------------------------- Tutor ----------------------------- */

.tutor {
  min-height: 76px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background:
    linear-gradient(110deg, rgba(46, 30, 18, 0.68), rgba(15, 10, 7, 0.58)),
    radial-gradient(circle at 8% 50%, rgba(214, 179, 106, 0.07), transparent 28%);
  box-shadow: inset 0 1px 0 rgba(255, 244, 218, 0.04);
}

.tutor-empty {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.tutor-glyph {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: calc(20px * var(--text-scale));
  background: rgba(214, 179, 106, 0.04);
}

.tutor-empty strong {
  display: block;
  color: var(--cream);
  font-size: calc(12.5px * var(--text-scale));
  font-weight: 700;
}

.tutor-empty small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.45;
}

.tutor-content {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(150px, 1.05fr) minmax(210px, 2.4fr) auto;
  align-items: center;
  gap: 18px;
}

.tutor-identity {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.tutor-piece-icon {
  width: 45px;
  height: 45px;
  flex: 0 0 45px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.26);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: calc(26px * var(--text-scale));
  line-height: 1;
  background: radial-gradient(circle at 35% 30%, rgba(255, 242, 205, 0.11), transparent 58%), rgba(7, 5, 3, 0.24);
}

.tutor-name strong {
  display: block;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(21px * var(--text-scale));
  font-weight: 600;
  line-height: 1.05;
}

.tutor-name small {
  display: block;
  margin-top: 3px;
  color: var(--gold);
  font-family: var(--font-thai);
  font-size: calc(12px * var(--text-scale));
}

.tutor-3d-link {
  margin-top: 5px;
  padding: 3px 7px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(214, 179, 106, 0.24);
  border-radius: 999px;
  color: var(--gold);
  background: rgba(214, 179, 106, 0.06);
  font-family: var(--font-body);
  font-size: calc(8px * var(--text-scale));
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.tutor-3d-link:hover {
  color: var(--gold-bright);
  border-color: var(--line-strong);
  background: rgba(214, 179, 106, 0.12);
}

.tutor-3d-link span:first-child {
  font-size: calc(10px * var(--text-scale));
  line-height: 1;
}

.tutor-movement {
  padding-left: 18px;
  border-left: 1px solid var(--line);
  min-width: 0;
}

.tutor-movement strong {
  display: block;
  margin-bottom: 2px;
  color: var(--gold);
  font-size: calc(9px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.tutor-movement span {
  display: block;
  color: var(--cream-dim);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.55;
}

.tutor-stats {
  display: flex;
  align-items: stretch;
  gap: 7px;
}

.tutor-stat {
  min-width: 57px;
  padding: 7px 9px;
  display: grid;
  gap: 0;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(7, 5, 3, 0.23);
}

.tutor-stat strong {
  color: var(--cream);
  font-size: calc(18px * var(--text-scale));
  font-weight: 700;
  line-height: 1.15;
}

.tutor-stat span {
  color: var(--muted);
  font-size: calc(8px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.tutor-stat.is-capture strong {
  color: var(--red);
}

.tutor-stat.is-off strong {
  color: var(--faint);
}

/* ----------------------------- Captured tray ----------------------------- */

.capture-tray {
  min-height: 36px;
  padding: 3px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
}

.capture-side {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.capture-side-right {
  justify-content: flex-end;
  text-align: right;
}

.capture-label {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: calc(8.5px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.capture-pieces {
  min-width: 20px;
  overflow: hidden;
  color: var(--gold);
  font-size: calc(15px * var(--text-scale));
  letter-spacing: 0.04em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.capture-separator {
  width: 1px;
  height: 14px;
  flex: 0 0 1px;
  background: var(--line);
}

/* ----------------------------- Sidebar ----------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(158deg, rgba(39, 25, 16, 0.57), rgba(14, 10, 7, 0.58)),
    radial-gradient(circle at 90% 0%, rgba(214, 179, 106, 0.06), transparent 32%);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 244, 218, 0.035);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-bottom: 13px;
}

.panel-heading.compact {
  margin-bottom: 0;
}

.panel-number {
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.2);
  border-radius: 50%;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: calc(9px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
}

.panel-heading h2 {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(19px * var(--text-scale));
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.15;
}

.panel-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: calc(9.5px * var(--text-scale));
  line-height: 1.45;
}

.mode-grid {
  display: grid;
  gap: 7px;
}

.bot-settings {
  margin-top: 13px;
  padding-top: 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid rgba(214, 179, 106, 0.14);
}

.bot-settings[hidden] {
  display: none;
}

.bot-settings-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bot-settings-head h3 {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(15px * var(--text-scale));
  font-weight: 600;
  line-height: 1.15;
}

.bot-settings-head p {
  margin: 0;
  color: var(--muted);
  font-size: calc(8.5px * var(--text-scale));
  line-height: 1.5;
}

.bot-level-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.bot-level-card {
  min-height: 60px;
  padding: 9px 9px 8px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  border: 1px solid rgba(214, 179, 106, 0.14);
  border-radius: 10px;
  color: var(--muted);
  text-align: left;
  background:
    linear-gradient(160deg, rgba(255, 244, 218, 0.028), transparent 58%),
    rgba(7, 5, 3, 0.2);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms var(--ease);
}

.bot-level-card:hover {
  border-color: rgba(214, 179, 106, 0.34);
  background:
    linear-gradient(160deg, rgba(255, 244, 218, 0.05), transparent 58%),
    rgba(7, 5, 3, 0.3);
  transform: translateY(-1px);
}

.bot-level-card.is-active {
  border-color: rgba(214, 179, 106, 0.55);
  background:
    linear-gradient(135deg, rgba(214, 179, 106, 0.14), rgba(214, 179, 106, 0.02)),
    rgba(7, 5, 3, 0.26);
  box-shadow: inset 0 0 0 1px rgba(214, 179, 106, 0.14), 0 7px 18px rgba(0, 0, 0, 0.22);
}

.bot-level-pips {
  height: 9px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
}

.bot-level-pips i {
  width: 9px;
  height: 3px;
  display: block;
  border-radius: 1px;
  background: rgba(214, 179, 106, 0.18);
  transition: background 180ms ease, box-shadow 180ms ease;
}

.bot-level-pips i:nth-child(2) {
  height: 5px;
}

.bot-level-pips i:nth-child(3) {
  height: 7px;
}

.bot-level-pips i:nth-child(4) {
  height: 9px;
}

.bot-level-pips i.is-on {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  box-shadow: 0 0 6px rgba(243, 213, 142, 0.28);
}

.bot-level-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-right: 14px;
}

.bot-level-copy strong {
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(13px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.bot-level-copy small {
  max-width: 100%;
  overflow: hidden;
  color: var(--faint);
  font-size: calc(7.8px * var(--text-scale));
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-level-check {
  width: 14px;
  height: 14px;
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #1c1307;
  background: linear-gradient(135deg, var(--gold-bright), #c9a45c);
  font-size: 9px;
  font-weight: 900;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 180ms ease, transform 180ms var(--ease);
}

.bot-level-card.is-active .bot-level-check {
  opacity: 1;
  transform: scale(1);
}

.think-time {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 1px;
}

.think-time label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--cream);
  font-size: calc(9.5px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.02em;
}

.think-time output {
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.think-time input[type="range"] {
  width: 100%;
  height: 16px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.think-time input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    var(--gold-bright) 0 var(--range-progress, 0%),
    rgba(214, 179, 106, 0.16) var(--range-progress, 0%) 100%
  );
}

.think-time input[type="range"]::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid #2a1a0d;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.think-time input[type="range"]:focus-visible {
  outline: none;
}

.think-time input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(243, 213, 142, 0.24);
}

.think-time input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(214, 179, 106, 0.16);
}

.think-time input[type="range"]::-moz-range-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--gold-bright);
}

.think-time input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 2px solid #2a1a0d;
  border-radius: 50%;
  background: var(--gold-bright);
}

.think-time-scale {
  display: flex;
  justify-content: space-between;
  color: var(--faint);
  font-size: calc(7.5px * var(--text-scale));
  letter-spacing: 0.04em;
}

.mode-card {
  width: 100%;
  min-height: 55px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  border: 1px solid rgba(214, 179, 106, 0.12);
  border-radius: var(--radius-sm);
  text-align: left;
  background: rgba(7, 5, 3, 0.22);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms var(--ease);
}

.mode-card:hover {
  border-color: rgba(214, 179, 106, 0.3);
  background: rgba(7, 5, 3, 0.36);
  transform: translateX(2px);
}

.mode-card.is-active {
  border-color: rgba(214, 179, 106, 0.46);
  background:
    linear-gradient(105deg, rgba(214, 179, 106, 0.13), rgba(214, 179, 106, 0.025)),
    rgba(7, 5, 3, 0.25);
  box-shadow: inset 3px 0 0 var(--gold);
}

.mode-icon {
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--gold);
  background: rgba(214, 179, 106, 0.035);
}

.mode-icon svg {
  width: 20px;
  height: 20px;
}

.mode-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding-right: 22px;
}

.mode-copy strong {
  color: var(--cream);
  font-size: calc(11.5px * var(--text-scale));
  font-weight: 700;
  line-height: 1.25;
}

.mode-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: calc(9px * var(--text-scale));
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-tick {
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%) scale(0.8);
  border-radius: 50%;
  color: #1a120b;
  background: linear-gradient(145deg, #f3d58e, #d6b36a);
  font-size: calc(9px * var(--text-scale));
  font-weight: 900;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms var(--ease);
}

.mode-card.is-active .mode-tick {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.assist-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.assist-copy {
  min-width: 0;
}

.assist-panel .panel-heading p {
  max-width: 232px;
}

.switch {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  cursor: pointer;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 45px;
  height: 25px;
  padding: 3px;
  display: block;
  position: relative;
  border: 1px solid rgba(214, 179, 106, 0.24);
  border-radius: 999px;
  background: rgba(7, 5, 3, 0.45);
  transition: background 220ms ease, border-color 220ms ease;
}

.switch-knob {
  width: 17px;
  height: 17px;
  display: block;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 240ms var(--ease), background 220ms ease, box-shadow 220ms ease;
}

.switch input:checked + .switch-track {
  border-color: rgba(111, 224, 160, 0.42);
  background: rgba(31, 122, 77, 0.32);
}

.switch input:checked + .switch-track .switch-knob {
  transform: translateX(20px);
  background: var(--green);
  box-shadow: 0 0 12px rgba(111, 224, 160, 0.42);
}

.record-panel {
  min-height: 0;
}

.record-heading {
  align-items: center;
}

.record-heading > span:nth-child(2) {
  flex: 1;
}

.record-heading-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.record-replay {
  min-height: 23px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(214, 179, 106, 0.26);
  border-radius: 999px;
  color: var(--gold);
  background: rgba(214, 179, 106, 0.06);
  font-family: var(--font-ui);
  font-size: calc(8px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}

.record-replay:hover:not(:disabled) {
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.5);
  background: rgba(214, 179, 106, 0.12);
}

.record-replay:disabled {
  opacity: 0.42;
  cursor: default;
}

.record-replay[hidden] {
  display: none;
}

.record-count {
  min-width: 24px;
  height: 21px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: calc(8.5px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.04em;
}

.move-list {
  height: 142px;
  padding: 4px 3px 4px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(214, 179, 106, 0.28) transparent;
  scrollbar-width: thin;
}

.move-list::-webkit-scrollbar,
.modal-scroll::-webkit-scrollbar {
  width: 6px;
}

.move-list::-webkit-scrollbar-thumb,
.modal-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(214, 179, 106, 0.23);
}

.move-list::-webkit-scrollbar-track,
.modal-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.move-empty {
  margin: 6px 2px;
  color: var(--faint);
  font-size: calc(10px * var(--text-scale));
  font-style: italic;
  line-height: 1.5;
}

.move-row {
  min-height: 26px;
  padding: 4px 6px;
  display: grid;
  grid-template-columns: 25px 10px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid rgba(214, 179, 106, 0.06);
  border-radius: 5px;
  animation: moveIn 320ms var(--ease);
}

.move-row:last-child {
  border-bottom: 0;
}

.move-row.is-last {
  background: rgba(214, 179, 106, 0.055);
}

@keyframes moveIn {
  from { transform: translateY(4px); }
  to { transform: translateY(0); }
}

.move-no {
  color: var(--faint);
  font-size: calc(8.5px * var(--text-scale));
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.move-stone {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff8e9, #bea06a);
  box-shadow: 0 0 0 1px rgba(255, 245, 215, 0.12);
}

.move-stone.is-black {
  background: linear-gradient(145deg, #4d3a2a, #120c08);
  box-shadow: 0 0 0 1px rgba(214, 179, 106, 0.12);
}

html[data-piece-finish="ruby"] .move-stone.is-black {
  background: linear-gradient(145deg, #ff9b86, #b4232c);
  box-shadow: 0 0 0 1px rgba(255, 170, 156, 0.24);
}

.move-text {
  min-width: 0;
  overflow: hidden;
  color: var(--cream-dim);
  font-size: calc(9.5px * var(--text-scale));
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-text .move-capture {
  color: var(--red);
  font-weight: 800;
}

.move-text .move-check {
  color: var(--gold-bright);
  font-weight: 800;
}

.record-foot {
  padding-top: 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-top: 1px solid rgba(214, 179, 106, 0.08);
  color: var(--faint);
  font-size: calc(8.5px * var(--text-scale));
  font-weight: 600;
  letter-spacing: 0.04em;
}

.record-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 7px rgba(111, 224, 160, 0.65);
}

.record-status-dot.is-warning {
  background: var(--red);
  box-shadow: 0 0 7px rgba(255, 120, 102, 0.6);
}

.record-status-dot.is-idle {
  background: var(--faint);
  box-shadow: none;
}

.actions-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.button-new {
  width: 100%;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-grid .button {
  min-height: 39px;
  padding-inline: 8px;
  font-size: calc(10px * var(--text-scale));
}

.display-entry {
  width: 100%;
  justify-content: flex-start;
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.28);
  background:
    linear-gradient(105deg, rgba(214, 179, 106, 0.1), rgba(214, 179, 106, 0.015)),
    rgba(8, 5, 3, 0.26);
}

.display-entry:hover {
  border-color: rgba(214, 179, 106, 0.5);
  background:
    linear-gradient(105deg, rgba(214, 179, 106, 0.17), rgba(214, 179, 106, 0.03)),
    rgba(8, 5, 3, 0.38);
}

.display-entry .display-entry-arrow {
  margin-left: auto;
  transition: transform 180ms ease;
}

.display-entry:hover .display-entry-arrow {
  transform: translateX(3px);
}

.replay-entry {
  width: 100%;
  justify-content: flex-start;
  color: var(--gold);
  border-color: rgba(214, 179, 106, 0.22);
  background: rgba(8, 5, 3, 0.24);
}

.replay-entry:hover {
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.44);
  background: rgba(8, 5, 3, 0.38);
}

.text-button {
  min-height: 30px;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 0;
  color: var(--gold);
  background: transparent;
  font-size: calc(9.5px * var(--text-scale));
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: color 180ms ease;
}

.text-button span:last-child {
  margin-left: auto;
  transition: transform 180ms ease;
}

.text-button:hover {
  color: var(--gold-bright);
}

.text-button:hover span:last-child {
  transform: translateX(3px);
}

.wisdom-panel {
  position: relative;
  padding: 17px 18px 16px 44px;
  overflow: hidden;
  border-color: rgba(214, 179, 106, 0.11);
  background: linear-gradient(155deg, rgba(29, 19, 12, 0.43), rgba(12, 8, 5, 0.46));
}

.wisdom-panel::after {
  content: "";
  position: absolute;
  right: -18px;
  bottom: -34px;
  width: 105px;
  height: 105px;
  border: 1px solid rgba(214, 179, 106, 0.08);
  border-radius: 50%;
  box-shadow: 0 0 0 12px rgba(214, 179, 106, 0.02), 0 0 0 24px rgba(214, 179, 106, 0.015);
  pointer-events: none;
}

.wisdom-mark {
  position: absolute;
  top: 7px;
  left: 15px;
  color: rgba(214, 179, 106, 0.34);
  font-family: var(--font-display);
  font-size: calc(41px * var(--text-scale));
  line-height: 1;
}

.wisdom-panel p {
  position: relative;
  z-index: 1;
  margin: 0;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: calc(13.5px * var(--text-scale));
  font-style: italic;
  line-height: 1.42;
}

.wisdom-source {
  display: block;
  margin-top: 7px;
  position: relative;
  z-index: 1;
  color: var(--faint);
  font-size: calc(8px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

/* ----------------------------- Footer ----------------------------- */

.footer {
  padding: 2px 6px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--faint);
  font-size: calc(8.5px * var(--text-scale));
  font-weight: 500;
  letter-spacing: 0.045em;
}

.footer-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(214, 179, 106, 0.38);
}

/* ----------------------------- Modals ----------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(29, 19, 12, 0.44), rgba(3, 2, 1, 0.86)),
    rgba(3, 2, 1, 0.68);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  animation: fadeIn 220ms ease;
}

.modal-panel {
  width: min(100%, 760px);
  max-height: min(88vh, 900px);
  padding: 30px;
  position: relative;
  z-index: 1;
  overflow: hidden;
  border: 1px solid rgba(214, 179, 106, 0.29);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(155deg, rgba(47, 31, 19, 0.97), rgba(14, 10, 7, 0.98)),
    radial-gradient(circle at 10% 0%, rgba(214, 179, 106, 0.1), transparent 38%);
  box-shadow: var(--shadow-xl), inset 0 1px 0 rgba(255, 244, 218, 0.07);
  animation: modalIn 340ms var(--ease);
}

.modal-panel::before {
  content: "";
  position: absolute;
  inset: 9px;
  pointer-events: none;
  border: 1px solid rgba(214, 179, 106, 0.09);
  border-radius: calc(var(--radius-xl) - 8px);
}

@keyframes fadeIn {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

@keyframes modalIn {
  /* Keep opacity at 1 throughout: a modal must remain readable even if a
     browser or capture engine freezes CSS animations before the first frame. */
  from { transform: translateY(18px) scale(0.975); }
  to { transform: translateY(0) scale(1); }
}

.modal-close {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 4;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: rgba(7, 5, 3, 0.25);
  font-size: calc(20px * var(--text-scale));
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.modal-close:hover {
  color: var(--gold-bright);
  border-color: var(--line-strong);
  background: rgba(7, 5, 3, 0.5);
  transform: rotate(90deg);
}

.glossary-modal-panel {
  width: min(100%, 1080px);
  height: min(90vh, 930px);
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 0 52px 17px 2px;
  flex: 0 0 auto;
  border-bottom: 1px solid rgba(214, 179, 106, 0.11);
}

.modal-head h2 {
  margin: 4px 0 3px;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 46px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
}

.modal-head p {
  margin: 0;
  color: var(--muted);
  font-size: calc(11px * var(--text-scale));
}

.modal-scroll {
  min-height: 0;
  padding: 19px 4px 2px 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(214, 179, 106, 0.28) transparent;
  scrollbar-width: thin;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.glossary-card {
  min-height: 170px;
  padding: 14px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 12px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(214, 179, 106, 0.13);
  border-radius: var(--radius-md);
  background:
    linear-gradient(145deg, rgba(214, 179, 106, 0.055), transparent 52%),
    rgba(7, 5, 3, 0.18);
  transition: border-color 180ms ease, transform 220ms var(--ease), background 180ms ease;
}

.glossary-card:hover {
  border-color: rgba(214, 179, 106, 0.29);
  background:
    linear-gradient(145deg, rgba(214, 179, 106, 0.09), transparent 52%),
    rgba(7, 5, 3, 0.25);
  transform: translateY(-2px);
}

.glossary-card::after {
  content: "";
  position: absolute;
  right: -22px;
  bottom: -29px;
  width: 82px;
  height: 82px;
  border: 1px solid rgba(214, 179, 106, 0.07);
  border-radius: 50%;
}

.glossary-glyph {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.26);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: calc(30px * var(--text-scale));
  line-height: 1;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 242, 205, 0.12), transparent 50%),
    rgba(7, 5, 3, 0.22);
  box-shadow: inset 0 0 0 5px rgba(214, 179, 106, 0.025);
}

.glossary-body {
  min-width: 0;
}

.glossary-names {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 9px;
  padding-right: 6px;
}

.glossary-names strong {
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(21px * var(--text-scale));
  font-weight: 600;
  line-height: 1;
}

.glossary-names .thai-name {
  color: var(--gold);
  font-family: var(--font-thai);
  font-size: calc(13px * var(--text-scale));
}

.glossary-phonetic {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-size: calc(8px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.glossary-lore {
  margin: 8px 0 7px;
  color: var(--cream-dim);
  font-size: calc(10px * var(--text-scale));
  line-height: 1.48;
}

.glossary-move {
  margin: 0;
  padding-top: 7px;
  border-top: 1px solid rgba(214, 179, 106, 0.09);
  color: var(--muted);
  font-size: calc(9px * var(--text-scale));
  line-height: 1.45;
}

.glossary-move b {
  color: var(--gold);
  font-weight: 700;
}

.glossary-model {
  display: block;
  margin-top: 4px;
  color: var(--faint);
  font-size: calc(8.5px * var(--text-scale));
  font-style: italic;
  line-height: 1.4;
}

.rules-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(214, 179, 106, 0.11);
}

.rules-heading {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-bottom: 12px;
}

.rules-heading h3 {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(25px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.rules-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: calc(10px * var(--text-scale));
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.rule-card {
  min-height: 96px;
  padding: 12px;
  border: 1px solid rgba(214, 179, 106, 0.12);
  border-radius: var(--radius-sm);
  background: rgba(7, 5, 3, 0.18);
}

.rule-card span {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: calc(17px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.rule-card p {
  margin: 0;
  color: var(--muted);
  font-size: calc(9px * var(--text-scale));
  line-height: 1.5;
}

.heritage-strip {
  margin: 18px 0 2px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid rgba(214, 179, 106, 0.16);
  border-radius: var(--radius-md);
  background:
    radial-gradient(circle at 8% 50%, rgba(214, 179, 106, 0.09), transparent 24%),
    rgba(7, 5, 3, 0.18);
}

.heritage-seal {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.27);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: var(--font-thai);
  font-size: calc(22px * var(--text-scale));
  box-shadow: inset 0 0 0 5px rgba(214, 179, 106, 0.025);
}

.heritage-strip strong {
  display: block;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(18px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.heritage-strip p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: calc(9.5px * var(--text-scale));
  line-height: 1.5;
}

/* Result modal */

.result-panel {
  width: min(100%, 480px);
  padding: 42px 34px 30px;
  text-align: center;
}

.result-emblem {
  width: 84px;
  height: 84px;
  margin: 0 auto 15px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.3);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: calc(45px * var(--text-scale));
  line-height: 1;
  background:
    radial-gradient(circle at 36% 30%, rgba(255, 241, 203, 0.14), transparent 45%),
    rgba(7, 5, 3, 0.28);
  box-shadow: inset 0 0 0 8px rgba(214, 179, 106, 0.035), 0 0 40px rgba(214, 179, 106, 0.09);
}

.result-panel h2 {
  margin: 7px 0 6px;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(43px * var(--text-scale));
  font-weight: 500;
  line-height: 1;
}

.result-panel > p {
  margin: 0 auto;
  max-width: 330px;
  color: var(--muted);
  font-size: calc(11px * var(--text-scale));
  line-height: 1.55;
}

.result-actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
}

.result-credit {
  margin-top: 17px !important;
  color: var(--faint) !important;
  font-size: 8.5px !important;
  font-style: italic;
}

.button-review {
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.38);
  background: rgba(214, 179, 106, 0.08);
}

.button-review:hover {
  border-color: rgba(214, 179, 106, 0.6);
  background: rgba(214, 179, 106, 0.14);
}

/* Display preferences */

.display-panel {
  width: min(100%, 840px);
  max-height: min(92vh, 840px);
  overflow-y: auto;
  scrollbar-color: rgba(214, 179, 106, 0.28) transparent;
  scrollbar-width: thin;
}

.display-panel::-webkit-scrollbar {
  width: 6px;
}

.display-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(214, 179, 106, 0.23);
}

.display-head {
  padding-bottom: 14px;
}

.display-head h2 {
  font-size: clamp(30px, 3.5vw, 43px);
}

.display-body {
  padding: 18px 2px 3px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 26px;
  align-items: start;
}

.display-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.display-section h3 {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(24px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.display-section > p {
  margin: 4px 0 13px;
  color: var(--muted);
  font-size: calc(10px * var(--text-scale));
  line-height: 1.5;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.theme-card {
  min-height: 90px;
  padding: 10px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  position: relative;
  border: 1px solid rgba(214, 179, 106, 0.14);
  border-radius: 10px;
  color: var(--cream);
  background: rgba(7, 5, 3, 0.2);
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms var(--ease);
}

.theme-card:hover {
  border-color: rgba(214, 179, 106, 0.34);
  background: rgba(7, 5, 3, 0.32);
  transform: translateY(-1px);
}

.theme-card.is-active {
  border-color: rgba(214, 179, 106, 0.56);
  box-shadow: inset 0 0 0 1px rgba(214, 179, 106, 0.16);
}

.theme-preview {
  width: 39px;
  height: 59px;
  flex: 0 0 39px;
  display: grid;
  grid-template-rows: 1fr 1.5fr 0.55fr;
  overflow: hidden;
  border: 1px solid rgba(255, 244, 218, 0.14);
  border-radius: 6px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.theme-preview i {
  display: block;
}

.theme-preview.is-lacquer {
  background: linear-gradient(180deg, #120c08 0 33%, #6d4528 33% 82%, #d1a84c 82%);
}

.theme-preview.is-ivory {
  background: linear-gradient(180deg, #f4ead4 0 33%, #b58a5c 33% 82%, #8f6727 82%);
}

.theme-preview.is-jade {
  background: linear-gradient(180deg, #07130e 0 33%, #3d6a55 33% 82%, #d1b66d 82%);
}

.theme-preview.is-ruby {
  background: linear-gradient(180deg, #16080b 0 33%, #6d3039 33% 82%, #d1a84c 82%);
}

.theme-card-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 12px;
}

.theme-card-copy strong {
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(16px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.theme-card-copy small {
  color: var(--muted);
  font-size: calc(8px * var(--text-scale));
  line-height: 1.4;
}

.theme-check {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  position: absolute;
  top: 8px;
  right: 8px;
  border-radius: 50%;
  color: #1b120a;
  background: linear-gradient(145deg, #f3d58e, #d6b36a);
  font-size: calc(8px * var(--text-scale));
  font-weight: 900;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 180ms ease, transform 180ms var(--ease);
}

.theme-card.is-active .theme-check {
  opacity: 1;
  transform: scale(1);
}

.board-style-control,
.board-material-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.board-material-option {
  min-height: 73px;
  padding: 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  position: relative;
  border: 1px solid rgba(214, 179, 106, 0.14);
  border-radius: 10px;
  color: var(--cream);
  background: rgba(7, 5, 3, 0.2);
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms var(--ease);
}

.board-material-option:hover {
  border-color: rgba(214, 179, 106, 0.34);
  background: rgba(7, 5, 3, 0.32);
  transform: translateY(-1px);
}

.board-material-option.is-active {
  border-color: rgba(214, 179, 106, 0.56);
  box-shadow: inset 0 0 0 1px rgba(214, 179, 106, 0.16);
}

.board-material-preview {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  overflow: hidden;
  border: 1px solid rgba(255, 244, 218, 0.15);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  padding: 2px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.board-material-preview i {
  border-radius: 3px;
}

.board-material-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 10px;
}

.board-material-copy strong {
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(15px * var(--text-scale));
  font-weight: 600;
  line-height: 1.1;
}

.board-material-copy small {
  color: var(--muted);
  font-size: calc(8px * var(--text-scale));
  line-height: 1.4;
}

.stage-color-control {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.stage-color-option {
  width: 34px;
  height: 34px;
  padding: 3px;
  position: relative;
  border: 1px solid rgba(214, 179, 106, 0.2);
  border-radius: 50%;
  background: rgba(7, 5, 3, 0.2);
  cursor: pointer;
  transition: border-color 180ms ease, transform 180ms var(--ease), box-shadow 180ms ease;
}

.stage-color-option:hover {
  border-color: rgba(214, 179, 106, 0.5);
  transform: translateY(-1px);
}

.stage-color-option.is-active {
  border-color: #f3d58e;
  box-shadow: 0 0 0 2px rgba(243, 213, 142, 0.18);
}

.stage-color-swatch {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.stage-color-swatch.is-auto {
  background: conic-gradient(from 20deg, #0a0705, #6c5845, #d6b36a, #0a0705);
}

.stage-color-option.is-active::after {
  content: "✓";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 13px;
  height: 13px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(13, 9, 6, 0.3);
  border-radius: 50%;
  color: #1b120a;
  background: linear-gradient(145deg, #f3d58e, #d6b36a);
  font-size: calc(7px * var(--text-scale));
  font-weight: 900;
  line-height: 1;
}

.stage-color-custom {
  margin-top: 9px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(214, 179, 106, 0.13);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(7, 5, 3, 0.16);
  font-size: calc(9px * var(--text-scale));
  font-weight: 600;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.stage-color-custom.is-active {
  border-color: rgba(214, 179, 106, 0.56);
  box-shadow: inset 0 0 0 1px rgba(214, 179, 106, 0.14);
}

.stage-color-custom label {
  cursor: pointer;
}

.stage-color-custom input[type="color"] {
  width: 34px;
  height: 25px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(214, 179, 106, 0.25);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.stage-color-custom input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.stage-color-custom input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 3px;
}

.stage-color-custom span:last-child {
  margin-left: auto;
  color: var(--faint);
  font-size: calc(8px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.04em;
}

.board-style-option {
  min-height: 75px;
  padding: 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  position: relative;
  border: 1px solid rgba(214, 179, 106, 0.14);
  border-radius: 10px;
  color: var(--cream);
  background: rgba(7, 5, 3, 0.2);
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms var(--ease);
}

.board-style-option:hover {
  border-color: rgba(214, 179, 106, 0.34);
  background: rgba(7, 5, 3, 0.32);
  transform: translateY(-1px);
}

.board-style-option.is-active {
  border-color: rgba(214, 179, 106, 0.56);
  box-shadow: inset 0 0 0 1px rgba(214, 179, 106, 0.16);
}

.board-preview {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  border: 1px solid rgba(255, 244, 218, 0.15);
  border-radius: 6px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.board-preview.is-traditional {
  background-color: #7f5532;
  background-image:
    linear-gradient(rgba(24, 12, 6, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 12, 6, 0.28) 1px, transparent 1px);
  background-size: 14px 14px;
}

.board-preview.is-checkered {
  background: repeating-conic-gradient(#c29a67 0 25%, #4c3120 0 50%) 0 0 / 21.5px 21.5px;
}

.piece-set-preview {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 244, 218, 0.15);
  border-radius: 6px;
  color: #f4e7cc;
  background:
    radial-gradient(circle at 50% 88%, rgba(35, 76, 62, 0.62), transparent 66%),
    linear-gradient(150deg, rgba(255, 244, 218, 0.1), rgba(0, 0, 0, 0.38));
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.piece-set-preview svg {
  width: 31px;
  height: 31px;
  display: block;
}

.piece-set-preview.is-tournament {
  color: #f0c97e;
  background:
    radial-gradient(circle at 50% 88%, rgba(120, 82, 28, 0.5), transparent 66%),
    linear-gradient(150deg, rgba(255, 244, 218, 0.14), rgba(0, 0, 0, 0.42));
}

.piece-set-preview.is-sigil {
  color: #f7dfa6;
  background:
    radial-gradient(circle at 50% 50%, rgba(180, 35, 44, 0.3), transparent 58%),
    linear-gradient(150deg, rgba(24, 16, 10, 0.9), rgba(0, 0, 0, 0.6));
}

.piece-set-preview.is-monolith {
  color: #d7ddd9;
  background:
    radial-gradient(circle at 50% 80%, rgba(45, 76, 66, 0.6), transparent 68%),
    linear-gradient(150deg, rgba(255, 244, 218, 0.12), rgba(0, 0, 0, 0.44));
}

.piece-finish-preview {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid rgba(255, 244, 218, 0.15);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.finish-swatch {
  display: flex;
  gap: 2px;
}

.finish-swatch i {
  width: 12px;
  height: 28px;
  display: block;
  border-radius: 7px 7px 2px 2px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.24);
}

.board-style-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 10px;
}

.board-style-copy strong {
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.1;
}

.board-style-copy small {
  color: var(--muted);
  font-size: 8px;
  line-height: 1.4;
}

.text-size-control {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.text-size-option {
  min-height: 69px;
  padding: 7px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid rgba(214, 179, 106, 0.14);
  border-radius: 9px;
  color: var(--muted);
  background: rgba(7, 5, 3, 0.2);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, color 180ms ease;
}

.text-size-option:hover {
  color: var(--gold-bright);
  border-color: rgba(214, 179, 106, 0.34);
  background: rgba(7, 5, 3, 0.32);
}

.text-size-option.is-active {
  color: var(--cream);
  border-color: rgba(214, 179, 106, 0.56);
  background: rgba(214, 179, 106, 0.1);
  box-shadow: inset 0 0 0 1px rgba(214, 179, 106, 0.12);
}

.size-glyph {
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1;
}

.text-size-option[data-text-choice="small"] .size-glyph {
  font-size: calc(16px * var(--text-scale));
}

.text-size-option[data-text-choice="medium"] .size-glyph {
  font-size: calc(19px * var(--text-scale));
}

.text-size-option[data-text-choice="large"] .size-glyph {
  font-size: calc(22px * var(--text-scale));
}

.text-size-option[data-text-choice="xlarge"] .size-glyph {
  font-size: calc(25px * var(--text-scale));
}

.text-size-option small {
  color: inherit;
  font-size: calc(7.5px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.25;
  text-align: center;
}

.text-size-option em {
  color: var(--faint);
  font-size: calc(7px * var(--text-scale));
  font-style: normal;
  font-weight: 700;
}

.reading-preview {
  min-height: 112px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(214, 179, 106, 0.13);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(214, 179, 106, 0.055), transparent 60%),
    rgba(7, 5, 3, 0.18);
}

.reading-preview p {
  margin: 7px 0 0;
  color: var(--cream-dim);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.55;
}

.display-note {
  margin: 10px 0 0 !important;
  color: var(--faint) !important;
  font-size: 8px !important;
  font-style: italic;
}

.display-actions {
  margin-top: 14px;
  padding-top: 15px;
  border-top: 1px solid rgba(214, 179, 106, 0.11);
}

/* Stalemate review */

.stalemate-panel {
  width: min(100%, 940px);
  max-height: min(92vh, 820px);
  overflow-y: auto;
  scrollbar-color: rgba(214, 179, 106, 0.28) transparent;
  scrollbar-width: thin;
}

.stalemate-panel::-webkit-scrollbar {
  width: 6px;
}

.stalemate-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(214, 179, 106, 0.23);
}

.stalemate-head {
  padding-bottom: 14px;
}

.stalemate-head h2 {
  font-size: clamp(29px, 3.4vw, 42px);
}

.stalemate-body {
  padding: 18px 2px 3px;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.mini-board-column {
  min-width: 0;
}

.mini-board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border: 1px solid rgba(214, 179, 106, 0.32);
  border-radius: 12px;
  background: #55351f;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35), inset 0 0 0 4px rgba(8, 5, 3, 0.35);
}

.mini-square {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(40, 22, 10, 0.25);
  border-bottom: 1px solid rgba(40, 22, 10, 0.25);
  background: #b28a5d;
  color: #f5e9cf;
  line-height: 1;
}

.mini-square.is-alt {
  background: #a98054;
}

.mini-square.is-king {
  background: rgba(224, 187, 105, 0.82);
  box-shadow: inset 0 0 0 2px #f6dc98;
}

.mini-square.is-escape {
  background:
    linear-gradient(135deg, rgba(255, 93, 73, 0.62), rgba(138, 34, 27, 0.72)),
    #8f4f3b;
}

.mini-square.is-blocked {
  background:
    linear-gradient(135deg, rgba(80, 65, 49, 0.72), rgba(39, 29, 21, 0.84)),
    #5f4936;
}

.mini-square.is-last-from {
  box-shadow: inset 0 0 0 2px rgba(111, 224, 160, 0.8);
}

.mini-square.is-last-to {
  box-shadow: inset 0 0 0 2px #f3d58e;
}

.mini-square.is-king.is-last-to {
  box-shadow: inset 0 0 0 2px #f6dc98, inset 0 0 0 4px rgba(13, 9, 6, 0.35);
}

.mini-piece {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: clamp(18px, 3.1vw, 29px);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.32);
}

.mini-piece.is-black {
  color: #1b100a;
  text-shadow: 0 1px 0 rgba(255, 245, 219, 0.35);
}

html[data-piece-finish="ruby"] .mini-piece.is-black {
  color: #d23d43;
  text-shadow: 0 1px 0 rgba(255, 225, 214, 0.35);
}

.mini-piece.is-white {
  color: #fff5de;
  text-shadow: 0 1px 2px rgba(34, 19, 10, 0.6);
}

.mini-coord {
  position: absolute;
  right: 3px;
  bottom: 2px;
  z-index: 2;
  color: rgba(255, 248, 231, 0.74);
  font-family: var(--font-body);
  font-size: clamp(5px, 0.66vw, 8px);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.mini-square.is-escape::before,
.mini-square.is-blocked::before {
  content: "×";
  position: absolute;
  z-index: 2;
  color: rgba(255, 242, 221, 0.92);
  font-family: var(--font-body);
  font-size: clamp(13px, 2vw, 20px);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.mini-square.is-escape .mini-coord,
.mini-square.is-blocked .mini-coord {
  color: #fff5e3;
}

.mini-legend {
  padding: 11px 2px 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 13px;
  color: var(--faint);
  font-size: calc(8.5px * var(--text-scale));
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.mini-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 2px;
  border: 1px solid rgba(255, 245, 220, 0.2);
}

.legend-king {
  background: #e0bb69;
}

.legend-escape {
  background: #b24a3a;
}

.legend-move {
  background: transparent;
  border: 1px solid #f3d58e;
}

.stalemate-explain {
  min-width: 0;
  padding-top: 1px;
}

.stalemate-status {
  padding: 13px 15px;
  border: 1px solid rgba(111, 224, 160, 0.25);
  border-radius: 12px;
  color: var(--cream-dim);
  background:
    linear-gradient(110deg, rgba(60, 119, 83, 0.19), rgba(7, 5, 3, 0.16)),
    rgba(7, 5, 3, 0.17);
  font-size: calc(11.5px * var(--text-scale));
  line-height: 1.5;
}

.stalemate-status strong {
  color: var(--green);
  font-weight: 800;
}

.stalemate-last-move {
  margin: 10px 0 16px;
  color: var(--muted);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.45;
}

.stalemate-last-move strong {
  color: var(--gold);
}

.stalemate-cause {
  margin: -7px 0 16px;
  color: var(--cream-dim);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.55;
}

.stalemate-explain h3 {
  margin: 0 0 8px;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: calc(23px * var(--text-scale));
  font-weight: 600;
  line-height: 1.15;
}

.escape-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  list-style: none;
}

.escape-list li {
  min-height: 35px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(214, 179, 106, 0.11);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(7, 5, 3, 0.16);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.4;
}

.escape-square {
  width: 27px;
  height: 23px;
  flex: 0 0 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 120, 102, 0.35);
  border-radius: 5px;
  color: #ffb4a8;
  background: rgba(158, 56, 43, 0.2);
  font-size: calc(8.5px * var(--text-scale));
  font-weight: 800;
  letter-spacing: 0.04em;
}

.escape-list li.is-blocked .escape-square {
  color: var(--faint);
  border-color: var(--line);
  background: rgba(7, 5, 3, 0.25);
}

.escape-list li strong {
  color: var(--cream-dim);
  font-weight: 700;
}

.escape-list li em {
  color: var(--faint);
  font-style: normal;
}

.rule-note {
  margin-top: 15px;
  padding: 12px 14px;
  border: 1px solid rgba(214, 179, 106, 0.2);
  border-radius: 10px;
  color: var(--cream-dim);
  background:
    linear-gradient(110deg, rgba(214, 179, 106, 0.09), transparent),
    rgba(7, 5, 3, 0.16);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.55;
}

.rule-note strong {
  color: var(--gold-bright);
}

.stalemate-actions {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid rgba(214, 179, 106, 0.11);
}

/* ----------------------------- Toasts ----------------------------- */

.toast-stack {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(360px, calc(100vw - 44px));
  padding: 11px 14px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  border: 1px solid rgba(214, 179, 106, 0.26);
  border-radius: 12px;
  color: var(--cream-dim);
  background: rgba(20, 13, 8, 0.94);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 244, 218, 0.06);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: calc(10.5px * var(--text-scale));
  line-height: 1.45;
  animation: toastIn 300ms var(--ease);
}

.toast.is-leaving {
  animation: toastOut 240ms ease forwards;
}

.toast-icon {
  color: var(--gold);
  font-size: calc(13px * var(--text-scale));
  line-height: 1.25;
}

.toast.is-error {
  border-color: rgba(255, 120, 102, 0.36);
}

.toast.is-error .toast-icon {
  color: var(--red);
}

.toast.is-success {
  border-color: rgba(111, 224, 160, 0.32);
}

.toast.is-success .toast-icon {
  color: var(--green);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(8px); }
}

.noscript-note {
  position: fixed;
  inset: auto 20px 20px;
  padding: 14px;
  z-index: 300;
  border: 1px solid var(--red);
  border-radius: 10px;
  color: var(--cream);
  background: var(--panel-solid);
  text-align: center;
}

/* ----------------------------- Responsive ----------------------------- */

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 330px;
  }

  .brand-subtitle {
    max-width: 270px;
  }

  .icon-label {
    display: none;
  }

  .icon-button {
    width: 42px;
    padding: 0;
    justify-content: center;
  }
}

@media (max-width: 1080px) {
  .app-shell {
    padding-inline: 18px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .record-panel,
  .wisdom-panel {
    grid-column: span 1;
  }

  .board-stage {
    height: clamp(460px, 70vh, 780px);
  }

  .brand-subtitle {
    max-width: 350px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 12px 12px 14px;
    gap: 13px;
  }

  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .brand-seal {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .brand-seal span {
    font-size: calc(20px * var(--text-scale));
  }

  .brand-line {
    display: block;
  }

  .brand-line strong {
    display: block;
    font-size: calc(26px * var(--text-scale));
  }

  .brand-subtitle {
    display: block;
    max-width: 230px;
    margin-top: 2px;
    font-size: calc(9px * var(--text-scale));
  }

  .brand-copy > .eyebrow {
    display: none;
  }

  .button-rules {
    width: 42px;
    padding: 0;
    font-size: 0;
  }

  .button-rules .button-icon {
    font-size: calc(14px * var(--text-scale));
  }

  .workspace {
    gap: 13px;
  }

  .arena {
    padding: 10px;
  }

  .arena-head {
    padding: 0 2px;
  }

  .board-stage {
    height: clamp(370px, 52vh, 580px);
    min-height: 370px;
  }

  .tutor-content {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .tutor-movement {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 8px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .tutor-stats {
    grid-row: 1;
    grid-column: 2;
  }

  .tutor-stat {
    min-width: 46px;
    padding-inline: 6px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .move-list {
    height: 112px;
  }

  .glossary-grid {
    grid-template-columns: 1fr;
  }

  .stalemate-body {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .display-body {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .mini-board-column {
    width: min(100%, 340px);
    margin: 0 auto;
  }

  .mini-legend {
    justify-content: center;
  }

  .rules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal {
    padding: 10px;
  }

  .glossary-modal-panel {
    height: calc(100vh - 20px);
    padding: 23px 18px 18px;
  }

  .modal-panel {
    padding: 24px 18px 18px;
  }

  .modal-close {
    top: 12px;
    right: 12px;
  }

  .modal-head {
    padding-right: 40px;
  }
}

@media (max-width: 540px) {
  .top-actions {
    gap: 6px;
  }

  .lang-toggle {
    height: 38px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .button {
    min-height: 38px;
  }

  .brand-subtitle {
    max-width: 155px;
  }

  .brand-line strong {
    font-size: calc(23px * var(--text-scale));
  }

  .board-stage {
    height: 50vh;
    min-height: 320px;
  }

  .stage-toolbar {
    top: 11px;
    left: 11px;
    right: 11px;
  }

  .stage-button span:last-child {
    display: none;
  }

  #displayButtonStage {
    width: auto;
    padding-inline: 11px;
  }

  #displayButtonStage span:last-child {
    display: inline;
  }

  #topViewToggle {
    width: auto;
    padding-inline: 11px;
  }

  #topViewToggle span:last-child {
    display: inline;
  }

  .assist-pill {
    padding-inline: 8px;
  }

  .tutor {
    padding: 11px;
  }

  .tutor-empty small {
    font-size: calc(9.5px * var(--text-scale));
  }

  .tutor-piece-icon {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: calc(22px * var(--text-scale));
  }

  .tutor-name strong {
    font-size: calc(18px * var(--text-scale));
  }

  .capture-label {
    display: none;
  }

  .capture-tray {
    justify-content: space-around;
  }

  .capture-pieces {
    font-size: calc(17px * var(--text-scale));
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .glossary-card {
    grid-template-columns: 44px minmax(0, 1fr);
    padding: 12px;
  }

  .glossary-glyph {
    width: 44px;
    height: 44px;
    font-size: calc(24px * var(--text-scale));
  }

  .glossary-names strong {
    font-size: calc(19px * var(--text-scale));
  }

  .result-panel h2 {
    font-size: calc(36px * var(--text-scale));
  }

  .stalemate-panel {
    padding: 23px 14px 16px;
  }

  .stalemate-head {
    padding-right: 38px;
  }

  .mini-board-column {
    width: min(100%, 260px);
  }

  .mini-piece {
    font-size: calc(18px * var(--text-scale));
  }

  .stalemate-actions .button {
    flex: 1 1 140px;
  }

  .display-panel {
    padding: 23px 14px 16px;
  }

  .display-head {
    padding-right: 38px;
  }

  .text-size-control {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast-stack {
    right: 12px;
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================
   Display themes
   ========================================================= */

html[data-theme="ivory"] {
  color-scheme: light;
  --bg-deep: #e8d7ba;
  --bg: #f3e8d3;
  --bg-soft: #fff8eb;
  --panel: rgba(255, 249, 237, 0.8);
  --panel-solid: #fff8eb;
  --panel-lift: rgba(246, 234, 214, 0.86);
  --line: rgba(98, 65, 29, 0.18);
  --line-strong: rgba(98, 65, 29, 0.38);
  --gold: #946720;
  --gold-bright: #805415;
  --gold-deep: #69430f;
  --cream: #2b1b10;
  --cream-dim: #4f3926;
  --muted: #725d48;
  --faint: #927c64;
  --green: #1f7a4d;
  --green-deep: #0d5632;
  --red: #b53d2e;
  --blue: #2d6a91;
  --shadow-xl: 0 40px 100px rgba(77, 51, 25, 0.24);
  --shadow-lg: 0 22px 56px rgba(77, 51, 25, 0.16);
  --shadow-md: 0 12px 30px rgba(77, 51, 25, 0.12);
  --theme-surface: linear-gradient(145deg, rgba(255, 251, 242, 0.93), rgba(243, 231, 209, 0.82));
  --theme-soft: rgba(255, 249, 237, 0.58);
  --theme-hover: rgba(224, 201, 164, 0.28);
  --theme-modal: linear-gradient(155deg, #fff9ee, #f1e3ca);
  --theme-toast: rgba(255, 249, 237, 0.97);
  --theme-emblem: radial-gradient(circle at 36% 30%, rgba(255, 255, 255, 0.7), transparent 48%), rgba(236, 216, 181, 0.5);
  --theme-backdrop: radial-gradient(circle at center, rgba(80, 53, 26, 0.25), rgba(31, 20, 10, 0.64));
}

html[data-theme="jade"] {
  --bg-deep: #030d09;
  --bg: #07170f;
  --bg-soft: #0a2015;
  --panel: rgba(11, 37, 26, 0.78);
  --panel-solid: #0b2117;
  --panel-lift: rgba(20, 60, 42, 0.68);
  --line: rgba(217, 190, 112, 0.17);
  --line-strong: rgba(217, 190, 112, 0.37);
  --gold: #d4b36a;
  --gold-bright: #f2d58e;
  --gold-deep: #a37b34;
  --cream: #f0ead8;
  --cream-dim: #d2c6a8;
  --muted: #9cae9d;
  --faint: #718778;
  --green: #71e2a6;
  --green-deep: #1b6846;
  --red: #ff8170;
  --blue: #8bc5e3;
  --shadow-xl: 0 40px 100px rgba(0, 0, 0, 0.56);
  --shadow-lg: 0 22px 56px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.28);
  --theme-surface: linear-gradient(155deg, rgba(18, 55, 38, 0.72), rgba(5, 20, 13, 0.74));
  --theme-soft: rgba(7, 25, 17, 0.35);
  --theme-hover: rgba(24, 74, 51, 0.55);
  --theme-modal: linear-gradient(155deg, #143b29, #07150f);
  --theme-toast: rgba(10, 34, 23, 0.96);
  --theme-emblem: radial-gradient(circle at 36% 30%, rgba(255, 246, 207, 0.12), transparent 47%), rgba(5, 22, 14, 0.35);
  --theme-backdrop: radial-gradient(circle at center, rgba(14, 53, 36, 0.35), rgba(2, 10, 6, 0.87));
}

html[data-theme="ruby"] {
  --bg-deep: #0f0407;
  --bg: #19070c;
  --bg-soft: #240b12;
  --panel: rgba(56, 16, 25, 0.76);
  --panel-solid: #250a11;
  --panel-lift: rgba(83, 26, 38, 0.64);
  --line: rgba(222, 181, 109, 0.18);
  --line-strong: rgba(222, 181, 109, 0.39);
  --gold: #d9b36c;
  --gold-bright: #f5d794;
  --gold-deep: #a67a31;
  --cream: #f5e7d8;
  --cream-dim: #dac0b2;
  --muted: #bd9b91;
  --faint: #8e6c68;
  --green: #73dca0;
  --green-deep: #1e6b48;
  --red: #ff8977;
  --blue: #93bfe0;
  --shadow-xl: 0 40px 100px rgba(0, 0, 0, 0.58);
  --shadow-lg: 0 22px 56px rgba(0, 0, 0, 0.42);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.3);
  --theme-surface: linear-gradient(155deg, rgba(78, 22, 34, 0.72), rgba(19, 6, 9, 0.76));
  --theme-soft: rgba(32, 8, 14, 0.36);
  --theme-hover: rgba(99, 31, 45, 0.52);
  --theme-modal: linear-gradient(155deg, #4b1722, #18070b);
  --theme-toast: rgba(42, 12, 19, 0.97);
  --theme-emblem: radial-gradient(circle at 36% 30%, rgba(255, 228, 190, 0.13), transparent 47%), rgba(38, 9, 15, 0.42);
  --theme-backdrop: radial-gradient(circle at center, rgba(93, 27, 42, 0.34), rgba(12, 3, 6, 0.88));
}

html[data-theme="ivory"] body {
  background:
    radial-gradient(ellipse at 12% -4%, rgba(184, 137, 65, 0.22), transparent 38%),
    radial-gradient(ellipse at 93% 76%, rgba(133, 78, 45, 0.13), transparent 43%),
    radial-gradient(ellipse at 50% 120%, rgba(173, 141, 90, 0.2), transparent 58%),
    linear-gradient(145deg, #ead9bb 0%, #f8efdf 46%, #e9d6b5 100%);
}

html[data-theme="jade"] body {
  background:
    radial-gradient(ellipse at 14% -5%, rgba(212, 179, 106, 0.13), transparent 36%),
    radial-gradient(ellipse at 92% 78%, rgba(29, 112, 74, 0.24), transparent 43%),
    radial-gradient(ellipse at 50% 120%, rgba(14, 68, 44, 0.26), transparent 58%),
    linear-gradient(145deg, #030d09 0%, #071a12 46%, #04100b 100%);
}

html[data-theme="ruby"] body {
  background:
    radial-gradient(ellipse at 14% -5%, rgba(222, 181, 109, 0.14), transparent 36%),
    radial-gradient(ellipse at 92% 78%, rgba(133, 35, 55, 0.24), transparent 43%),
    radial-gradient(ellipse at 50% 120%, rgba(86, 20, 33, 0.28), transparent 58%),
    linear-gradient(145deg, #0f0407 0%, #1b090e 46%, #100508 100%);
}

html:not([data-theme="lacquer"]) :is(.topbar, .arena, .panel, .tutor) {
  background: var(--theme-surface);
}

html:not([data-theme="lacquer"]) :is(
  .icon-button,
  .lang-toggle,
  .button-quiet,
  .chip,
  .mode-card,
  .theme-card,
  .board-style-option,
  .board-material-option,
  .bot-level-card,
  .stage-color-custom,
  .text-size-option,
  .reading-preview,
  .tutor-stat,
  .mode-icon,
  .tutor-glyph,
  .record-count,
  .switch-track,
  .glossary-card,
  .rule-card,
  .wisdom-panel,
  .heritage-strip
) {
  background: var(--theme-soft);
}

html:not([data-theme="lacquer"]) :is(
  .icon-button:hover,
  .lang-toggle:hover,
  .button-quiet:hover,
  .mode-card:hover,
  .theme-card:hover,
  .board-style-option:hover,
  .board-material-option:hover,
  .bot-level-card:hover,
  .text-size-option:hover
) {
  background: var(--theme-hover);
}

html:not([data-theme="lacquer"]) :is(
  .mode-card.is-active,
  .theme-card.is-active,
  .board-style-option.is-active,
  .board-material-option.is-active,
  .bot-level-card.is-active,
  .text-size-option.is-active
) {
  background:
    linear-gradient(105deg, rgba(214, 179, 106, 0.13), rgba(214, 179, 106, 0.025)),
    var(--theme-soft);
}

html:not([data-theme="lacquer"]) :is(.modal-panel) {
  background: var(--theme-modal);
}

html:not([data-theme="lacquer"]) .modal-backdrop {
  background: var(--theme-backdrop);
}

html:not([data-theme="lacquer"]) :is(.toast) {
  background: var(--theme-toast);
}

html:not([data-theme="lacquer"]) .result-emblem {
  background: var(--theme-emblem);
}

html[data-piece-finish="ruby"] .result-emblem[data-side="b"] {
  color: #e15a61;
  border-color: rgba(225, 90, 97, 0.4);
  box-shadow: inset 0 0 0 8px rgba(225, 90, 97, 0.05), 0 0 40px rgba(180, 35, 44, 0.16);
}

html[data-theme="ivory"] :is(.stage-button, .assist-pill) {
  color: #ddcba9;
  border-color: rgba(214, 179, 106, 0.22);
  background: rgba(10, 7, 4, 0.62);
}

html[data-theme="ivory"] .stage-button:hover {
  color: #f3d58e;
  background: rgba(10, 7, 4, 0.78);
}

html[data-theme="ivory"] :is(.scene-loader, .scene-fallback span) {
  color: #b9a78d;
}

html[data-theme="ivory"] :is(.scene-fallback strong, .brand-seal, .loader-mark) {
  color: #f3d58e;
}

html[data-theme="ivory"] .stalemate-status {
  border-color: rgba(31, 122, 77, 0.25);
  background: rgba(31, 122, 77, 0.08);
}

html[data-theme="ivory"] .escape-square {
  color: #fff4e5;
  border-color: #9f3d30;
  background: #a84536;
}

html[data-theme="ivory"] .escape-list li.is-blocked .escape-square {
  color: var(--cream-dim);
  border-color: rgba(98, 65, 29, 0.2);
  background: rgba(98, 65, 29, 0.08);
}

html[data-theme="ivory"] :is(.escape-list li, .rule-note, .move-row.is-last) {
  background: var(--theme-soft);
}

html[data-theme="ivory"] .display-note {
  color: var(--faint) !important;
}

html[data-theme="ivory"] .brand-seal::before,
html[data-theme="ivory"] .brand-seal::after {
  border-color: rgba(243, 213, 142, 0.28);
}

html[data-theme="ivory"] .wisdom-panel {
  border-color: rgba(98, 65, 29, 0.15);
}

html[data-theme="ivory"] .theme-card.is-active,
html[data-theme="ivory"] .text-size-option.is-active {
  background: rgba(148, 103, 32, 0.1);
}

html[data-theme="ivory"] .theme-preview {
  border-color: rgba(98, 65, 29, 0.2);
}


/* --------------------------------------------------------------------------
   Interactive glossary + 3D piece preview
   -------------------------------------------------------------------------- */

.glossary-card[data-piece-key] {
  cursor: pointer;
}

.glossary-card[data-piece-key]:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.glossary-card .glossary-speak {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.22);
  border-radius: 50%;
  background: rgba(214, 179, 106, 0.07);
  color: var(--gold-bright);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: 160ms ease;
}

.glossary-card .glossary-speak:hover {
  background: rgba(214, 179, 106, 0.18);
  border-color: rgba(214, 179, 106, 0.55);
  transform: scale(1.08);
}

.glossary-card .glossary-speak.is-speaking {
  animation: pronouncePulse 800ms ease-in-out infinite;
  color: var(--cream);
  border-color: var(--gold-bright);
}

@keyframes pronouncePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 179, 106, 0.4); }
  50% { box-shadow: 0 0 0 7px rgba(214, 179, 106, 0); }
}

.glossary-card .glossary-view3d {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 3px 7px;
  border: 1px solid rgba(214, 179, 106, 0.2);
  border-radius: 999px;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: calc(8px * var(--text-scale));
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.glossary-card .glossary-view3d i {
  font-style: normal;
  font-size: 10px;
  color: var(--gold-bright);
}

.piece-preview-panel {
  width: min(100%, 1060px);
  max-height: min(90vh, 820px);
  padding: 0;
  overflow: hidden;
}

.piece-preview-layout {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  min-height: 610px;
}

.piece-preview-stage {
  position: relative;
  min-height: 610px;
  overflow: hidden;
  border-right: 1px solid rgba(214, 179, 106, 0.15);
  background:
    radial-gradient(ellipse 62% 58% at 50% 42%, rgba(214, 179, 106, 0.16), transparent 62%),
    radial-gradient(ellipse 80% 40% at 50% 92%, rgba(0, 0, 0, 0.7), transparent 72%),
    linear-gradient(160deg, #160f09, #070403 70%);
}

#piecePreviewCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#piecePreviewCanvas:active { cursor: grabbing; }

.piece-preview-badge {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 2;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 179, 106, 0.38);
  border-radius: 50%;
  background: rgba(7, 5, 3, 0.45);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 24px;
  box-shadow: inset 0 0 22px rgba(214, 179, 106, 0.1);
  backdrop-filter: blur(8px);
}

.piece-preview-stage-name {
  position: absolute;
  left: 22px;
  bottom: 24px;
  z-index: 2;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
}

.piece-preview-hint {
  position: absolute;
  left: 50%;
  bottom: 25px;
  transform: translateX(-50%);
  z-index: 2;
  padding: 5px 10px;
  border: 1px solid rgba(214, 179, 106, 0.18);
  border-radius: 999px;
  background: rgba(7, 5, 3, 0.45);
  color: var(--muted);
  font-size: calc(8px * var(--text-scale));
  letter-spacing: 0.05em;
  white-space: nowrap;
  backdrop-filter: blur(7px);
}

.piece-preview-copy {
  max-height: 610px;
  overflow: auto;
  padding: 34px 32px 28px;
  scrollbar-width: thin;
}

.piece-preview-copy h2 {
  margin: 5px 0 2px;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: clamp(30px, 3.2vw, 42px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.piece-preview-role {
  color: var(--gold);
  font-size: calc(11px * var(--text-scale));
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.piece-preview-pronounce {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  margin: 14px 0 14px;
}

.pronounce-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid rgba(214, 179, 106, 0.34);
  border-radius: 999px;
  background: rgba(214, 179, 106, 0.08);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: calc(9px * var(--text-scale));
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: 160ms ease;
}

.pronounce-btn:hover {
  background: rgba(214, 179, 106, 0.17);
  border-color: var(--gold);
}

.pronounce-btn.is-speaking {
  animation: pronouncePulse 800ms ease-in-out infinite;
}

.pronounce-hint {
  color: var(--muted);
  font-size: calc(9px * var(--text-scale));
}

.piece-preview-lore {
  margin: 0 0 16px;
  color: #cbb79a;
  font-size: calc(13px * var(--text-scale));
  line-height: 1.62;
}

.piece-preview-block {
  margin-top: 13px;
  padding-top: 11px;
  border-top: 1px solid rgba(214, 179, 106, 0.11);
}

.piece-preview-block > span {
  display: block;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: calc(8px * var(--text-scale));
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.piece-preview-block p {
  margin: 0;
  color: var(--muted);
  font-size: calc(12px * var(--text-scale));
  line-height: 1.55;
}

.piece-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.piece-preview-actions .ghost-btn {
  font-size: calc(9px * var(--text-scale));
}

.piece-preview-actions .ghost-btn.is-active {
  border-color: rgba(214, 179, 106, 0.48);
  background: rgba(214, 179, 106, 0.12);
  color: var(--gold-bright);
}

@media (max-width: 850px) {
  .piece-preview-panel {
    max-height: calc(100vh - 20px);
    overflow: auto;
  }
  .piece-preview-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .piece-preview-stage {
    min-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid rgba(214, 179, 106, 0.15);
  }
  .piece-preview-copy {
    max-height: none;
    padding: 25px 20px 22px;
  }
  .piece-preview-hint { display: none; }
}

@media (max-width: 640px) {
  .piece-preview-stage { min-height: 34vh; }
  .piece-preview-badge { width: 40px; height: 40px; font-size: 19px; top: 14px; left: 14px; }
  .piece-preview-stage-name { font-size: 18px; left: 16px; bottom: 16px; }
  .piece-preview-copy { padding: 21px 17px 18px; }
  .piece-preview-copy h2 { font-size: 30px; }
  .glossary-card .glossary-speak { top: 7px; right: 7px; width: 24px; height: 24px; }
}

/* =========================================================
   Full-size board mode
   ========================================================= */

body.board-focus {
  overflow: hidden;
}

body.board-focus .app-shell {
  width: 100%;
  max-width: none;
  height: 100vh;
  padding: 10px;
  gap: 8px;
}

body.board-focus .topbar,
body.board-focus .sidebar,
body.board-focus .footer,
body.board-focus .capture-tray {
  display: none !important;
}

body.board-focus .workspace {
  display: block;
  flex: 1;
  min-height: 0;
}

body.board-focus .arena {
  height: 100%;
  padding: 10px;
  gap: 8px;
  border-radius: 22px;
}

body.board-focus .board-stage {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  max-height: none;
  border-radius: 18px;
}

body.board-focus .tutor {
  min-height: 68px;
}

body.board-focus .brand {
  pointer-events: none;
}
