﻿:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --ink: #22170a;
  --muted: #5f4e34;
  --paper: #fff6df;
  --panel: rgba(255, 247, 222, 0.94);
  --card: rgba(255, 252, 242, 0.98);
  --line: rgba(141, 92, 21, 0.36);
  --green: #a86c17;
  --green-dark: #70440d;
  --gold: #b67819;
  --red: #b84d3e;
  --shadow: rgba(45, 29, 8, 0.13);
  --die-shadow: rgba(48, 28, 5, 0.18);
  --sun-glow: rgba(217, 168, 68, 0.2);
  --bg-start: #f7eed8;
  --bg-mid: #fffaf0;
  --bg-end: #e8dcc2;
  --gold-soft: rgba(168, 108, 23, 0.16);
  --gold-line: rgba(174, 112, 22, 0.52);
  --button-ink: #140d04;
  --felt: #f2dfaa;
  --felt-deep: #c09242;
  --felt-line: rgba(119, 75, 12, 0.24);
  --felt-grain: rgba(95, 61, 12, 0.045);
  --metal-top: #fff0bd;
  --metal-mid: #b67819;
  --metal-low: #5f380c;
}

html.dark,
body.dark {
  color-scheme: dark;
  --ink: #fff3d0;
  --muted: #c8b893;
  --paper: #070604;
  --panel: rgba(14, 11, 7, 0.92);
  --card: rgba(23, 18, 11, 0.92);
  --line: rgba(211, 157, 53, 0.42);
  --green: #d3a247;
  --green-dark: #9a681c;
  --gold: #f1c86a;
  --red: #ff806d;
  --shadow: rgba(0, 0, 0, 0.46);
  --die-shadow: rgba(0, 0, 0, 0.5);
  --sun-glow: rgba(241, 200, 106, 0.16);
  --bg-start: #030302;
  --bg-mid: #11100b;
  --bg-end: #050404;
  --gold-soft: rgba(241, 200, 106, 0.16);
  --gold-line: rgba(241, 200, 106, 0.62);
  --button-ink: #120b02;
  --felt: #141109;
  --felt-deep: #070604;
  --felt-line: rgba(241, 200, 106, 0.24);
  --felt-grain: rgba(255, 226, 146, 0.045);
  --metal-top: #ffe29a;
  --metal-mid: #c58c30;
  --metal-low: #5f380c;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg-end);
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  overscroll-behavior: none;
  background:
    repeating-linear-gradient(90deg, transparent 0 30px, rgba(255, 230, 150, 0.018) 31px 32px),
    linear-gradient(120deg, transparent 0 22%, var(--sun-glow) 48%, transparent 74%),
    linear-gradient(135deg, var(--bg-start), var(--bg-mid) 48%, var(--bg-end));
  color: var(--ink);
  transition:
    background 180ms ease,
    color 180ms ease;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.game {
  width: min(980px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: stretch;
}

.topbar {
  grid-column: 1 / -1;
  position: relative;
  z-index: 20;
  display: block;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.1), transparent 54%),
    repeating-linear-gradient(135deg, transparent 0 13px, rgba(255, 222, 145, 0.035) 14px 15px),
    var(--panel);
  box-shadow: 0 20px 60px var(--shadow);
}

.game {
  isolation: isolate;
}

.topbar,
.scoreboard,
.table,
.rules {
  border-color: var(--gold-line);
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.05),
    0 20px 60px var(--shadow);
}

.topbar,
.scoreboard,
.table,
.rules,
.player,
.info-rollup,
.menu-panel {
  backdrop-filter: blur(8px);
}

.top-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.menu-shell {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}

.menu-trigger {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-shadow: 0 0 12px rgba(241, 200, 106, 0.08);
}

.menu-trigger[aria-expanded="true"],
.menu-shell.menu-open .menu-trigger {
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 218, 0.48),
    0 12px 26px rgba(62, 36, 7, 0.18);
  text-shadow: 0 1px 0 rgba(255, 247, 213, 0.38);
}

.menu-trigger:hover,
.menu-trigger:focus-visible {
  background:
    linear-gradient(180deg, #f6d982, var(--green) 58%, #8c5d19);
  color: var(--button-ink);
  text-shadow: 0 1px 0 rgba(255, 247, 213, 0.38);
}

.menu-panel {
  position: absolute;
  top: calc(100% - 1px);
  left: 50%;
  width: min(420px, calc(50vw - 28px));
  max-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-color: var(--gold-line);
  background:
    linear-gradient(145deg, rgba(255, 231, 153, 0.1), transparent 42%),
    repeating-linear-gradient(135deg, transparent 0 13px, rgba(255, 222, 145, 0.035) 14px 15px),
    var(--panel);
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.055),
    0 24px 70px var(--shadow);
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateX(-50%);
  transition:
    max-height 220ms ease,
    opacity 160ms ease,
    transform 180ms ease;
}

