/* The scene remains edge to edge. These opaque floating panels carry the UI. */
body,
body[data-theme="cartoon"] {
  --ui-board: #628c68;
  --ui-panel: #fff5df;
  --ui-panel-alt: #f0e1c0;
  --ui-text: #40352b;
  --ui-muted: #6b604c;
  --ui-border: #67513a;
  --ui-primary: #49674b;
  --ui-primary-hover: #38583c;
  --ui-primary-text: #fff8e8;
  --ui-accent: #ddb37e;
  --ui-accent-text: #40352b;
  --ui-board-text: #fff5df;
  --ui-radius: 22px;
  --ui-button-radius: 13px;
  --ui-stroke: 2px;
  --ui-shadow: 0 4px 0 #48553b, 0 10px 20px #263e2b1a;
  --ui-button-shadow: 0 3px 0 #35452f;
  --ui-overlay: #243b2bb3;
  --ui-focus: #3f533a;
  --red: #a62d2c;
  --blue: #225b9f;
  --ink: var(--ui-text);
  --muted: var(--ui-muted);
  --cream: var(--ui-panel);
  --gold: var(--ui-accent);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ui-text);
  background: var(--ui-board);
}

body[data-theme="pop"] {
  --ui-board: #274ddc;
  --ui-panel: #fff6df;
  --ui-panel-alt: #f4e4be;
  --ui-text: #1d2545;
  --ui-muted: #55536a;
  --ui-border: #1d2545;
  --ui-primary: #ff806a;
  --ui-primary-hover: #ff9c87;
  --ui-primary-text: #1d2545;
  --ui-accent: #ffdb54;
  --ui-accent-text: #1d2545;
  --ui-board-text: #fff6df;
  --ui-radius: 14px;
  --ui-button-radius: 9px;
  --ui-stroke: 2px;
  --ui-shadow: 5px 5px 0 #182347;
  --ui-button-shadow: 0 4px 0 #182347;
  --ui-overlay: #111b47a6;
  --ui-focus: #ffdb54;
  --red: #a62d2c;
  --blue: #225b9f;
}

body[data-theme="garden"] {
  --ui-board: #14584f;
  --ui-panel: #ffe7cc;
  --ui-panel-alt: #f4d5b7;
  --ui-text: #173b37;
  --ui-muted: #4d6055;
  --ui-border: #36685d;
  --ui-primary: #693b5a;
  --ui-primary-hover: #845372;
  --ui-primary-text: #fff4e3;
  --ui-accent: #ebae8b;
  --ui-accent-text: #173b37;
  --ui-board-text: #ffe7cc;
  --ui-radius: 27px;
  --ui-button-radius: 17px;
  --ui-stroke: 1px;
  --ui-shadow: 0 7px 0 #0d383f55, 0 16px 36px #062c3330;
  --ui-button-shadow: 0 3px 0 #2e253f;
  --ui-overlay: #082e30ae;
  --ui-focus: #ffc594;
  --red: #9d3736;
  --blue: #245989;
}

body[data-theme="candy"] {
  --ui-board: #4cd4d0;
  --ui-panel: #50234f;
  --ui-panel-alt: #662c61;
  --ui-text: #fff5d9;
  --ui-muted: #efcbe4;
  --ui-border: #ffe8bd;
  --ui-primary: #ffe171;
  --ui-primary-hover: #ffedaa;
  --ui-primary-text: #482047;
  --ui-accent: #ffb9dc;
  --ui-accent-text: #482047;
  --ui-board-text: #fff5d9;
  --ui-radius: 29px;
  --ui-button-radius: 19px;
  --ui-stroke: 2px;
  --ui-shadow: 0 6px 0 #34213f, 0 13px 0 #ffe8bd55;
  --ui-button-shadow: 0 4px 0 #9c6b83;
  --ui-overlay: #3c1948b5;
  --ui-focus: #ffe171;
  --red: #ffb6a3;
  --blue: #9bd8ff;
}