.menu-shell.menu-open .menu-panel {
  max-height: min(560px, calc(100dvh - 92px));
  opacity: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  pointer-events: auto;
  transform: translateX(-50%);
}

.info-panel {
  left: auto;
  right: 0;
  transform: none;
}

.info-shell.menu-open .info-panel {
  transform: none;
}

@media (hover: hover) and (pointer: fine) {
  .menu-shell:hover .menu-panel {
    max-height: min(560px, calc(100dvh - 92px));
    opacity: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    transform: translateX(-50%);
  }

  .info-shell:hover .info-panel {
    transform: none;
  }
}

.menu-options {
  display: grid;
  gap: 8px;
}

.info-rollup {
  min-width: 0;
  max-height: min(520px, calc(100dvh - 92px));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--gold-line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 231, 153, 0.1), transparent 42%),
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(255, 226, 146, 0.032) 13px 14px),
    var(--card);
  color: var(--muted);
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.05),
    0 16px 42px var(--shadow);
}

.info-heading {
  min-height: 42px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid rgba(211, 157, 53, 0.18);
}

.info-heading span,
.info-heading strong {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.info-content {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.info-content p,
.info-content ul {
  margin: 0;
}

.info-content p,
.info-content li {
  font-size: 0.82rem;
  line-height: 1.35;
}

.info-content ul {
  display: grid;
  gap: 5px;
  padding-left: 18px;
}

.info-content strong {
  color: var(--ink);
}

.info-content a {
  color: var(--green);
  font-weight: 900;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.info-content a:hover {
  color: var(--green-dark);
}

.info-content li span {
  color: var(--red);
}

.setting {
  width: 100%;
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

body.gamble-mode .risk-setting {
  display: none;
}

.topbar span,
.topbar label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.theme-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.08), transparent),
    var(--card);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 180, 0.035);
}

.theme-option {
  min-width: 76px;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
}

.theme-option.active {
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
  text-shadow: 0 1px 0 rgba(255, 247, 213, 0.38);
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 210, 0.45),
    0 8px 18px rgba(77, 46, 8, 0.18);
}

.score-setting {
  display: grid;
  grid-template-columns: minmax(72px, 86px) auto;
  gap: 6px;
}

.score-setting input {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.06), transparent),
    var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.score-setting button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
  box-shadow: inset 0 1px 0 rgba(255, 248, 210, 0.34);
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

.score-setting button:hover {
  background:
    linear-gradient(180deg, #f3cf74, var(--green-dark) 62%, var(--metal-low));
}

.scoreboard,
.table,
.rules {
  border: 1px solid var(--gold-line);
  background:
    linear-gradient(145deg, rgba(255, 230, 150, 0.06), transparent 44%),
    var(--panel);
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.05),
    0 20px 60px var(--shadow);
}

.scoreboard {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
}

.table {
  grid-column: 1 / -1;
  position: relative;
  overflow: hidden;
}

.player {
  min-height: 136px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  background:
    repeating-linear-gradient(135deg, transparent 0 9px, rgba(255, 236, 174, 0.035) 10px 11px),
    linear-gradient(145deg, rgba(255, 241, 174, 0.08), transparent 42%),
    var(--card);
  transition:
    background 180ms ease,
    border-color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.player::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(211, 157, 53, 0.18);
  border-radius: 7px;
  pointer-events: none;
}

.player::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(120deg, rgba(255, 230, 150, 0.1), transparent 34%),
    linear-gradient(300deg, rgba(0, 0, 0, 0.16), transparent 42%);
}

.player > * {
  position: relative;
  z-index: 1;
}

.player.active {
  border-color: var(--gold);
  box-shadow:
    inset 0 0 0 2px var(--gold-soft),
    0 0 24px rgba(217, 168, 68, 0.14);
  transform: translateY(-2px);
}

.player.winner {
  border-color: var(--gold);
  box-shadow:
    inset 0 0 0 2px rgba(216, 154, 43, 0.24),
    0 0 30px rgba(217, 168, 68, 0.2);
}

.player.win-pop {
  animation: winner-pop 900ms ease;
}

.label {
  margin: 0;
  color: var(--gold);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.name-button {
  width: fit-content;
  max-width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 4px 6px;
  text-align: left;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(241, 200, 106, 0.12);
}

.name-button:hover {
  background: var(--gold-soft);
  color: var(--green);
}

.name-button:disabled {
  cursor: default;
  opacity: 1;
}

.name-button:disabled:hover {
  background: transparent;
  color: var(--muted);
}

.starter-button {
  width: fit-content;
  max-width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.08), transparent),
    var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  text-transform: uppercase;
}

.starter-button:hover:not(:disabled),
.starter-button.active {
  border-color: var(--green);
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
}

.starter-button:disabled {
  cursor: default;
}

.opponent-top {
  display: grid;
  gap: 8px;
}

.mini-switcher {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.08), transparent),
    var(--panel);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 180, 0.035);
}

.mini-switcher .theme-option {
  min-width: 0;
  min-height: 34px;
  font-size: 0.82rem;
}

.inline-name-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: min(100%, 280px);
}

.inline-name-editor[hidden] {
  display: none;
}

.inline-name-editor input {
  min-height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.inline-name-editor button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

.inline-name-editor button:hover {
  background:
    linear-gradient(180deg, #f3cf74, var(--green-dark) 62%, var(--metal-low));
}

.player strong {
  font-size: clamp(3.4rem, 8vw, 5.4rem);
  line-height: 0.95;
  color: var(--ink);
  text-shadow:
    0 1px 0 rgba(255, 246, 210, 0.7),
    0 0 12px rgba(168, 108, 23, 0.18);
}

body.dark .player strong {
  color: #fff7df;
  text-shadow:
    0 1px 0 #8c5d19,
    0 0 16px rgba(217, 168, 68, 0.2);
}

.player span,
.round span,
.turn-score span {
  color: var(--muted);
}

.round strong,
.turn-score strong {
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 246, 210, 0.58);
}

body.dark .round strong,
body.dark .turn-score strong {
  color: #fff7df;
  text-shadow:
    0 1px 0 #8c5d19,
    0 0 14px rgba(217, 168, 68, 0.2);
}

.wins {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  width: fit-content;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 235, 168, 0.16), rgba(0, 0, 0, 0.06)),
    var(--panel);
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.04),
    0 8px 18px rgba(0, 0, 0, 0.12);
}

.wins span {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.wins strong {
  font-size: 1.25rem;
  line-height: 1;
}

.table {
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 14px;
  text-align: center;
  background:
    linear-gradient(145deg, rgba(255, 252, 230, 0.34), transparent 36%),
    repeating-linear-gradient(45deg, transparent 0 18px, var(--felt-grain) 19px 20px),
    repeating-linear-gradient(135deg, transparent 0 24px, rgba(80, 48, 8, 0.035) 25px 26px),
    linear-gradient(160deg, var(--felt), var(--felt-deep));
}

.table::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid var(--felt-line);
  border-radius: 10px;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 1px rgba(255, 248, 218, 0.22),
    inset 0 0 36px rgba(91, 56, 11, 0.1);
}

.table::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 240, 0.14), transparent 18%, transparent 82%, rgba(255, 255, 240, 0.08)),
    linear-gradient(180deg, rgba(255, 250, 222, 0.16), transparent 30%, rgba(91, 56, 11, 0.12));
}

body.dark .table {
  background:
    linear-gradient(145deg, rgba(255, 219, 128, 0.1), transparent 32%),
    repeating-linear-gradient(45deg, transparent 0 10px, var(--felt-grain) 11px 12px),
    repeating-linear-gradient(135deg, transparent 0 14px, rgba(0, 0, 0, 0.08) 15px 16px),
    linear-gradient(160deg, var(--felt), var(--felt-deep));
}

body.dark .table::before {
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.035),
    inset 0 0 40px rgba(0, 0, 0, 0.18);
}

body.dark .table::after {
  background:
    linear-gradient(90deg, rgba(255, 228, 145, 0.08), transparent 18%, transparent 82%, rgba(255, 228, 145, 0.06)),
    linear-gradient(180deg, rgba(255, 245, 204, 0.08), transparent 26%, rgba(0, 0, 0, 0.18));
}

.table > * {
  position: relative;
  z-index: 1;
}

.victory-burst {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.9);
}

.victory-burst::before {
  content: "";
  position: absolute;
  width: min(62vw, 420px);
  aspect-ratio: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(255, 246, 198, 0.72), rgba(241, 200, 106, 0.34) 32%, transparent 68%);
  filter: blur(2px);
  transform: scale(0.42);
}