body[data-theme="neon"] {
  --ui-board: #211139;
  --ui-panel: #101b32;
  --ui-panel-alt: #1b2846;
  --ui-text: #effcff;
  --ui-muted: #b3cedc;
  --ui-border: #59e8ed;
  --ui-primary: #f76ace;
  --ui-primary-hover: #ff9ee1;
  --ui-primary-text: #211234;
  --ui-accent: #62f0ec;
  --ui-accent-text: #101b32;
  --ui-board-text: #86fffb;
  --ui-radius: 5px;
  --ui-button-radius: 3px;
  --ui-stroke: 1px;
  --ui-shadow: 0 0 0 3px #59e8ed18, 0 6px 24px #09051e80;
  --ui-button-shadow: 3px 3px 0 #694b9c;
  --ui-overlay: #0a0826c4;
  --ui-focus: #62f0ec;
  --red: #ffa6a0;
  --blue: #8bd5ff;
}

body { --scene-top: 135px; --scene-bottom: 150px; }
body.at-menu { --scene-top: 180px; --scene-bottom: 150px; }
.game-world { min-height: 280px; background: var(--ui-board); }
.screen-vignette { background: none; box-shadow: none; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 4px;
}
#stone-hit-layer button:focus-visible {
  background: transparent;
  outline: 3px solid var(--ui-focus);
  box-shadow: 0 0 0 6px var(--ui-text);
}