.victory-burst::after {
  content: "";
  position: absolute;
  width: min(70vw, 520px);
  aspect-ratio: 1;
  border: 1px solid rgba(241, 200, 106, 0.42);
  border-radius: 999px;
  box-shadow:
    inset 0 0 22px rgba(241, 200, 106, 0.16),
    0 0 34px rgba(241, 200, 106, 0.22);
  transform: scale(0.5);
}

.victory-burst span {
  position: relative;
  padding: 10px 22px;
  border: 1px solid var(--gold-line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
  font-size: clamp(1.45rem, 5vw, 3rem);
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255, 247, 213, 0.5);
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 218, 0.5),
    0 18px 40px rgba(0, 0, 0, 0.28),
    0 0 32px rgba(241, 200, 106, 0.24);
}

.victory-burst.show {
  animation: victory-burst 1450ms ease both;
}

.victory-burst.show::before {
  animation: victory-glow 1450ms ease both;
}

.victory-burst.show::after {
  animation: victory-ring 1450ms ease both;
}

.victory-burst.show span {
  animation: victory-title 1450ms cubic-bezier(0.2, 1, 0.26, 1) both;
}

.round {
  display: grid;
  gap: 4px;
}

.turn-score {
  display: grid;
  gap: 2px;
  min-width: 130px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.1), transparent),
    var(--card);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 180, 0.035);
}

.turn-score[hidden] {
  display: none;
}

.round strong {
  font-size: 2.4rem;
  line-height: 1;
}

.turn-score strong {
  font-size: 1.8rem;
  line-height: 1;
}

.die {
  width: min(72vw, 330px);
  min-height: min(36vw, 145px);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 120ms ease,
    opacity 120ms ease;
}

.die.rolling .die-face {
  animation: roll-die 1.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.die[data-dice-count="1"] {
  gap: 0;
}

.die[data-dice-count="2"] {
  gap: 18px;
}

.die:hover:not(:disabled) {
  transform: translateY(-3px) rotate(-1deg);
}

.die:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
}

.die:disabled,
.controls button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.die-face {
  width: min(36vw, 145px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12%;
  flex: 0 0 auto;
  padding: 14%;
  border-radius: 22px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.9), transparent 0 16%, transparent 28%),
    linear-gradient(145deg, #fffaf0 0%, #f6dda0 35%, #cf9938 70%, #6c4212 100%);
  color: #070604;
  box-shadow:
    inset 10px 10px 18px rgba(255, 255, 255, 0.5),
    inset -12px -16px 18px rgba(48, 27, 5, 0.34),
    inset 0 0 0 1px rgba(255, 248, 218, 0.32),
    0 18px 34px var(--die-shadow),
    0 0 24px rgba(217, 168, 68, 0.13);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

body:not(.dark) .die-face {
  box-shadow:
    inset 10px 10px 18px rgba(255, 255, 255, 0.58),
    inset -10px -14px 16px rgba(95, 55, 8, 0.25),
    inset 0 0 0 1px rgba(255, 248, 218, 0.45),
    0 16px 28px rgba(68, 42, 8, 0.18),
    0 0 18px rgba(176, 112, 22, 0.1);
}

.die-face::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 18%;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.5), transparent 30%),
    linear-gradient(315deg, rgba(0, 0, 0, 0.2), transparent 34%);
  opacity: 0.62;
}

.die-face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.36),
    inset 0 -5px 8px rgba(0, 0, 0, 0.2);
}

.die[data-dice-count="1"] .primary {
  width: min(36vw, 145px);
  transform: translateX(0);
}

.die[data-dice-count="1"] .secondary {
  width: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateX(30px) scale(0.82);
}

.die[data-dice-count="2"] .primary {
  width: min(30vw, 132px);
  transform: translateX(-4px);
}

.die[data-dice-count="2"] .secondary {
  width: min(30vw, 132px);
  opacity: 1;
  transform: translateX(4px) scale(1);
}

.die-face i {
  width: 100%;
  aspect-ratio: 1;
  align-self: center;
  justify-self: center;
  position: relative;
  z-index: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle at 34% 28%, #33312c, #050403 64%, #000 100%);
  box-shadow:
    inset 0 3px 5px rgba(255, 255, 255, 0.16),
    inset 0 -3px 4px rgba(0, 0, 0, 0.68),
    0 1px 0 rgba(255, 246, 210, 0.34),
    0 -1px 1px rgba(0, 0, 0, 0.3);
  opacity: 0;
}

.die-face[data-value="1"] i:nth-child(5),
.die-face[data-value="2"] i:nth-child(1),
.die-face[data-value="2"] i:nth-child(9),
.die-face[data-value="3"] i:nth-child(1),
.die-face[data-value="3"] i:nth-child(5),
.die-face[data-value="3"] i:nth-child(9),
.die-face[data-value="4"] i:nth-child(1),
.die-face[data-value="4"] i:nth-child(3),
.die-face[data-value="4"] i:nth-child(7),
.die-face[data-value="4"] i:nth-child(9),
.die-face[data-value="5"] i:nth-child(1),
.die-face[data-value="5"] i:nth-child(3),
.die-face[data-value="5"] i:nth-child(5),
.die-face[data-value="5"] i:nth-child(7),
.die-face[data-value="5"] i:nth-child(9),
.die-face[data-value="6"] i:nth-child(1),
.die-face[data-value="6"] i:nth-child(3),
.die-face[data-value="6"] i:nth-child(4),
.die-face[data-value="6"] i:nth-child(6),
.die-face[data-value="6"] i:nth-child(7),
.die-face[data-value="6"] i:nth-child(9) {
  opacity: 1;
}

.dice-hint {
  max-width: 320px;
  margin: -6px 0 0;
  color: #4d3a1c;
  font-size: 0.92rem;
  line-height: 1.35;
  text-shadow: 0 1px 0 rgba(255, 246, 210, 0.4);
}

.message {
  min-height: 42px;
  margin: 0;
  color: #4d3a1c;
  font-size: 1.05rem;
  line-height: 1.45;
  text-shadow: 0 1px 0 rgba(255, 246, 210, 0.36);
}

body.dark .dice-hint,
body.dark .message {
  color: var(--muted);
  text-shadow: none;
}

.message.win-message {
  color: var(--gold);
  font-weight: 900;
  animation: win-message-pop 1200ms ease;
  text-shadow: 0 0 16px rgba(241, 200, 106, 0.3);
}

.table.win-flash {
  animation: table-win-flash 1450ms ease;
}

.dice-switcher {
  width: min(100%, 260px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 231, 153, 0.08), transparent),
    var(--card);
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 180, 0.035),
    0 10px 22px rgba(0, 0, 0, 0.12);
}

.dice-switcher .theme-option {
  min-width: 0;
}

.controls {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

body.gamble-mode .controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.gamble-mode #newGameButton {
  grid-column: 1;
}

body.gamble-mode #bankButton {
  width: 100%;
  grid-column: 2;
  grid-row: 1;
  justify-self: stretch;
}

body.gamble-mode #resetWinsButton {
  grid-column: 3;
}

.controls button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--metal-top), var(--metal-mid) 58%, var(--metal-low));
  color: var(--button-ink);
  cursor: pointer;
  font-weight: 800;
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 210, 0.35),
    0 10px 22px rgba(34, 19, 4, 0.18);
}

.controls button:hover:not(:disabled) {
  background:
    linear-gradient(180deg, #f3cf74, var(--green-dark) 62%, var(--metal-low));
}

#newGameButton {
  background:
    linear-gradient(180deg, rgba(255, 235, 168, 0.18), rgba(0, 0, 0, 0.08)),
    #292015;
  color: var(--ink);
}

body:not(.dark) #newGameButton {
  background:
    linear-gradient(180deg, #8b6428, #4d3516);
  color: #fff6df;
}

#bankButton {
  background:
    linear-gradient(180deg, #f7df92, var(--gold) 58%, #96651b);
  color: var(--button-ink);
}

#bankButton:hover:not(:disabled) {
  background: #f0b44b;
}

body.dark #newGameButton {
  background:
    linear-gradient(180deg, rgba(255, 235, 168, 0.12), rgba(255, 235, 168, 0.02)),
    #2b261a;
}

#resetWinsButton {
  background:
    linear-gradient(180deg, rgba(255, 252, 230, 0.18), rgba(0, 0, 0, 0.08)),
    #756b56;
  color: #fff4d7;
}

body:not(.dark) #resetWinsButton {
  background:
    linear-gradient(180deg, #9b927d, #645b48);
  color: #fff6df;
}

#resetWinsButton:hover:not(:disabled) {
  background:
    linear-gradient(180deg, rgba(255, 252, 230, 0.16), rgba(0, 0, 0, 0.12)),
    #5f543f;
}