/* Header and the mode menu. */
.topbar { top: max(20px, env(safe-area-inset-top)); left: 24px; right: 24px; height: 42px; }
.brand {
  color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius);
  padding: 8px 12px; gap: 8px; font-size: 15px;
  box-shadow: var(--ui-button-shadow);
}
.brand-icon { width: 23px; height: 25px; }
.brand-icon i { width: 9px; height: 9px; background: var(--ui-text); box-shadow: none; }
.brand-icon i:nth-child(3) { background: var(--ui-primary); left: 7px; }
.brand small { color: var(--ui-muted); }
.topbar nav { gap: 8px; }
.icon-button {
  width: 40px; height: 40px; color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius);
  box-shadow: var(--ui-button-shadow); backdrop-filter: none;
}
.icon-button:hover { background: var(--ui-panel-alt); }
.icon-button svg { stroke-width: 1.9; }
.menu-title { top: 70px; left: 0; right: 0; text-align: center; }
.menu-title h1 {
  display: inline-block; margin: 0; font-size: 70px; line-height: 1.2;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-weight: 900; letter-spacing: 5px; color: var(--ui-board-text);
  text-shadow: 3px 4px 0 #172243;
}
.menu-title h1 > span { color: var(--ui-accent); font-size: 29px; margin: 4px 0 0 8px; }
.menu-title p, .menu-title .eyebrow, .mode-caption { color: var(--ui-board-text); text-shadow: 0 2px 2px #172243; }
.menu-actions { bottom: max(16px, env(safe-area-inset-bottom)); width: min(460px, calc(100% - 36px)); }
.mode-options { gap: 14px; }
.mode-button {
  height: 72px; padding: 18px 22px; gap: 14px; color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow); backdrop-filter: none;
}
.mode-button:hover { background: var(--ui-panel-alt); box-shadow: var(--ui-shadow); transform: translateY(-2px); }
.mode-button strong { color: inherit; font-size: 18px; font-weight: 800; }
.mode-button small, .mode-button strong > span { color: inherit; }
.ai-mode { background: var(--ui-primary); color: var(--ui-primary-text); }
.ai-mode:hover { background: var(--ui-primary-hover); box-shadow: var(--ui-shadow); }
.mode-symbol .red-token { background: #e75655; border: 1px solid #8c2a39; }
.mode-symbol .blue-token { background: #4c9ddd; border: 1px solid #164f86; }
.robot-symbol { border: 2px solid currentColor; color: inherit; border-radius: 5px; }
.robot-symbol i, .robot-symbol b { background: currentColor; }
.menu-config {
  width: fit-content; max-width: 100%; margin: 10px auto 0; padding: 4px 17px;
  min-height: 31px; color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: 30px;
  font-size: 11px; font-weight: 600; box-shadow: 0 2px 0 #101b4333;
}
.config-edit { color: inherit; }

/* Stable red/blue player identity, independent of the decorative palette. */
.scoreboard {
  top: 20px; width: min(500px, calc(100% - 500px)); height: 66px;
  grid-template-columns: 1fr 90px 1fr; padding: 0 17px;
  color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow); backdrop-filter: none;
}
.side { opacity: 1; gap: 9px; }
.side strong { font-size: 13px; font-weight: 700; }
.side-avatar { color: #9c2d2f; background: #ffd2c5; border-color: #ba4d4b; width: 33px; height: 33px; box-shadow: none; }
.blue-side .side-avatar { color: #185687; background: #d6edff; border-color: #478cb5; }
.side.active .side-avatar { box-shadow: 0 0 0 3px #e65058, 0 0 0 5px var(--ui-panel); }
.blue-side.active .side-avatar { box-shadow: 0 0 0 3px #429ddd, 0 0 0 5px var(--ui-panel); }
.side-score { font-size: 30px; color: var(--red); font-weight: 700; }
.blue-side .side-score { color: var(--blue); }
.win-dots { margin-top: 7px; }
.win-dots i { background: transparent; border: 1px solid var(--ui-muted); }
.red-side .win-dots i.won { background: var(--red); border-color: var(--red); }
.blue-side .win-dots i.won { background: var(--blue); border-color: var(--blue); }
.round-info, .round-info > span, .round-info > small, .round-info #match-level { color: var(--ui-muted); }
.round-info > strong { color: var(--ui-text); font-size: 13px; font-weight: 700; }
.table-meta { top: 101px; gap: 9px; }
.remaining-badge, .dice-caption, .last-move {
  color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: 30px;
  text-shadow: none; backdrop-filter: none; box-shadow: 0 2px 0 #101b4333;
}
.remaining-badge { padding: 4px 12px; font-size: 11px; }
.remaining-badge strong { font-size: 19px; color: var(--ui-text); }
.dice-caption { padding: 6px 12px; font-size: 11px; max-width: min(350px, 65vw); }
.last-move { bottom: 145px; }

/* The controls stay compact enough to leave the playing surface open. */
.control-dock {
  bottom: max(17px, env(safe-area-inset-bottom)); width: min(560px, calc(100% - 36px));
  padding: 13px 17px; color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow); backdrop-filter: none;
}
.turn-line { margin-bottom: 10px; }
.turn-chip { font-size: 14px; font-weight: 700; }
.turn-chip > i { background: var(--ui-muted); }
.turn-chip.red > i { background: var(--red); }
.turn-chip.blue > i { background: var(--blue); }
.selected-label, #turn-hint { color: var(--ui-muted); }
.selected-label { font-size: 11px; }
.action-row { gap: 11px; }
.amount-picker { gap: 7px; }
.amount-picker button {
  min-width: 31px; height: 42px; background: var(--ui-panel-alt); color: var(--ui-text);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius);
  box-shadow: 0 2px 0 #101b4333; font-size: 21px; font-weight: 700;
}
.amount-picker button:hover:not(:disabled) { background: var(--ui-accent); color: var(--ui-accent-text); }
.amount-picker button.active {
  color: var(--ui-accent-text); background: var(--ui-accent); border-color: var(--ui-border);
  box-shadow: inset 0 0 0 1px var(--ui-border), 0 2px 0 #101b4333;
}
.amount-picker button:disabled { background: var(--ui-panel-alt); color: var(--ui-muted); border-color: var(--ui-muted); opacity: .65; box-shadow: none; }
.primary-button {
  min-height: 42px; background: var(--ui-primary); color: var(--ui-primary-text);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius);
  box-shadow: var(--ui-button-shadow); font-weight: 700;
}
.primary-button:hover:not(:disabled) { background: var(--ui-primary-hover); }
.primary-button:disabled { background: var(--ui-panel-alt); color: var(--ui-muted); border-color: var(--ui-muted); box-shadow: none; opacity: .8; }
#main-action { min-width: 165px; }
.secondary-button, .quiet-button { color: var(--ui-text); background: var(--ui-panel-alt); border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius); }
.quiet-button { background: transparent; border-color: transparent; }
.secondary-button:hover, .quiet-button:hover { background: var(--ui-panel-alt); }

/* Dialogs, settings, difficulty choices and the end-of-round panel. */
dialog, .result-card {
  color: var(--ui-text); background: var(--ui-panel);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow); scrollbar-color: var(--ui-muted) var(--ui-panel-alt);
}
dialog::backdrop, .result-screen { background: var(--ui-overlay); backdrop-filter: blur(4px); }
dialog h2, .result-card h2 { font-weight: 800; }
.dialog-close { color: var(--ui-text); background: var(--ui-panel-alt); border-radius: var(--ui-button-radius); }
.dialog-close:hover { background: var(--ui-accent); color: var(--ui-accent-text); }
.eyebrow, .dialog-intro, .rules-list p, .rules-list li > b, .field-label span,
.count-field > span, fieldset legend small, fieldset label small, .toggle-setting small,
.result-card p, .result-score i { color: var(--ui-muted); }
.rules-list li > b { color: var(--ui-text); text-shadow: none; }
.count-field, fieldset label, .presets button {
  color: var(--ui-text); background: var(--ui-panel-alt);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius);
}
.count-field input, .count-field > button { color: var(--ui-text); }
.count-field input { color-scheme: light; }
body[data-theme="candy"] .count-field input, body[data-theme="neon"] .count-field input { color-scheme: dark; }
.presets button:hover { background: var(--ui-accent); color: var(--ui-accent-text); }
fieldset label:has(input:checked) { background: var(--ui-accent); color: var(--ui-accent-text); border-color: var(--ui-border); }
fieldset label:has(input:checked) small { color: inherit; }
fieldset input { accent-color: var(--ui-primary); }
fieldset i { color: var(--ui-muted); }
.toggle-setting { border-top-color: var(--ui-border); }
.toggle-setting strong { font-weight: 700; }
.toggle-setting > i { background: var(--ui-muted); border: 1px solid var(--ui-border); }
.toggle-setting > i:after { top: 2px; left: 2px; background: var(--ui-panel); box-shadow: 0 1px 3px #101b4366; }
.toggle-setting input:checked + i { background: var(--ui-primary); }
.toggle-setting input:focus-visible + i { outline-color: var(--ui-focus); }
.difficulty-options button {
  background: var(--ui-panel-alt); color: var(--ui-text);
  border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius); font-weight: 700;
}
.difficulty-options button > span { color: var(--ui-muted); }
.difficulty-options button:hover { background: var(--ui-accent); color: var(--ui-accent-text); }
.difficulty-options button[aria-checked="true"],
#ai-dialog[data-level="extreme"] .difficulty-options button[aria-checked="true"] {
  background: var(--ui-primary); color: var(--ui-primary-text); border-color: var(--ui-border);
  box-shadow: var(--ui-button-shadow);
}
.difficulty-options button[aria-checked="true"] > span { color: inherit; }
.difficulty-detail {
  background: var(--ui-panel-alt); border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-radius);
}
.difficulty-detail h3, .ai-strength, .ai-count strong { color: var(--ui-text); }
.ai-strategy, .ai-count > span, .ai-count-policy, .restart-note { color: var(--ui-muted); }
.level-symbol, #ai-dialog[data-level="extreme"] .level-symbol { color: var(--ui-primary); opacity: .22; }
.result-emblem { color: var(--ui-accent); }
.round-record span { background: #ffd4c6; color: #952c2a; border: 1px solid #a94a42; font-weight: 700; }
.round-record span.blue { background: #d4edff; color: #164f7e; border-color: #397aa2; }
.toast { background: var(--ui-panel); color: var(--ui-text); border: var(--ui-stroke) solid var(--ui-border); border-radius: var(--ui-button-radius); box-shadow: var(--ui-shadow); white-space: normal; text-align: center; line-height: 1.7; }
.boot-loader, .graphics-error { background: var(--ui-board); color: var(--ui-board-text); }
.boot-loader p, .graphics-error p, .graphics-error > span { color: var(--ui-board-text); }
.loading-stone { background: var(--ui-primary); border: 2px solid var(--ui-border); }

/* Each theme has its own shape and typographic character. */
body[data-theme="cartoon"] .menu-title h1 {
  color: #fff5df; -webkit-text-stroke: 1.5px #314c36; paint-order: stroke fill;
  text-shadow: 0 4px 0 #314c36; letter-spacing: 4px;
}
body[data-theme="cartoon"] .menu-title h1 > span {
  color: #e3bf8c; -webkit-text-stroke: 1px #67513a; text-shadow: 0 2px 0 #314c36;
}
body[data-theme="cartoon"] .mode-button { border-radius: 22px; }
body[data-theme="cartoon"] .icon-button { border-radius: 13px; }
body[data-theme="cartoon"] .primary-button { border-radius: 15px; }
body[data-theme="cartoon"] .amount-picker button.active { box-shadow: 0 3px 0 #67513a; }
body[data-theme="pop"] .menu-title h1 { -webkit-text-stroke: 1px #182347; }
body[data-theme="pop"] .mode-button:first-child { transform: rotate(-1.5deg); }
body[data-theme="pop"] .mode-button:last-child { transform: rotate(1.5deg); }
body[data-theme="pop"] .mode-button:hover { transform: translateY(-3px); }
body[data-theme="garden"] .menu-title h1,
body[data-theme="garden"] dialog h2,
body[data-theme="garden"] .result-card h2 {
  font-family: "STSong", "Songti SC", "SimSun", Georgia, serif; font-weight: 700;
}
body[data-theme="garden"] .menu-title h1 { letter-spacing: 9px; text-shadow: 0 3px 8px #092e32; }
body[data-theme="garden"] .mode-button { border-radius: 29px 17px 30px 18px; }
body[data-theme="garden"] .control-dock { border-radius: 25px 25px 18px 18px; }
body[data-theme="garden"] .icon-button { border-radius: 50%; }
body[data-theme="candy"] .menu-title h1 { letter-spacing: 4px; text-shadow: 3px 3px 0 #6a2c63, -2px -2px 0 #6a2c63, 0 6px 0 #50234f; }
body[data-theme="candy"] .mode-button { border-radius: 30px 30px 22px 22px; }
body[data-theme="candy"] .primary-button { border-radius: 30px; }
body[data-theme="candy"] .icon-button { border-radius: 14px; }
body[data-theme="neon"] .menu-title h1 { letter-spacing: 10px; text-shadow: 0 0 20px #59e8ed80, 4px 3px 0 #5e1b77; }
body[data-theme="neon"] .menu-title h1 > span { color: #ff93df; }
body[data-theme="neon"] .brand,
body[data-theme="neon"] .round-info,
body[data-theme="neon"] .selected-label,
body[data-theme="neon"] .side-score,
body[data-theme="neon"] .amount-picker button,
body[data-theme="neon"] .ai-count strong { font-family: "Cascadia Mono", Consolas, "Microsoft YaHei", monospace; }
body[data-theme="neon"] .icon-button:hover { box-shadow: 0 0 12px #59e8ed66; }
body[data-theme="neon"] .difficulty-detail { background: repeating-linear-gradient(0deg, #1b2846 0 23px, #29405d 24px), var(--ui-panel-alt); }
body[data-theme="neon"] .scoreboard { border-bottom-width: 3px; }

/* Palette previews use CSS only and remain recognizable before selection. */
#theme-dialog { width: min(620px, calc(100% - 28px)); padding: 28px; }
#theme-dialog h2 { padding-right: 35px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; margin: 23px 0; }
.theme-option {
  position: relative; display: flex; flex-direction: column; gap: 7px;
  min-width: 0; padding: 10px 10px 13px; text-align: left;
  background: var(--ui-panel-alt); color: var(--ui-text);
  border: 2px solid var(--ui-border); border-radius: var(--ui-button-radius);
}
.theme-option:hover { box-shadow: 0 3px 0 var(--ui-border); transform: translateY(-2px); }
.theme-option strong { font-size: 15px; line-height: 1.3; padding: 0 3px; }
.theme-option small { font-size: 11px; line-height: 1.5; color: var(--ui-muted); padding: 0 3px; }
.theme-option[aria-checked="true"] { outline: 3px solid var(--ui-accent); outline-offset: 3px; border-color: var(--ui-border); }
.theme-option[aria-checked="true"]:after {
  content: "✓"; position: absolute; top: 16px; right: 16px; width: 24px; height: 24px;
  display: grid; place-items: center; border: 2px solid var(--ui-border); border-radius: 50%;
  background: var(--ui-accent); color: var(--ui-accent-text); font-size: 14px; font-weight: 800;
}
.theme-preview {
  display: flex; align-items: center; justify-content: center; gap: 13px;
  width: 100%; height: 92px; overflow: hidden; border-radius: 6px;
  background: #274ddc; border: 1px solid #132466;
}
.preview-token {
  display: block; width: 40px; height: 40px; flex: none; border-radius: 50%;
  background: #ff806a; color: transparent; font-size: 0; font-style: normal;
  border: 2px solid #862e38; box-shadow: 0 5px 0 #a13f49, inset 0 0 0 5px #ffb09a;
  transform: rotate(-14deg);
}
.preview-token + .preview-token { background: #ffdc54; border-color: #99752b; box-shadow: 0 5px 0 #ad7f2f, inset 0 0 0 5px #ffe88c; transform: translateY(6px) rotate(12deg); }
.theme-option[data-theme-choice="cartoon"] {
  grid-column: 1 / -1; display: grid;
  grid-template-columns: minmax(100px, .85fr) minmax(0, 1fr);
  grid-template-rows: 1fr 1fr; gap: 4px 16px; padding: 10px;
}
[data-theme-choice="cartoon"] .theme-preview {
  grid-row: 1 / 3; height: 76px; border: 2px solid #795a3f; border-radius: 14px;
  background: radial-gradient(ellipse at 12% 12%, #a5b88766 0 14%, transparent 15%),
    radial-gradient(ellipse at 95% 92%, #355b4840 0 19%, transparent 20%), #628c68;
  box-shadow: inset 0 0 0 3px #b2946477;
}
[data-theme-choice="cartoon"] > strong { align-self: end; margin-right: 25px; }
[data-theme-choice="cartoon"] > small { align-self: start; }
[data-theme-choice="cartoon"] .preview-token {
  display: grid; place-items: center; position: relative; width: 43px; height: 47px;
  color: #4b382b; background: transparent; border: 0; padding: 0;
  border-radius: 0; box-shadow: none; font-size: 0; transform: rotate(-6deg);
}
[data-theme-choice="cartoon"] .preview-token + .preview-token {
  color: #4b382b; background: transparent; border: 0; padding: 0; box-shadow: none;
  transform: translateY(4px) rotate(6deg);
}
[data-theme-choice="cartoon"] .preview-token svg {
  display: block; width: 100%; height: 100%; overflow: visible;
  filter: drop-shadow(0 3px 0 #354d3d66);
}
[data-theme-choice="pop"] .theme-preview { background: radial-gradient(circle, #6587ee 1px, transparent 2px) 0 0 / 14px 14px, #274ddc; }
[data-theme-choice="garden"] .theme-preview { background: repeating-linear-gradient(115deg, transparent 0 23px, #83ac7b22 24px 26px, transparent 27px 46px), #14584f; border-color: #0a3739; border-radius: 18px 9px 18px 9px; }
[data-theme-choice="garden"] .preview-token { background: #ed937e; border-color: #963e4c; box-shadow: 0 5px 0 #a75058, inset 0 0 0 5px #f5b69c; }
[data-theme-choice="garden"] .preview-token + .preview-token { background: #ffc697; border-color: #9d6b43; box-shadow: 0 5px 0 #b57d4e, inset 0 0 0 5px #ffdbb1; }
[data-theme-choice="candy"] .theme-preview { background: repeating-linear-gradient(135deg, #6fe1d7 0 15px, #4cd4d0 15px 30px); border-color: #18818d; border-radius: 18px; }
[data-theme-choice="candy"] .preview-token { background: #ff8aca; border-color: #9a3b82; box-shadow: 0 5px 0 #ad5197, inset 0 0 0 5px #ffb9e1; }
[data-theme-choice="candy"] .preview-token + .preview-token { background: #ffe171; border-color: #a47a40; box-shadow: 0 5px 0 #ba8a43, inset 0 0 0 5px #fff0a3; }
[data-theme-choice="neon"] .theme-preview { background: linear-gradient(#754ba72e 1px, transparent 1px), linear-gradient(90deg, #754ba72e 1px, transparent 1px), #211139; background-size: 17px 17px; border-color: #7657ae; border-radius: 2px; }
[data-theme-choice="neon"] .preview-token { background: #4ee7ee; border-color: #c3ffff; box-shadow: 0 5px 0 #27899f, 0 0 12px #4ee7ee90, inset 0 0 0 5px #8ffaff; }
[data-theme-choice="neon"] .preview-token + .preview-token { background: #fa6ad8; border-color: #ffcbf5; box-shadow: 0 5px 0 #9d3b9c, 0 0 12px #fa6ad890, inset 0 0 0 5px #ffa6ec; }
#theme-done { width: 100%; }

@media (min-width: 900px) and (max-width: 1090px) {
  .scoreboard { width: calc(100% - 500px); padding: 0 12px; grid-template-columns: 1fr 72px 1fr; }
  .side { gap: 7px; }
  .side-avatar { width: 28px; height: 28px; }
  .side strong { font-size: 11px; }
  .side-score { font-size: 26px; }
}

@media (max-width: 899px) {
  body { --scene-top: 175px; --scene-bottom: 185px; }
  body.at-menu { --scene-top: 150px; --scene-bottom: 160px; }
  .topbar { top: max(12px, env(safe-area-inset-top)); left: 14px; right: 14px; height: 36px; }
  .brand { font-size: 12px; padding: 6px 9px; gap: 6px; }
  .brand-icon { width: 20px; height: 23px; transform: rotate(-14deg); }
  .brand-icon i { width: 8px; height: 8px; }
  .brand-icon i:nth-child(3) { left: 6px; }
  .topbar nav { gap: 6px; }
  .icon-button { width: 35px; height: 35px; }
  .icon-button svg { width: 18px; height: 18px; }
  .menu-title { top: 73px; left: 0; right: 0; }
  .menu-title h1 { font-size: 51px; letter-spacing: 4px; }
  .menu-title h1 > span { font-size: 22px; margin-left: 5px; }
  .menu-actions { width: min(460px, calc(100% - 32px)); bottom: max(14px, env(safe-area-inset-bottom)); }
  .mode-options { gap: 12px; }
  .mode-button { height: 68px; padding: 14px 17px; gap: 10px; }
  .mode-button strong { font-size: 16px; }
  .menu-config { font-size: 10px; min-height: 30px; margin-top: 10px; padding: 3px 14px; }
  .scoreboard { top: 65px; width: min(520px, calc(100% - 28px)); height: 64px; padding: 0 13px; grid-template-columns: 1fr 78px 1fr; }
  .side strong { font-size: 12px; }
  .side-score { font-size: 27px; }
  .side-avatar { width: 30px; height: 30px; }
  .table-meta { top: 141px; gap: 7px; }
  .remaining-badge { padding: 3px 10px; font-size: 10px; }
  .remaining-badge strong { font-size: 17px; }
  .dice-caption { padding: 5px 9px; font-size: 10px; }
  .control-dock { width: min(560px, calc(100% - 28px)); padding: 12px 14px; bottom: max(14px, env(safe-area-inset-bottom)); }
  .turn-line { float: none; width: auto; margin: 0 0 9px; }
  .turn-chip { font-size: 13px; }
  .selected-label { font-size: 10px; }
  .action-row { display: block; }
  .amount-picker { margin-bottom: 9px; gap: 7px; }
  .amount-picker button { min-width: 0; height: 38px; font-size: 20px; }
  #main-action { width: 100%; min-width: 0; min-height: 40px; padding: 9px 15px; }
  .last-move { bottom: 173px; }
  #theme-dialog { padding: 23px 20px; }
  .theme-grid { gap: 13px; margin: 21px 0; }
  .theme-preview { height: 79px; }
  .theme-option strong { font-size: 14px; }
  .theme-option small { font-size: 10px; }
}

@media (max-width: 360px) {
  .topbar { left: 12px; right: 12px; }
  .brand { padding: 6px 7px; font-size: 11px; gap: 4px; }
  .brand-icon { width: 18px; }
  .topbar nav { gap: 5px; }
  .icon-button { width: 33px; height: 33px; }
  .menu-title h1 { font-size: 44px; }
  body[data-theme="garden"] .menu-title h1, body[data-theme="neon"] .menu-title h1 { letter-spacing: 5px; }
  .mode-button { gap: 8px; padding: 12px; }
  .mode-button strong { font-size: 14px; }
  .mode-symbol { transform: scale(.88); }
  .scoreboard { grid-template-columns: 1fr 65px 1fr; padding: 0 10px; }
  .side { gap: 6px; }
  .side-avatar { width: 26px; height: 26px; }
  .side strong { font-size: 10px; }
  .side-score { font-size: 25px; }
  .round-info > strong { font-size: 11px; }
  .turn-chip { font-size: 12px; }
  .selected-label { font-size: 9px; }
  #theme-dialog { padding: 22px 16px; }
  .theme-grid { gap: 12px; }
  .theme-option { padding: 8px 8px 11px; }
  .theme-option small { font-size: 9px; }
  .theme-preview { height: 69px; gap: 9px; }
  .preview-token { width: 31px; height: 31px; }
  .theme-option[aria-checked="true"]:after { top: 11px; right: 11px; width: 21px; height: 21px; font-size: 12px; }
  .theme-grid { margin: 18px 0; gap: 10px; }
  .theme-preview { height: 62px; }
  .theme-option[data-theme-choice="cartoon"] { padding: 8px; column-gap: 11px; }
  [data-theme-choice="cartoon"] .theme-preview { height: 62px; gap: 8px; }
  [data-theme-choice="cartoon"] .preview-token { width: 34px; height: 39px; }
}

@media (orientation: landscape) and (max-height: 550px) {
  body { --scene-top: 90px; --scene-bottom: 85px; }
  body.at-menu { --scene-top: 90px; --scene-bottom: 120px; }
  .topbar { top: 10px; left: 14px; right: 14px; height: 32px; }
  .topbar .brand { visibility: hidden; }
  .topbar nav { gap: 6px; }
  .icon-button { width: 31px; height: 31px; }
  .menu-title { top: 13px; left: 22px; right: auto; text-align: left; }
  .menu-title h1 { font-size: 37px; letter-spacing: 3px; }
  .menu-title h1 > span { font-size: 19px; }
  body[data-theme="garden"] .menu-title h1, body[data-theme="neon"] .menu-title h1 { letter-spacing: 4px; }
  .menu-actions { width: 370px; bottom: 9px; }
  .mode-button { height: 57px; justify-content: center; padding: 10px 16px; }
  .mode-button strong { font-size: 16px; }
  .mode-symbol { display: none; }
  .menu-config { min-height: 26px; margin-top: 8px; font-size: 10px; }
  .scoreboard { top: 10px; left: 20px; transform: none; width: min(360px, calc(100% - 195px)); height: 47px; padding: 0 13px; grid-template-columns: 1fr 76px 1fr; }
  .side-avatar { display: none; }
  .side-score { font-size: 24px; }
  .side strong { font-size: 11px; }
  .win-dots { margin-top: 4px; }
  .win-dots i { width: 5px; height: 5px; }
  .round-info > strong { font-size: 11px; }
  .round-info #match-level { display: block; font-size: 8px; }
  .table-meta { top: 64px; gap: 7px; }
  .remaining-badge { padding: 2px 9px; font-size: 9px; }
  .remaining-badge strong { font-size: 15px; }
  .dice-caption { padding: 3px 9px; font-size: 9px; }
  .control-dock { display: grid; grid-template-columns: minmax(110px, .7fr) minmax(0, 1.8fr); align-items: center; gap: 13px; width: min(610px, calc(100% - 28px)); bottom: max(9px, env(safe-area-inset-bottom)); padding: 9px 13px; }
  .turn-line { float: none; width: auto; margin: 0; }
  .turn-chip { font-size: 11px; gap: 6px; }
  .selected-label { display: none; }
  .action-row { display: flex; align-items: center; gap: 10px; }
  .amount-picker { margin: 0; gap: 5px; }
  .amount-picker button { height: 34px; min-width: 23px; font-size: 17px; }
  #main-action { width: auto; min-width: 112px; min-height: 34px; font-size: 11px; padding: 7px 10px; }
  .result-card { max-height: calc(100dvh - 24px); overflow: auto; }
  #theme-dialog { max-height: calc(100dvh - 24px); padding: 19px 23px; }
  .theme-grid { margin: 18px 0; }
  .theme-preview { height: 65px; }
  .theme-option { gap: 5px; padding: 8px 8px 10px; }
  [data-theme-choice="cartoon"] .theme-preview { height: 57px; }
}