.rules {
  grid-column: 1 / -1;
  padding: 14px 18px;
  position: relative;
  overflow: hidden;
}

.rules::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(211, 157, 53, 0.18);
  pointer-events: none;
}

.copyright {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.rules h1 {
  margin: 0 0 5px;
  font-size: clamp(1.25rem, 2.35vw, 1.9rem);
  line-height: 1.12;
  white-space: nowrap;
  color: var(--ink);
  text-shadow:
    0 1px 0 #8c5d19,
    0 0 18px rgba(217, 168, 68, 0.24);
}

.rules p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.shake {
  animation: shake 260ms ease;
}

.bad-roll {
  color: var(--red);
}

@keyframes shake {
  0%,
  100% {
    transform: rotate(0);
  }

  25% {
    transform: rotate(-8deg);
  }

  75% {
    transform: rotate(8deg);
  }
}

@keyframes winner-pop {
  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow: inset 0 0 0 2px rgba(216, 154, 43, 0.22);
  }

  35% {
    transform: translateY(-4px) scale(1.015);
    box-shadow:
      inset 0 0 0 2px rgba(216, 154, 43, 0.35),
      0 0 34px rgba(216, 154, 43, 0.32);
  }

  68% {
    transform: translateY(0) scale(1.006);
  }
}

@keyframes table-win-flash {
  0%,
  100% {
    box-shadow: 0 20px 60px var(--shadow);
  }

  42% {
    box-shadow:
      0 20px 60px var(--shadow),
      inset 0 0 0 2px rgba(216, 154, 43, 0.22),
      0 0 28px rgba(216, 154, 43, 0.18);
  }
}

@keyframes victory-burst {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.92);
  }

  14%,
  72% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes victory-glow {
  0% {
    opacity: 0;
    transform: scale(0.25);
  }

  28% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(1.25);
  }
}

@keyframes victory-ring {
  0% {
    opacity: 0;
    transform: scale(0.48);
  }

  32% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(1.08);
  }
}

@keyframes victory-title {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.86);
  }

  20% {
    opacity: 1;
    transform: translateY(0) scale(1.04);
  }

  58% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
}

@keyframes win-message-pop {
  0%,
  100% {
    transform: scale(1);
  }

  38% {
    transform: scale(1.05);
  }
}

@keyframes roll-die {
  0% {
    transform: translateY(0) rotate(0) scale(1);
  }

  18% {
    transform: translateY(-16px) rotate(90deg) scale(1.04);
  }

  38% {
    transform: translateY(8px) rotate(180deg) scale(0.98);
  }

  62% {
    transform: translateY(-10px) rotate(285deg) scale(1.03);
  }

  82% {
    transform: translateY(4px) rotate(340deg) scale(0.99);
  }

  100% {
    transform: translateY(0) rotate(360deg) scale(1);
  }
}

@media (max-width: 720px) {
  html {
    background: var(--bg-end);
  }

  body {
    align-items: start;
    padding:
      calc(env(safe-area-inset-top, 0px) + 16px)
      0
      calc(env(safe-area-inset-bottom, 0px) + 12px);
  }

  .game {
    width: min(100vw - 16px, 520px);
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .topbar {
    position: static;
    padding: 8px 10px;
  }

  .menu-trigger {
    width: 100%;
  }

  .menu-shell {
    position: static;
  }

  .menu-panel {
    position: absolute;
    top: calc(100% - 1px);
    left: 50%;
    right: auto;
    width: min(100vw - 32px, 420px);
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
    overflow-y: auto;
    transform: translateX(-50%);
  }

  .top-actions {
    width: 100%;
    position: relative;
  }

  .info-panel {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .menu-shell.menu-open .menu-panel,
  .info-shell.menu-open .info-panel {
    transform: translateX(-50%);
  }

  .setting {
    width: 100%;
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 8px;
  }

  .topbar span,
  .topbar label {
    align-self: center;
    font-size: 0.68rem;
    letter-spacing: 0.035em;
  }

  .theme-switcher,
  .score-setting {
    width: 100%;
  }

  .theme-option {
    min-height: 34px;
    min-width: 0;
    padding: 0 8px;
    font-size: 0.88rem;
  }

  .score-setting input,
  .score-setting button {
    min-height: 40px;
  }

  .scoreboard {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
  }

  .player {
    min-height: 118px;
    padding: 12px;
    gap: 6px;
  }

  .starter-button {
    min-height: 28px;
    font-size: 0.62rem;
    padding: 3px 8px;
  }

  .player strong {
    font-size: clamp(2.7rem, 16vw, 4.2rem);
  }

  .opponent-top {
    gap: 6px;
  }

  .mini-switcher {
    width: 100%;
    gap: 3px;
    padding: 3px;
  }

  .mini-switcher .theme-option {
    min-height: 32px;
    padding: 0 4px;
    font-size: clamp(0.68rem, 2.8vw, 0.82rem);
    letter-spacing: 0;
    white-space: nowrap;
  }

  .table {
    gap: 12px;
    padding: 16px 10px;
  }

  body.gamble-mode .table {
    gap: 9px;
    padding: 12px 10px;
  }

  .round strong {
    font-size: 2.4rem;
  }

  .turn-score strong {
    font-size: 1.55rem;
  }

  body.gamble-mode .turn-score {
    min-width: 112px;
    padding: 6px 12px;
  }

  .message {
    min-height: 42px;
    font-size: 0.95rem;
  }

  .die {
    width: min(92vw, 330px);
    min-height: 122px;
    gap: 10px;
  }

  .die[data-dice-count="1"] .primary {
    width: min(46vw, 145px);
  }

  .die[data-dice-count="2"] .primary,
  .die[data-dice-count="2"] .secondary {
    width: min(39vw, 132px);
  }

  .dice-switcher,
  .controls {
    width: 100%;
  }

  .controls button {
    min-height: 44px;
  }

  body.gamble-mode .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  body.gamble-mode #bankButton {
    width: 100%;
    grid-column: 2;
    grid-row: 1;
    justify-self: stretch;
  }

  .rules {
    padding: 14px;
  }

  .copyright {
    font-size: 0.76rem;
  }

  .rules h1 {
    font-size: clamp(0.95rem, 4.4vw, 1.4rem);
    white-space: nowrap;
  }

  .rules p {
    font-size: 0.92rem;
  }
}

@media (max-width: 460px) {
  .menu-panel {
    width: min(100vw - 24px, 390px);
  }

  .setting {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .scoreboard {
    gap: 6px;
    padding: 8px;
  }

  .player {
    padding: 10px;
  }

  .mini-switcher .theme-option {
    font-size: clamp(0.62rem, 2.65vw, 0.76rem);
  }

  .rules h1 {
    font-size: clamp(0.78rem, 3.9vw, 1rem);
  }
}

@media (max-width: 360px) {
  .scoreboard {
    grid-template-columns: 1fr;
  }

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

  .rules h1 {
    white-space: normal;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  html {
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    overflow: hidden;
  }

  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    align-items: start;
    overflow: hidden;
    padding:
      max(env(safe-area-inset-top, 0px), 8px)
      max(env(safe-area-inset-right, 0px), 10px)
      max(env(safe-area-inset-bottom, 0px), 8px)
      max(env(safe-area-inset-left, 0px), 10px);
  }

  .game {
    width: min(100%, 1040px);
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(118px, 0.56fr) minmax(320px, 1.55fr) minmax(118px, 0.56fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar topbar"
      "human table computer";
    gap: 10px;
    align-items: stretch;
  }

  .topbar {
    grid-area: topbar;
  }

  .topbar {
    padding: 6px 8px;
  }

  .menu-trigger {
    min-height: 34px;
    font-size: 0.82rem;
  }

  .menu-panel {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 52px);
    left: 50%;
    width: min(calc(100vw - 32px), 520px);
    max-height: calc(100dvh - 68px);
    padding: 8px;
    overflow-y: auto;
    z-index: 60;
    transform: translateX(-50%);
  }

  .info-panel {
    overflow: hidden;
  }

  .menu-shell.menu-open .menu-panel,
  .info-shell.menu-open .info-panel,
  .menu-shell:hover .menu-panel,
  .info-shell:hover .info-panel {
    transform: translateX(-50%);
  }

  .setting {
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 8px;
  }

  .topbar span,
  .topbar label {
    font-size: 0.72rem;
  }

  .theme-option,
  .score-setting input,
  .score-setting button {
    min-height: 34px;
    font-size: 0.9rem;
  }

  .scoreboard {
    display: contents;
  }

  .player {
    min-width: 0;
    min-height: 118px;
    padding: 10px 7px;
    gap: 6px;
  }

  #humanPanel {
    grid-area: human;
  }

  #computerPanel {
    grid-area: computer;
  }

  .player strong {
    font-size: clamp(2.35rem, 7vw, 3.4rem);
  }

  .player span {
    font-size: 0.82rem;
  }

  .wins {
    max-width: 118px;
    min-height: 38px;
    padding: 7px 8px;
  }

  .wins span {
    font-size: 0.66rem;
  }

  .wins strong {
    font-size: 1.05rem;
  }

  .table {
    grid-area: table;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    grid-template-columns: 1fr;
    grid-template-areas:
      "last"
      "turn"
      "dice"
      "hint"
      "switcher"
      "message"
      "controls";
    align-content: center;
    align-items: center;
    justify-items: center;
    gap: 5px;
    padding: 8px 6px;
  }

  .round {
    grid-area: last;
  }

  .turn-score {
    grid-area: turn;
  }

  .die {
    grid-area: dice;
    justify-self: center;
  }

  .dice-hint {
    grid-area: hint;
    justify-self: center;
    margin-top: 4px;
  }

  .dice-switcher,
  .message,
  .controls {
    width: min(100%, 360px);
    justify-self: center;
  }

  .dice-switcher {
    grid-area: switcher;
  }

  .message {
    grid-area: message;
  }

  .controls {
    grid-area: controls;
  }

  body.gamble-mode .table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto minmax(86px, 1fr) auto auto auto;
    grid-template-areas:
      "last turn"
      "dice dice"
      "switcher switcher"
      "message message"
      "controls controls";
    align-content: stretch;
    gap: 8px 12px;
    padding: clamp(12px, 3vh, 18px) 8px 10px;
  }

  body.gamble-mode .round {
    justify-self: end;
  }

  body.gamble-mode .turn-score {
    justify-self: start;
  }

  .round strong {
    font-size: 1.65rem;
  }

  .turn-score {
    min-width: 0;
    padding: 6px 10px;
  }

  body.gamble-mode .round span,
  body.gamble-mode .turn-score span {
    font-size: 0.7rem;
  }

  .turn-score strong {
    font-size: 1.25rem;
  }

  body.gamble-mode .round strong,
  body.gamble-mode .turn-score strong {
    font-size: 1.22rem;
  }

  .die {
    width: min(100%, 260px);
    min-height: 88px;
  }

  body.gamble-mode .die {
    width: min(100%, 250px);
    min-height: 76px;
    align-self: center;
    margin-top: 8px;
    margin-bottom: 8px;
  }

  .die[data-dice-count="1"] .primary {
    width: min(20vw, 116px);
  }

  .die[data-dice-count="2"] .primary,
  .die[data-dice-count="2"] .secondary {
    width: min(15vw, 104px);
  }

  body.gamble-mode .die[data-dice-count="1"] .primary {
    width: min(18vw, 104px);
  }

  body.gamble-mode .die[data-dice-count="2"] .primary,
  body.gamble-mode .die[data-dice-count="2"] .secondary {
    width: min(13vw, 92px);
  }

  .dice-hint,
  .message,
  .rules p {
    font-size: 0.72rem;
  }

  .dice-hint,
  .message {
    width: 100%;
    max-width: 100%;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  body.gamble-mode .dice-hint {
    display: none;
  }

  .message {
    min-height: 24px;
  }

  body.gamble-mode .message {
    width: min(100%, 430px);
    min-height: 18px;
    font-size: 0.68rem;
    line-height: 1.15;
    margin: 0;
  }

  .dice-switcher {
    padding: 3px;
    gap: 3px;
  }

  .dice-switcher .theme-option {
    min-height: 28px;
    padding: 0 4px;
    font-size: 0.76rem;
  }

  body.gamble-mode .dice-switcher {
    width: min(100%, 360px);
    margin-top: 4px;
  }

  body.gamble-mode .dice-switcher .theme-option {
    min-height: 26px;
    font-size: 0.72rem;
  }

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

  #newGameButton {
    grid-column: 1;
  }

  #resetWinsButton {
    grid-column: 2;
  }

  body.gamble-mode .controls {
    width: min(100%, 380px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    align-self: end;
    margin-top: 8px;
  }

  body.gamble-mode #newGameButton {
    grid-column: 1;
  }

  body.gamble-mode #bankButton {
    width: 100%;
    grid-column: 2;
    grid-row: 1;
    justify-self: stretch;
  }

  body.gamble-mode #resetWinsButton {
    grid-column: 3;
  }

  .controls button {
    min-height: 32px;
    padding: 0 6px;
    font-size: 0.74rem;
  }

  body.gamble-mode .controls button {
    min-height: 28px;
    padding: 0 4px;
    font-size: 0.68rem;
  }

  .rules {
    display: none;
  }

  .copyright {
    display: none;
  }
}

