:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #191d24;
  --panel-soft: #222833;
  --surface: #11161d;
  --surface-strong: #12161c;
  --ink: #f6f2e9;
  --muted: #b8c1cc;
  --line: rgba(255, 255, 255, 0.16);
  --soft-line: rgba(255, 255, 255, 0.1);
  --gold: #d4a84f;
  --primary-ink: #181409;
  --white-piece: #f2eadb;
  --white-piece-edge: #c7b896;
  --black-piece: #1c2129;
  --black-piece-edge: #090b0f;
  --light-square: #d8c19a;
  --dark-square: #4a765c;
  --dark-square-alt: #3c644f;
  --target: #f0cf68;
  --shadow: rgba(0, 0, 0, 0.34);
  --body-gold-wash: rgba(212, 168, 79, 0.08);
  --body-green-wash: rgba(74, 118, 92, 0.12);
  --setup-vignette: radial-gradient(circle at 50% 42%, rgba(10, 13, 17, 0.18), rgba(7, 9, 12, 0.68) 72%);
  --setup-wash: linear-gradient(180deg, rgba(9, 11, 15, 0.36), rgba(9, 11, 15, 0.78));
  --setup-card-shadow: rgba(0, 0, 0, 0.52);
  --topbar-start: rgba(17, 19, 24, 0.98);
  --topbar-mid: rgba(17, 19, 24, 0.9);
  --topbar-end: rgba(17, 19, 24, 0);
  --dock-bg: rgba(25, 29, 36, 0.94);
  --panel-bg: rgba(25, 29, 36, 0.92);
  --board-rail: #292017;
  --arrow-outline: rgba(17, 19, 24, 0.14);
  --selection-inset: rgba(17, 19, 24, 0.22);
  --selection-active-inset: rgba(17, 19, 24, 0.24);
  --subtle-fill: rgba(255, 255, 255, 0.08);
  --token-fill: rgba(255, 255, 255, 0.06);
  --move-empty: rgba(184, 193, 204, 0.58);
  --scrollbar: rgba(255, 255, 255, 0.24);
  --overlay-bg: rgba(5, 7, 10, 0.66);
  --danger-line: rgba(200, 70, 70, 0.7);
  --danger-soft: rgba(200, 70, 70, 0.16);
  --danger-text: #ffb8b8;
  --danger-token: rgba(200, 70, 70, 0.12);
  --danger-ink: #ffcdcd;
  --luxury-void: #070908;
  --luxury-velvet: #102018;
  --luxury-emerald: #173f30;
  --luxury-wine: #5f1d2b;
  --luxury-brass: #e2bd6b;
  --luxury-brass-soft: rgba(226, 189, 107, 0.24);
  --luxury-glass: rgba(11, 15, 14, 0.78);
  --luxury-ivory: #fff4dc;
  --luxury-table-line: rgba(255, 230, 170, 0.24);
  --viewport-width: 100vw;
  --viewport-height: 100dvh;
  --screen-width: 100vw;
  --screen-height: 100dvh;
  --app-gutter: clamp(10px, 1.7vw, 24px);
  --app-width: min(1500px, calc(var(--viewport-width) - var(--app-gutter) - var(--app-gutter)));
  --side-panel-width: clamp(320px, 24vw, 360px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef4ef;
  --panel: #ffffff;
  --panel-soft: #e9f1eb;
  --surface: #f7faf6;
  --surface-strong: #edf4ef;
  --ink: #17231f;
  --muted: #60726a;
  --line: rgba(24, 48, 42, 0.18);
  --soft-line: rgba(24, 48, 42, 0.11);
  --gold: #b8822b;
  --primary-ink: #241707;
  --white-piece: #fff4df;
  --white-piece-edge: #c7aa78;
  --black-piece: #263238;
  --black-piece-edge: #11181c;
  --light-square: #ead2a1;
  --dark-square: #5f8b6d;
  --dark-square-alt: #4f7c61;
  --target: #d19622;
  --shadow: rgba(35, 55, 46, 0.18);
  --body-gold-wash: rgba(184, 130, 43, 0.14);
  --body-green-wash: rgba(79, 124, 97, 0.18);
  --setup-vignette: radial-gradient(circle at 50% 38%, rgba(255, 250, 236, 0.34), rgba(238, 244, 239, 0.42) 68%);
  --setup-wash: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(232, 241, 234, 0.46));
  --setup-card-shadow: rgba(56, 76, 66, 0.24);
  --topbar-start: rgba(238, 244, 239, 0.98);
  --topbar-mid: rgba(238, 244, 239, 0.9);
  --topbar-end: rgba(238, 244, 239, 0);
  --dock-bg: rgba(255, 255, 255, 0.9);
  --panel-bg: rgba(255, 255, 255, 0.88);
  --board-rail: #5b4931;
  --arrow-outline: rgba(255, 255, 255, 0.52);
  --selection-inset: rgba(255, 255, 255, 0.52);
  --selection-active-inset: rgba(60, 45, 20, 0.2);
  --subtle-fill: rgba(24, 48, 42, 0.07);
  --token-fill: rgba(24, 48, 42, 0.055);
  --move-empty: rgba(96, 114, 106, 0.6);
  --scrollbar: rgba(24, 48, 42, 0.3);
  --overlay-bg: rgba(20, 26, 24, 0.38);
  --danger-line: rgba(178, 52, 52, 0.46);
  --danger-soft: rgba(178, 52, 52, 0.12);
  --danger-text: #8f2525;
  --danger-token: rgba(178, 52, 52, 0.1);
  --danger-ink: #8f2525;
  --luxury-void: #e7eee7;
  --luxury-velvet: #dfeade;
  --luxury-emerald: #62806f;
  --luxury-wine: #b06a78;
  --luxury-brass: #a86f1f;
  --luxury-brass-soft: rgba(168, 111, 31, 0.2);
  --luxury-glass: rgba(255, 255, 255, 0.82);
  --luxury-ivory: #20180c;
  --luxury-table-line: rgba(76, 58, 31, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  min-height: 100vh;
  min-height: var(--viewport-height);
  margin: 0;
  background:
    linear-gradient(135deg, var(--body-gold-wash), transparent 34%),
    linear-gradient(315deg, var(--body-green-wash), transparent 38%),
    var(--bg);
  color: var(--ink);
}

:root[data-screen="setup"] body {
  background:
    var(--setup-vignette),
    var(--setup-wash),
    url("./assets/setup-background.png") center / cover no-repeat fixed,
    var(--bg);
}

:root[data-screen="game"] body {
  background:
    linear-gradient(180deg, rgba(4, 6, 6, 0.58), rgba(4, 6, 6, 0.86)),
    radial-gradient(ellipse at 50% 0%, rgba(226, 189, 107, 0.16), transparent 42%),
    linear-gradient(120deg, rgba(16, 32, 24, 0.78), rgba(95, 29, 43, 0.26) 48%, rgba(6, 8, 9, 0.88)),
    url("./assets/setup-background.png") center / cover no-repeat fixed,
    var(--luxury-void);
}

:root[data-theme="light"][data-screen="game"] body {
  background:
    linear-gradient(180deg, rgba(244, 248, 242, 0.38), rgba(238, 244, 239, 0.74)),
    radial-gradient(ellipse at 50% 0%, rgba(168, 111, 31, 0.18), transparent 46%),
    linear-gradient(120deg, rgba(223, 234, 222, 0.82), rgba(176, 106, 120, 0.18) 50%, rgba(246, 249, 246, 0.88)),
    url("./assets/setup-background.png") center / cover no-repeat fixed,
    var(--luxury-void);
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app {
  position: relative;
  z-index: 0;
  width: var(--app-width);
  margin: 0 auto;
  padding: clamp(12px, 1.8vh, 20px) 0;
}

:root[data-screen="game"] .app {
  --app-width: min(1660px, calc(var(--viewport-width) - var(--app-gutter) - var(--app-gutter)));
  padding-top: clamp(10px, 1.4vh, 18px);
}

:root[data-screen="setup"] .app {
  --app-width: min(1520px, calc(var(--viewport-width) - var(--app-gutter) - var(--app-gutter)));
  display: grid;
  grid-template-rows: auto 1fr;
  padding-top: clamp(10px, 1.2vh, 16px);
}

.topbar {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(10px, 1.5vh, 16px);
  padding-bottom: clamp(10px, 1.5vh, 14px);
  background: linear-gradient(180deg, var(--topbar-start) 0%, var(--topbar-mid) 76%, var(--topbar-end) 100%);
  backdrop-filter: blur(8px);
}

:root[data-screen="game"] .topbar {
  align-items: center;
  margin-bottom: clamp(12px, 1.8vh, 22px);
  border: 1px solid rgba(226, 189, 107, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(226, 189, 107, 0.14), transparent 30%),
    linear-gradient(180deg, color-mix(in srgb, var(--luxury-glass) 92%, transparent), color-mix(in srgb, var(--surface) 62%, transparent));
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: clamp(8px, 1.1vh, 12px);
  backdrop-filter: blur(18px) saturate(1.2);
}

:root[data-theme="light"][data-screen="game"] .topbar {
  border-color: rgba(168, 111, 31, 0.22);
  background:
    linear-gradient(90deg, rgba(168, 111, 31, 0.12), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(239, 245, 239, 0.76));
  box-shadow: 0 18px 42px rgba(64, 79, 70, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

:root[data-screen="setup"] .topbar {
  align-items: center;
  margin-bottom: clamp(8px, 1.2vh, 14px);
  border: 1px solid rgba(226, 189, 107, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(226, 189, 107, 0.12), transparent 34%),
    linear-gradient(180deg, color-mix(in srgb, var(--luxury-glass) 86%, transparent), color-mix(in srgb, var(--surface) 58%, transparent));
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: clamp(8px, 1vh, 11px);
  backdrop-filter: blur(16px) saturate(1.14);
}

:root[data-theme="light"][data-screen="setup"] .topbar {
  border-color: rgba(168, 111, 31, 0.18);
  background:
    linear-gradient(90deg, rgba(168, 111, 31, 0.1), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(239, 245, 239, 0.72));
  box-shadow: 0 16px 40px rgba(64, 79, 70, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.top-controls {
  display: flex;
  min-width: min(708px, 100%);
  align-items: stretch;
  gap: 8px;
}

:root[data-screen="setup"] .top-controls {
  min-width: 0;
  flex: 0 0 auto;
  justify-content: end;
}

:root[data-screen="setup"] .meters {
  display: none;
}

:root[data-screen="setup"] .utility-dock {
  justify-self: end;
}

.utility-dock {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--dock-bg);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  padding: 5px;
}

.language-switcher {
  position: relative;
  display: grid;
}

.language-switcher::after {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  color: var(--muted);
  content: "";
  pointer-events: none;
  transform: translateY(-64%) rotate(45deg);
}

.language-select {
  width: 150px;
  height: 44px;
  appearance: none;
  border: 1px solid rgba(212, 168, 79, 0.44);
  border-radius: 8px;
  background: rgba(212, 168, 79, 0.1);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 900;
  line-height: 1.1;
  padding: 0 28px 0 10px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.language-select:hover {
  border-color: rgba(212, 168, 79, 0.76);
  background: rgba(212, 168, 79, 0.16);
  transform: translateY(-1px);
}

.language-select:focus-visible {
  outline: 0;
  border-color: rgba(212, 168, 79, 0.86);
  box-shadow: 0 0 0 3px rgba(212, 168, 79, 0.12);
}

.language-select option {
  background: var(--panel);
  color: var(--ink);
}

h1,
h2,
p,
dl,
dd,
ol {
  margin: 0;
}

h1 {
  font-size: 2.5rem;
  line-height: 1;
}

:root[data-screen="game"] h1 {
  color: var(--luxury-ivory);
  font-size: clamp(1.65rem, 2.4vw, 2.85rem);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.32), 0 18px 36px rgba(0, 0, 0, 0.42);
}

:root[data-screen="setup"] h1 {
  color: var(--luxury-ivory);
  font-size: clamp(1.65rem, 2.4vw, 2.8rem);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.32), 0 16px 34px rgba(0, 0, 0, 0.38);
}

:root[data-theme="light"][data-screen="game"] h1 {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.84), 0 14px 28px rgba(76, 95, 83, 0.18);
}

:root[data-theme="light"][data-screen="setup"] h1 {
  color: var(--luxury-ivory);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.84), 0 14px 28px rgba(76, 95, 83, 0.16);
}

h2 {
  font-size: 0.95rem;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 8px;
  flex: 1 1 auto;
  min-width: min(440px, 100%);
}

.meters div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px 10px;
}

:root[data-screen="game"] .meters div {
  position: relative;
  overflow: hidden;
  border-color: rgba(226, 189, 107, 0.26);
  background:
    linear-gradient(135deg, rgba(226, 189, 107, 0.16), transparent 46%),
    color-mix(in srgb, var(--surface-strong) 88%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 12px 24px rgba(0, 0, 0, 0.22);
}

:root[data-theme="light"][data-screen="game"] .meters div {
  border-color: rgba(168, 111, 31, 0.18);
  background:
    linear-gradient(135deg, rgba(168, 111, 31, 0.1), transparent 48%),
    rgba(255, 255, 255, 0.76);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86), 0 10px 22px rgba(64, 79, 70, 0.14);
}

:root[data-screen="game"] .meters div::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, transparent, var(--luxury-brass), transparent);
  content: "";
}

dt {
  color: var(--muted);
  font-size: 0.75rem;
}

dd {
  margin-top: 3px;
  font-size: 1.05rem;
  font-weight: 850;
}

.play-area {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-panel-width);
  gap: clamp(14px, 1.7vw, 28px);
  align-items: start;
  min-height: 0;
}

:root[data-screen="game"] .play-area {
  --side-panel-width: clamp(300px, 22vw, 390px);
}

.setup-screen {
  display: grid;
  min-height: max(0px, calc(var(--viewport-height) - clamp(144px, 14vh, 178px)));
  align-items: center;
  padding: clamp(4px, 1vh, 10px) 0 clamp(12px, 2vh, 24px);
}

.setup-stage {
  display: grid;
  width: 100%;
  gap: clamp(18px, 3vw, 44px);
}

:root[data-screen="setup"] .setup-stage {
  grid-template-columns: minmax(280px, 0.88fr) minmax(640px, 1.18fr);
  align-items: center;
}

.setup-intro {
  display: grid;
  max-width: 760px;
  justify-self: center;
  gap: 8px;
  text-align: center;
}

:root[data-screen="setup"] .setup-intro {
  max-width: 620px;
  justify-self: start;
  gap: clamp(10px, 1.4vh, 16px);
  text-align: left;
}

.setup-kicker {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

:root[data-screen="setup"] .setup-kicker {
  display: inline-grid;
  width: max-content;
  min-height: 28px;
  align-items: center;
  border: 1px solid rgba(226, 189, 107, 0.36);
  border-radius: 999px;
  background: rgba(226, 189, 107, 0.12);
  color: var(--luxury-brass);
  padding: 0 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"][data-screen="setup"] .setup-kicker {
  color: #80520f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.82), 0 8px 18px rgba(255, 255, 255, 0.58);
}

.setup-intro h2 {
  font-size: clamp(1.7rem, 4vw, 3.25rem);
  line-height: 1.08;
  padding-bottom: 2px;
}

:root[data-screen="setup"] .setup-intro h2 {
  color: var(--luxury-ivory);
  font-size: clamp(2rem, 4.4vw, 4.75rem);
  line-height: 0.98;
  text-wrap: balance;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.34), 0 22px 52px rgba(0, 0, 0, 0.46);
}

:root[data-theme="light"][data-screen="setup"] .setup-intro h2 {
  color: var(--luxury-ivory);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.82), 0 18px 38px rgba(76, 95, 83, 0.2);
}

.setup-content {
  display: grid;
  position: relative;
  min-height: min(520px, max(0px, calc(var(--viewport-height) - 330px)));
  grid-template-columns: 1fr;
  gap: clamp(18px, 3vw, 34px);
  align-items: center;
  justify-items: center;
}

:root[data-screen="setup"] .setup-content {
  min-height: 0;
  align-items: center;
  justify-items: end;
}

.setup-card {
  display: grid;
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-bg) 86%, transparent);
  box-shadow: 0 24px 70px var(--setup-card-shadow);
  backdrop-filter: blur(12px);
}

:root[data-screen="setup"] .setup-card {
  width: min(100%, 930px);
  overflow: visible;
  gap: 0;
  border-color: rgba(226, 189, 107, 0.28);
  background:
    linear-gradient(145deg, rgba(226, 189, 107, 0.13), transparent 28%),
    linear-gradient(315deg, rgba(37, 85, 63, 0.18), rgba(95, 29, 43, 0.1) 62%, transparent),
    color-mix(in srgb, var(--luxury-glass) 88%, transparent);
  box-shadow:
    0 34px 92px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

:root[data-screen="setup"] .setup-card::before {
  position: absolute;
  z-index: 0;
  inset: 8px;
  border: 1px solid rgba(226, 189, 107, 0.14);
  border-radius: 6px;
  content: "";
  pointer-events: none;
}

:root[data-screen="setup"] .setup-card::after {
  position: absolute;
  z-index: 0;
  inset: 0;
  background:
    linear-gradient(90deg, transparent, rgba(226, 189, 107, 0.12), transparent) top / 100% 1px no-repeat,
    radial-gradient(circle at 92% 6%, rgba(226, 189, 107, 0.18), transparent 22%);
  content: "";
  pointer-events: none;
}

:root[data-theme="light"][data-screen="setup"] .setup-card {
  border-color: rgba(168, 111, 31, 0.24);
  background:
    linear-gradient(145deg, rgba(168, 111, 31, 0.12), transparent 30%),
    linear-gradient(315deg, rgba(108, 134, 116, 0.12), rgba(176, 106, 120, 0.09) 60%, transparent),
    rgba(255, 255, 255, 0.78);
  box-shadow:
    0 28px 72px rgba(64, 79, 70, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 0 0 1px rgba(255, 255, 255, 0.36);
}

.board-panel,
.side-panel > section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: 0 18px 42px var(--shadow);
}

.board-panel {
  position: relative;
  overflow: hidden;
  display: grid;
  align-content: start;
  gap: clamp(10px, 1.4vh, 16px);
  min-height: 0;
  padding: clamp(10px, 1.4vh, 14px);
}

:root[data-screen="game"] .board-panel {
  border-color: rgba(226, 189, 107, 0.28);
  background:
    linear-gradient(145deg, rgba(226, 189, 107, 0.12), transparent 26%),
    linear-gradient(315deg, rgba(37, 85, 63, 0.2), rgba(95, 29, 43, 0.12) 58%, transparent),
    color-mix(in srgb, var(--luxury-glass) 86%, transparent);
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  padding: clamp(12px, 1.7vw, 24px);
  backdrop-filter: blur(16px) saturate(1.16);
}

:root[data-theme="light"][data-screen="game"] .board-panel {
  border-color: rgba(168, 111, 31, 0.24);
  background:
    linear-gradient(145deg, rgba(168, 111, 31, 0.12), transparent 30%),
    linear-gradient(315deg, rgba(108, 134, 116, 0.12), rgba(176, 106, 120, 0.1) 58%, transparent),
    rgba(255, 255, 255, 0.76);
  box-shadow:
    0 28px 68px rgba(64, 79, 70, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 0 0 1px rgba(255, 255, 255, 0.36);
}

:root[data-screen="game"] .board-panel::before {
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(226, 189, 107, 0.14);
  border-radius: 6px;
  content: "";
  pointer-events: none;
}

:root[data-screen="game"] .board-panel::after {
  position: absolute;
  inset: auto 8% 0;
  height: 36px;
  background: linear-gradient(90deg, transparent, rgba(226, 189, 107, 0.18), transparent);
  content: "";
  pointer-events: none;
}

.status-row {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 10px 12px;
}

:root[data-screen="game"] .status-row {
  position: relative;
  overflow: hidden;
  border-color: rgba(226, 189, 107, 0.28);
  background:
    linear-gradient(90deg, rgba(226, 189, 107, 0.14), transparent 38%),
    color-mix(in srgb, var(--surface-strong) 88%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 12px 26px rgba(0, 0, 0, 0.22);
}

:root[data-theme="light"][data-screen="game"] .status-row {
  border-color: rgba(168, 111, 31, 0.2);
  background:
    linear-gradient(90deg, rgba(168, 111, 31, 0.11), transparent 42%),
    rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82), 0 10px 22px rgba(64, 79, 70, 0.14);
}

:root[data-screen="game"] .status-row::before {
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--luxury-brass), transparent);
  content: "";
  opacity: 0.72;
}

.status-row p {
  min-width: 0;
  line-height: 1.3;
  font-weight: 800;
}

.badge {
  display: inline-grid;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 44%;
  min-height: 30px;
  place-items: center;
  border: 1px solid var(--danger-line);
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger-text);
  padding: 0 10px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 850;
  line-height: 1.05;
  white-space: normal;
}

.badge[hidden] {
  display: none;
}

.board-frame {
  --label-size: clamp(20px, 2.2vh, 28px);
  --board-max: min(820px, max(360px, calc(var(--viewport-height) - 350px)));
  position: relative;
  isolation: isolate;
  display: grid;
  width: min(100%, calc(var(--board-max) + (var(--label-size) * 2) + 44px));
  justify-self: center;
  grid-template-columns: var(--label-size) minmax(0, var(--board-max)) var(--label-size);
  grid-template-rows: var(--label-size) auto var(--label-size);
  border: 1px solid rgba(226, 189, 107, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(226, 189, 107, 0.18), transparent 24%, rgba(255, 255, 255, 0.04) 48%, transparent 74%, rgba(226, 189, 107, 0.16)),
    linear-gradient(180deg, rgba(8, 12, 10, 0.9), rgba(20, 31, 24, 0.86));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 16px 34px rgba(255, 255, 255, 0.04),
    0 32px 78px rgba(0, 0, 0, 0.52);
  padding: clamp(10px, 1.1vw, 18px);
}

:root[data-theme="light"] .board-frame {
  background:
    linear-gradient(135deg, rgba(168, 111, 31, 0.16), transparent 24%, rgba(255, 255, 255, 0.44) 48%, transparent 74%, rgba(168, 111, 31, 0.14)),
    linear-gradient(180deg, rgba(247, 249, 245, 0.92), rgba(222, 232, 224, 0.88));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.72),
    inset 0 16px 34px rgba(255, 255, 255, 0.32),
    0 24px 54px rgba(64, 79, 70, 0.22);
}

.board-frame::before,
.board-frame::after {
  position: absolute;
  border-radius: 6px;
  content: "";
  pointer-events: none;
}

.board-frame::before {
  z-index: 0;
  inset: 7px;
  border: 1px solid rgba(226, 189, 107, 0.18);
  background:
    repeating-linear-gradient(90deg, transparent 0 20px, rgba(255, 255, 255, 0.025) 20px 21px),
    linear-gradient(90deg, rgba(16, 32, 24, 0.4), rgba(95, 29, 43, 0.18), rgba(16, 32, 24, 0.4));
}

:root[data-theme="light"] .board-frame::before {
  border-color: rgba(168, 111, 31, 0.16);
  background:
    repeating-linear-gradient(90deg, transparent 0 20px, rgba(76, 58, 31, 0.035) 20px 21px),
    linear-gradient(90deg, rgba(223, 234, 222, 0.5), rgba(176, 106, 120, 0.12), rgba(223, 234, 222, 0.5));
}

.board-frame::after {
  z-index: 2;
  inset: clamp(28px, 3vw, 44px);
  border: 1px solid rgba(255, 238, 190, 0.16);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.22);
}

:root[data-theme="light"] .board-frame::after {
  border-color: rgba(168, 111, 31, 0.14);
  box-shadow: inset 0 0 20px rgba(76, 58, 31, 0.1);
}

.coord-labels {
  position: relative;
  z-index: 3;
  display: grid;
  color: color-mix(in srgb, var(--luxury-brass) 72%, var(--muted));
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1;
  user-select: none;
}

.coord-labels span {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
}

.coord-columns {
  grid-template-columns: repeat(var(--board-size, 8), minmax(0, 1fr));
}

.coord-rows {
  grid-template-rows: repeat(var(--board-size, 8), minmax(0, 1fr));
}

.coord-columns.top {
  grid-column: 2;
  grid-row: 1;
}

.coord-columns.bottom {
  grid-column: 2;
  grid-row: 3;
}

.coord-rows.left {
  grid-column: 1;
  grid-row: 2;
}

.coord-rows.right {
  grid-column: 3;
  grid-row: 2;
}

.board {
  position: relative;
  z-index: 1;
  grid-column: 2;
  grid-row: 2;
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: clamp(8px, 1.1vw, 16px) solid var(--board-rail);
  border-radius: 8px;
  background: var(--board-rail);
  grid-template-columns: repeat(var(--board-size, 8), minmax(0, 1fr));
  grid-template-rows: repeat(var(--board-size, 8), minmax(0, 1fr));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.15),
    inset 0 0 0 4px rgba(0, 0, 0, 0.24),
    0 2px 0 rgba(255, 238, 190, 0.14),
    0 26px 42px rgba(0, 0, 0, 0.46);
}

:root[data-theme="light"] .board {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.34),
    inset 0 0 0 4px rgba(58, 42, 22, 0.12),
    0 2px 0 rgba(255, 255, 255, 0.5),
    0 18px 34px rgba(64, 79, 70, 0.24);
}

.board[data-board-style],
.board-style-preview {
  --board-style-light: #d8c19a;
  --board-style-dark: #4a765c;
  --board-style-dark-alt: #3c644f;
  --board-style-rail: #292017;
  --board-style-rail-shine: rgba(226, 189, 107, 0.34);
  --board-style-square-gloss: rgba(255, 255, 255, 0.09);
}

.board[data-board-style] {
  --light-square: var(--board-style-light);
  --dark-square: var(--board-style-dark);
  --dark-square-alt: var(--board-style-dark-alt);
  --board-rail: var(--board-style-rail);
}

.board[data-board-style="emerald"],
.board-style-preview[data-board-style="emerald"] {
  --board-style-light: #d8c19a;
  --board-style-dark: #4a765c;
  --board-style-dark-alt: #3c644f;
  --board-style-rail: #292017;
  --board-style-rail-shine: rgba(226, 189, 107, 0.4);
}

.board[data-board-style="walnut"],
.board-style-preview[data-board-style="walnut"] {
  --board-style-light: #e0c393;
  --board-style-dark: #7b4a31;
  --board-style-dark-alt: #683c28;
  --board-style-rail: #2a170e;
  --board-style-rail-shine: rgba(235, 187, 112, 0.36);
}

.board[data-board-style="porcelain"],
.board-style-preview[data-board-style="porcelain"] {
  --board-style-light: #dfd8c5;
  --board-style-dark: #3f6673;
  --board-style-dark-alt: #345967;
  --board-style-rail: #1d2a31;
  --board-style-rail-shine: rgba(214, 232, 236, 0.34);
}

.board[data-board-style="midnight"],
.board-style-preview[data-board-style="midnight"] {
  --board-style-light: #b6c5cd;
  --board-style-dark: #526075;
  --board-style-dark-alt: #46536a;
  --board-style-rail: #171d27;
  --board-style-rail-shine: rgba(194, 211, 226, 0.28);
}

.board[data-board-style="crimson"],
.board-style-preview[data-board-style="crimson"] {
  --board-style-light: #dfc899;
  --board-style-dark: #8a3d4b;
  --board-style-dark-alt: #743340;
  --board-style-rail: #281019;
  --board-style-rail-shine: rgba(242, 187, 170, 0.32);
}

:root[data-theme="light"] .board[data-board-style="emerald"],
:root[data-theme="light"] .board-style-preview[data-board-style="emerald"] {
  --board-style-light: #ead2a1;
  --board-style-dark: #5f8b6d;
  --board-style-dark-alt: #4f7c61;
  --board-style-rail: #5b4931;
}

:root[data-theme="light"] .board[data-board-style="walnut"],
:root[data-theme="light"] .board-style-preview[data-board-style="walnut"] {
  --board-style-light: #f1d8aa;
  --board-style-dark: #9a6544;
  --board-style-dark-alt: #86563a;
  --board-style-rail: #6a4a2d;
}

:root[data-theme="light"] .board[data-board-style="porcelain"],
:root[data-theme="light"] .board-style-preview[data-board-style="porcelain"] {
  --board-style-light: #f1eadb;
  --board-style-dark: #6b8e9a;
  --board-style-dark-alt: #5d7d8a;
  --board-style-rail: #637170;
}

:root[data-theme="light"] .board[data-board-style="midnight"],
:root[data-theme="light"] .board-style-preview[data-board-style="midnight"] {
  --board-style-light: #d7e1e6;
  --board-style-dark: #657387;
  --board-style-dark-alt: #566478;
  --board-style-rail: #48505e;
}

:root[data-theme="light"] .board[data-board-style="crimson"],
:root[data-theme="light"] .board-style-preview[data-board-style="crimson"] {
  --board-style-light: #f0d6a6;
  --board-style-dark: #a35a65;
  --board-style-dark-alt: #8f4d59;
  --board-style-rail: #69404a;
}

.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: inherit;
}

.square:focus-visible {
  z-index: 2;
  outline: 3px solid var(--target);
  outline-offset: -3px;
}

.light-square {
  background:
    linear-gradient(135deg, var(--board-style-square-gloss), transparent 36%, rgba(0, 0, 0, 0.05)),
    radial-gradient(circle at 24% 20%, rgba(255, 255, 255, 0.22), transparent 28%),
    var(--light-square);
  cursor: default;
}

.dark-square {
  background-color: var(--dark-square);
  background-image:
    linear-gradient(145deg, rgba(255, 255, 255, 0.1), transparent 34%, rgba(0, 0, 0, 0.16)),
    radial-gradient(circle at 72% 78%, rgba(255, 255, 255, 0.08), transparent 31%),
    url("./assets/board-texture.svg");
  cursor: pointer;
}

.preview-board .dark-square,
.square:disabled {
  cursor: default;
}

.dark-square:nth-child(4n) {
  background-color: var(--dark-square-alt);
}

.square.last-move {
  box-shadow:
    inset 0 0 0 4px rgba(226, 189, 107, 0.48),
    inset 0 0 22px rgba(226, 189, 107, 0.2);
}

.last-move-arrow {
  position: absolute;
  z-index: 3;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 244, 220, 0.24), rgba(226, 189, 107, 0.9));
  color: rgba(226, 189, 107, 0.9);
  box-shadow: 0 0 0 3px var(--arrow-outline), 0 0 18px rgba(226, 189, 107, 0.38);
  pointer-events: none;
  transform-origin: left center;
}

.last-move-arrow.capture {
  background: linear-gradient(90deg, rgba(255, 220, 220, 0.24), rgba(255, 142, 142, 0.88));
  color: rgba(255, 172, 172, 0.88);
  box-shadow: 0 0 0 3px var(--arrow-outline), 0 0 18px rgba(255, 142, 142, 0.34);
}

.last-move-arrow::before,
.last-move-arrow::after {
  position: absolute;
  top: 50%;
  content: "";
  transform: translateY(-50%);
}

.last-move-arrow::before {
  left: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  color: inherit;
}

.last-move-arrow::after {
  right: -2px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid rgba(226, 189, 107, 0.9);
}

.last-move-arrow.capture::after {
  border-left-color: rgba(255, 184, 184, 0.8);
}

.square.selectable::before,
.square.target::before {
  position: absolute;
  inset: 10%;
  border-radius: 8px;
  content: "";
  pointer-events: none;
}

.square.selectable::before {
  border: 3px solid rgba(255, 244, 220, 0.72);
  box-shadow: inset 0 0 0 2px var(--selection-inset), 0 0 18px rgba(255, 244, 220, 0.3);
}

.square.selected::before {
  border-color: var(--target);
  box-shadow: inset 0 0 0 2px var(--selection-active-inset), 0 0 28px rgba(226, 189, 107, 0.58);
}

.square.target::after {
  position: absolute;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #fff4dc 0 18%, var(--target) 19% 100%);
  box-shadow: 0 0 0 8px rgba(226, 189, 107, 0.22), 0 0 24px rgba(226, 189, 107, 0.46);
  content: "";
}

.square.target:has(.piece)::after {
  width: 84%;
  border: 4px solid rgba(226, 189, 107, 0.92);
  background: transparent;
  box-shadow: inset 0 0 18px rgba(226, 189, 107, 0.22), 0 0 16px rgba(226, 189, 107, 0.24);
}

.dark-square:not(:disabled):hover {
  filter: brightness(1.08) saturate(1.06);
}

.square.captured-threat .piece {
  box-shadow:
    inset 0 7px 8px rgba(255, 255, 255, 0.34),
    inset 0 -10px 12px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 3px 0 rgba(0, 0, 0, 0.28),
    0 13px 18px rgba(0, 0, 0, 0.36),
    0 0 0 4px rgba(255, 184, 184, 0.72),
    0 0 22px rgba(255, 142, 142, 0.28);
}

.piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translateZ(0);
  box-shadow:
    inset 0 7px 8px rgba(255, 255, 255, 0.34),
    inset 0 -10px 12px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 3px 0 rgba(0, 0, 0, 0.28),
    0 13px 18px rgba(0, 0, 0, 0.36);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.piece::before {
  position: absolute;
  inset: 15%;
  border: 3px double rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  content: "";
  box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.1), inset 0 -4px 8px rgba(0, 0, 0, 0.16);
}

.piece.white {
  border: 3px solid color-mix(in srgb, var(--white-piece-edge) 82%, var(--luxury-brass));
  background:
    radial-gradient(circle at 28% 22%, #ffffff 0 12%, transparent 26%),
    radial-gradient(circle at 44% 38%, #fff8ea 0 34%, transparent 35%),
    linear-gradient(145deg, #fffaf0, var(--white-piece) 46%, #b59e73 100%);
}

.piece.black {
  border: 3px solid color-mix(in srgb, var(--black-piece-edge) 74%, #6f7b7b);
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.34) 0 10%, transparent 24%),
    radial-gradient(circle at 48% 42%, #38434a 0 32%, transparent 33%),
    linear-gradient(145deg, #535f61, var(--black-piece) 45%, var(--black-piece-edge) 100%);
}

.square.selectable .piece,
.square.selected .piece {
  transform: translateY(-3px);
  filter: saturate(1.08);
  box-shadow:
    inset 0 7px 8px rgba(255, 255, 255, 0.34),
    inset 0 -10px 12px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 5px 0 rgba(0, 0, 0, 0.22),
    0 18px 22px rgba(0, 0, 0, 0.4),
    0 0 18px rgba(226, 189, 107, 0.32);
}

.piece.king::after {
  position: absolute;
  inset: 27%;
  background: url("./assets/crown.svg") center / contain no-repeat;
  content: "";
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}

.side-panel {
  display: grid;
  max-height: calc(var(--viewport-height) - 120px);
  align-content: start;
  gap: clamp(10px, 1.2vh, 14px);
  overflow: auto;
  padding-right: 2px;
  scrollbar-color: var(--scrollbar) transparent;
}

:root[data-screen="game"] .side-panel {
  max-height: calc(var(--viewport-height) - 112px);
}

:root[data-screen="game"] .side-panel > section {
  position: relative;
  overflow: hidden;
  border-color: rgba(226, 189, 107, 0.22);
  background:
    linear-gradient(150deg, rgba(226, 189, 107, 0.11), transparent 34%),
    color-mix(in srgb, var(--luxury-glass) 82%, transparent);
  box-shadow:
    0 20px 54px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px) saturate(1.12);
}

:root[data-theme="light"][data-screen="game"] .side-panel > section {
  border-color: rgba(168, 111, 31, 0.18);
  background:
    linear-gradient(150deg, rgba(168, 111, 31, 0.09), transparent 36%),
    rgba(255, 255, 255, 0.74);
  box-shadow:
    0 18px 44px rgba(64, 79, 70, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

:root[data-screen="game"] .side-panel > section::before {
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(226, 189, 107, 0.72), transparent);
  content: "";
}

.settings-panel,
.action-panel,
.summary-panel,
.online-panel,
.rules-panel,
.history-panel {
  padding: 12px;
}

.settings-panel {
  display: grid;
  gap: 12px;
}

:root[data-screen="setup"] .settings-panel {
  position: relative;
  z-index: 1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: clamp(12px, 1.4vw, 18px);
  row-gap: clamp(10px, 1.2vh, 14px);
  padding: clamp(14px, 1.6vw, 20px);
}

.setting-group {
  display: grid;
  gap: 8px;
}

:root[data-screen="setup"] .setting-group {
  min-width: 0;
  gap: 8px;
  border-top: 1px solid rgba(226, 189, 107, 0.14);
  padding-top: 10px;
}

:root[data-screen="setup"] .setting-group:nth-child(1),
:root[data-screen="setup"] .setting-group:nth-child(2) {
  border-top: 0;
  padding-top: 0;
}

:root[data-theme="light"][data-screen="setup"] .setting-group {
  border-top-color: rgba(168, 111, 31, 0.13);
}

.setting-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.setting-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

:root[data-screen="setup"] .setting-label {
  color: color-mix(in srgb, var(--luxury-brass) 70%, var(--muted));
  font-size: 0.72rem;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.info-icon {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--subtle-fill);
  color: var(--muted);
  cursor: help;
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.info-tooltip,
.info-icon::after {
  position: absolute;
  right: -1px;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.info-tooltip {
  display: grid;
  grid-template-columns: minmax(84px, max-content) 1fr;
  column-gap: 9px;
  row-gap: 7px;
  align-items: start;
  bottom: calc(100% + 9px);
  width: min(320px, calc(var(--viewport-width) - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.32);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 750;
  padding: 9px 10px;
  text-align: left;
}

.tooltip-row {
  display: contents;
}

.tooltip-term {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 950;
  line-height: 1.32;
  text-transform: uppercase;
}

.tooltip-text {
  color: var(--ink);
  font-weight: 760;
  line-height: 1.32;
}

.info-icon[data-i18n-aria-label="setting.boardInfo"] .info-tooltip {
  grid-template-columns: 160px 1fr;
  width: min(360px, calc(var(--viewport-width) - 32px));
}

.info-icon[data-i18n-aria-label="setting.boardInfo"] .tooltip-term {
  white-space: nowrap;
}

.info-icon::after {
  bottom: calc(100% + 4px);
  border-color: var(--panel) transparent transparent;
  border-style: solid;
  border-width: 6px 6px 0;
  content: "";
}

.info-icon:hover,
.info-icon:focus,
.info-icon:focus-visible {
  border-color: rgba(212, 168, 79, 0.72);
  background: rgba(212, 168, 79, 0.14);
  color: var(--ink);
  transform: translateY(-1px);
}

.info-icon:focus {
  outline: 0;
}

.info-icon:focus-visible {
  box-shadow: 0 0 0 3px rgba(212, 168, 79, 0.14);
}

.info-icon:hover .info-tooltip,
.info-icon:hover::after,
.info-icon:focus .info-tooltip,
.info-icon:focus::after,
.info-icon:focus-visible .info-tooltip,
.info-icon:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 480px) {
  .info-tooltip {
    grid-template-columns: 1fr;
    width: min(300px, calc(var(--viewport-width) - 24px));
  }

  .info-icon[data-i18n-aria-label="setting.boardInfo"] .info-tooltip {
    grid-template-columns: 1fr;
    width: min(300px, calc(var(--viewport-width) - 24px));
  }

  .tooltip-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .info-icon[data-i18n-aria-label="setting.boardInfo"] .tooltip-row {
    grid-template-columns: 1fr;
  }

  .info-icon[data-i18n-aria-label="setting.boardInfo"] .tooltip-term {
    white-space: normal;
  }
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(94px, 1fr));
  gap: 6px;
}

:root[data-screen="setup"] .segmented-control {
  gap: 7px;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
}

.board-style-control {
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
}

:root[data-screen="setup"] .board-style-control {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.segment {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0 8px;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

:root[data-screen="setup"] .segment {
  min-height: 40px;
  border-color: rgba(226, 189, 107, 0.18);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 54%),
    color-mix(in srgb, var(--surface) 78%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.055);
}

:root[data-theme="light"][data-screen="setup"] .segment {
  border-color: rgba(168, 111, 31, 0.16);
  background:
    linear-gradient(145deg, rgba(168, 111, 31, 0.055), transparent 54%),
    rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.segment:hover {
  border-color: rgba(212, 168, 79, 0.64);
  transform: translateY(-1px);
}

.segment:focus-visible {
  outline: 3px solid var(--target);
  outline-offset: 2px;
}

.segment[aria-checked="true"] {
  border-color: rgba(212, 168, 79, 0.92);
  background: var(--gold);
  color: var(--primary-ink);
}

:root[data-screen="setup"] .segment[aria-checked="true"] {
  border-color: rgba(255, 226, 158, 0.9);
  background:
    linear-gradient(180deg, #f0cd76, var(--gold) 58%, #a87925);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -2px 0 rgba(93, 57, 9, 0.32),
    0 10px 20px rgba(0, 0, 0, 0.18);
}

.board-style-segment {
  display: grid;
  min-height: 74px;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 8px;
}

:root[data-screen="setup"] .board-style-segment {
  min-height: 68px;
  gap: 6px;
  padding: 7px 5px;
}

.board-style-segment[aria-checked="true"] {
  background: color-mix(in srgb, var(--gold) 18%, var(--surface));
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(212, 168, 79, 0.28);
}

.board-style-preview {
  display: grid;
  width: min(50px, 100%);
  aspect-ratio: 1;
  overflow: hidden;
  border: 4px solid var(--board-style-rail);
  border-radius: 6px;
  background: var(--board-style-rail);
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.24);
}

:root[data-screen="setup"] .board-style-preview {
  width: min(42px, 100%);
  border-width: 3px;
  box-shadow:
    0 7px 14px rgba(0, 0, 0, 0.24),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

.style-swatch-cell[data-tone="light"] {
  background: var(--board-style-light);
}

.style-swatch-cell[data-tone="dark"] {
  background: var(--board-style-dark);
}

.style-swatch-cell[data-tone="dark"]:nth-child(4n) {
  background: var(--board-style-dark-alt);
}

.board-style-name {
  min-width: 0;
  max-width: 100%;
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.summary-panel {
  display: grid;
  gap: 8px;
}

:root[data-screen="game"] .summary-panel h2,
:root[data-screen="game"] .online-panel h2,
:root[data-screen="game"] .rules-panel h2,
:root[data-screen="game"] .history-panel h2 {
  color: color-mix(in srgb, var(--luxury-brass) 76%, var(--ink));
  font-size: 0.82rem;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.summary-panel p {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.35;
}

.online-setup {
  display: grid;
  grid-column: 1 / -1;
  gap: 9px;
}

.online-field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.online-field-label {
  font-size: 0.68rem;
}

.online-join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(86px, auto);
  gap: 8px;
}

.online-text-input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid rgba(226, 189, 107, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 54%),
    color-mix(in srgb, var(--surface) 78%, transparent);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 900;
  letter-spacing: 0;
  padding: 0 12px;
}

.room-code-input {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

:root[data-theme="light"] .online-text-input {
  border-color: rgba(168, 111, 31, 0.18);
  background: rgba(255, 255, 255, 0.66);
}

.online-text-input::placeholder {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
}

.online-text-input:focus-visible {
  outline: 3px solid rgba(212, 168, 79, 0.34);
  outline-offset: 2px;
}

.join-room-action {
  min-height: 44px;
  padding: 0 16px;
}

.online-status-text {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.3;
}

.online-panel {
  display: grid;
  gap: 10px;
}

.online-side-badge {
  display: inline-grid;
  min-height: 26px;
  place-items: center;
  border: 1px solid rgba(212, 168, 79, 0.5);
  border-radius: 999px;
  background: rgba(212, 168, 79, 0.12);
  color: var(--gold);
  padding: 0 9px;
  font-size: 0.68rem;
  font-weight: 950;
  line-height: 1;
}

.room-code-display {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(226, 189, 107, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(110deg, rgba(226, 189, 107, 0.12), transparent 52%),
    color-mix(in srgb, var(--surface) 72%, transparent);
  padding: 8px;
}

.online-room-actions {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: end;
  gap: 5px;
}

.leave-room-action {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger-ink);
}

:root[data-theme="light"] .room-code-display {
  border-color: rgba(168, 111, 31, 0.14);
  background:
    linear-gradient(110deg, rgba(168, 111, 31, 0.1), transparent 54%),
    rgba(255, 255, 255, 0.62);
}

.room-code-display span {
  min-width: 0;
  color: var(--luxury-ivory);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.25rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  line-height: 1;
  overflow-wrap: anywhere;
}

:root[data-theme="light"] .room-code-display span {
  color: var(--ink);
}

.online-room-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.online-room-list div {
  min-width: 0;
  border: 1px solid rgba(226, 189, 107, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.055), transparent 50%),
    color-mix(in srgb, var(--surface) 72%, transparent);
  padding: 8px;
}

:root[data-theme="light"] .online-room-list div {
  border-color: rgba(168, 111, 31, 0.12);
  background:
    linear-gradient(120deg, rgba(168, 111, 31, 0.06), transparent 52%),
    rgba(255, 255, 255, 0.62);
}

.online-room-list dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
}

.online-room-list dd {
  min-width: 0;
  margin: 5px 0 0;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

:root[data-screen="game"] .summary-panel p {
  color: var(--luxury-ivory);
}

.rules-panel {
  display: grid;
  gap: 10px;
}

.rules-list {
  display: grid;
  gap: 7px;
}

.rules-list div {
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px 9px;
}

:root[data-screen="game"] .rules-list div {
  border-color: rgba(226, 189, 107, 0.16);
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.055), transparent 50%),
    color-mix(in srgb, var(--surface) 74%, transparent);
}

:root[data-theme="light"][data-screen="game"] .rules-list div {
  border-color: rgba(168, 111, 31, 0.12);
  background:
    linear-gradient(120deg, rgba(168, 111, 31, 0.06), transparent 52%),
    rgba(255, 255, 255, 0.62);
}

.rules-list dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
}

.rules-list dd {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 760;
  line-height: 1.25;
}

.action-panel {
  display: grid;
  gap: 8px;
  order: 3;
}

:root[data-screen="setup"] .setup-card > .action-panel {
  position: relative;
  z-index: 1;
  border-top: 1px solid rgba(226, 189, 107, 0.16);
  background:
    linear-gradient(90deg, rgba(226, 189, 107, 0.12), transparent 44%),
    color-mix(in srgb, var(--surface-strong) 58%, transparent);
  padding: clamp(12px, 1.4vw, 16px) clamp(14px, 1.6vw, 20px) clamp(14px, 1.6vw, 18px);
}

:root[data-theme="light"][data-screen="setup"] .setup-card > .action-panel {
  border-top-color: rgba(168, 111, 31, 0.14);
  background:
    linear-gradient(90deg, rgba(168, 111, 31, 0.1), transparent 44%),
    rgba(255, 255, 255, 0.56);
}

.settings-panel,
.summary-panel {
  order: 1;
}

.online-panel {
  order: 2;
}

.rules-panel {
  order: 4;
}

.history-panel {
  order: 5;
}

.primary-action {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(212, 168, 79, 0.8);
  border-radius: 8px;
  background: var(--gold);
  color: var(--primary-ink);
  cursor: pointer;
  font-weight: 900;
  transition: transform 120ms ease, filter 120ms ease;
}

:root[data-screen="setup"] .primary-action {
  min-height: 52px;
  border-color: rgba(255, 226, 158, 0.9);
  background:
    linear-gradient(180deg, #f0cd76, var(--gold) 58%, #a87925);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    inset 0 -2px 0 rgba(93, 57, 9, 0.36),
    0 16px 28px rgba(0, 0, 0, 0.26);
  font-size: 0.98rem;
}

:root[data-screen="game"] .primary-action {
  border-color: rgba(255, 226, 158, 0.86);
  background:
    linear-gradient(180deg, #f0cd76, var(--gold) 58%, #a87925);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    inset 0 -2px 0 rgba(93, 57, 9, 0.36),
    0 12px 24px rgba(0, 0, 0, 0.28);
}

.primary-action:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.primary-action.danger-action {
  border-color: var(--danger-line);
  background: linear-gradient(180deg, var(--danger-text), #c94f4f 58%, #7f2424);
  color: #1c0909;
}

.secondary-action {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  transition: border-color 120ms ease, transform 120ms ease;
}

.secondary-action:hover {
  border-color: rgba(212, 168, 79, 0.66);
  transform: translateY(-1px);
}

.secondary-action.danger-action {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.secondary-action.danger-action:hover {
  border-color: var(--danger-text);
}

.audio-action[aria-pressed="true"] {
  border-color: rgba(212, 168, 79, 0.72);
  background: rgba(212, 168, 79, 0.16);
  color: var(--gold);
}

.top-controls .audio-action,
.top-controls .theme-action {
  display: grid;
  width: 44px;
  height: 44px;
  min-height: 44px;
  flex: none;
  place-items: center;
  border-radius: 8px;
  padding: 0;
  color: var(--muted);
}

.top-controls .audio-action:hover,
.top-controls .theme-action:hover {
  color: var(--ink);
}

.top-controls .audio-action[aria-pressed="true"],
.top-controls .theme-action[aria-pressed="true"] {
  border-color: rgba(212, 168, 79, 0.86);
  background: rgba(212, 168, 79, 0.18);
  color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 168, 79, 0.14);
}

.theme-icon {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.theme-sun-core,
.theme-sun-rays,
.theme-moon {
  transition: opacity 120ms ease;
}

.theme-sun-core {
  fill: currentColor;
  stroke: none;
}

.theme-moon {
  fill: currentColor;
  stroke: none;
}

.theme-action[aria-pressed="true"] .theme-sun-core,
.theme-action[aria-pressed="true"] .theme-sun-rays {
  opacity: 0;
}

.theme-action[aria-pressed="true"] .theme-moon {
  opacity: 1;
}

.theme-action[aria-pressed="false"] .theme-sun-core,
.theme-action[aria-pressed="false"] .theme-sun-rays {
  opacity: 1;
}

.theme-action[aria-pressed="false"] .theme-moon {
  opacity: 0;
}

.audio-icon {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.audio-slash {
  opacity: 1;
  transition: opacity 120ms ease;
}

.audio-wave {
  opacity: 0;
  transition: opacity 120ms ease;
}

.audio-action[aria-pressed="true"] .audio-slash {
  opacity: 0;
}

.audio-action[aria-pressed="true"] .audio-wave {
  opacity: 1;
}

.button-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

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

.history-toolbar {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

:root[data-screen="game"] .history-toolbar {
  gap: 8px;
}

.history-actions {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.compact-action {
  flex: 0 0 auto;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0 7px;
  font-size: 0.66rem;
  font-weight: 850;
  white-space: nowrap;
}

:root[data-screen="game"] .compact-action {
  border-color: rgba(226, 189, 107, 0.24);
  background: color-mix(in srgb, var(--surface) 76%, transparent);
}

:root[data-theme="light"][data-screen="game"] .compact-action {
  border-color: rgba(168, 111, 31, 0.2);
  background: rgba(255, 255, 255, 0.66);
}

.compact-action:hover {
  border-color: rgba(212, 168, 79, 0.66);
}

.compact-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.undo-action {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 5px;
  border-color: rgba(212, 168, 79, 0.42);
  background: rgba(212, 168, 79, 0.1);
  color: var(--gold);
}

.undo-action svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
}

.undo-action:hover {
  border-color: rgba(212, 168, 79, 0.76);
  background: rgba(212, 168, 79, 0.18);
}

.undo-action:disabled {
  border-color: rgba(212, 168, 79, 0.4);
  background: rgba(212, 168, 79, 0.1);
}

.mini-toggle {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: auto auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

:root[data-screen="game"] .mini-toggle {
  border-color: rgba(226, 189, 107, 0.24);
  background: color-mix(in srgb, var(--surface) 76%, transparent);
}

:root[data-theme="light"][data-screen="game"] .mini-toggle {
  border-color: rgba(168, 111, 31, 0.2);
  background: rgba(255, 255, 255, 0.66);
}

.mini-toggle button {
  min-width: 0;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 7px;
  font-size: 0.66rem;
  font-weight: 850;
  white-space: nowrap;
}

.mini-toggle button + button {
  border-left: 1px solid var(--line);
}

.mini-toggle button[aria-pressed="true"] {
  background: var(--gold);
  color: var(--primary-ink);
}

.history-panel {
  display: grid;
  min-height: 210px;
  align-content: start;
  gap: 12px;
}

:root[data-screen="game"] .history-panel {
  min-height: clamp(210px, 28vh, 340px);
}

.history-panel ol {
  display: grid;
  max-height: 320px;
  gap: 6px;
  overflow: auto;
  padding-left: 0;
  color: var(--muted);
  font-size: 0.82rem;
  list-style: none;
  scrollbar-color: var(--scrollbar) transparent;
}

.move-round {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--surface);
  padding: 7px;
}

:root[data-screen="game"] .move-round {
  border-color: rgba(226, 189, 107, 0.13);
  background:
    linear-gradient(110deg, rgba(226, 189, 107, 0.08), transparent 44%),
    color-mix(in srgb, var(--surface) 70%, transparent);
}

:root[data-theme="light"][data-screen="game"] .move-round {
  border-color: rgba(168, 111, 31, 0.12);
  background:
    linear-gradient(110deg, rgba(168, 111, 31, 0.08), transparent 46%),
    rgba(255, 255, 255, 0.58);
}

.move-round.latest {
  border-color: rgba(212, 168, 79, 0.62);
  background: rgba(212, 168, 79, 0.08);
}

:root[data-screen="game"] .move-round.latest {
  border-color: rgba(226, 189, 107, 0.58);
  background:
    linear-gradient(110deg, rgba(226, 189, 107, 0.16), transparent 52%),
    color-mix(in srgb, var(--surface) 72%, transparent);
}

:root[data-theme="light"][data-screen="game"] .move-round.latest {
  border-color: rgba(168, 111, 31, 0.32);
  background:
    linear-gradient(110deg, rgba(168, 111, 31, 0.14), transparent 54%),
    rgba(255, 255, 255, 0.68);
}

.move-number {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: var(--subtle-fill);
  color: var(--ink);
  font-weight: 900;
}

:root[data-screen="game"] .move-number {
  background: rgba(226, 189, 107, 0.16);
  color: color-mix(in srgb, var(--luxury-brass) 84%, var(--ink));
}

.move-side {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 4px;
}

.move-side-label {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
  line-height: 1;
}

.move-notation,
.move-empty {
  display: inline-grid;
  min-width: 0;
  min-height: 24px;
  align-items: center;
  justify-self: start;
  border-radius: 6px;
  padding: 3px 6px;
  line-height: 1;
}

.move-notation {
  max-width: 100%;
  border: 1px solid var(--soft-line);
  background: var(--token-fill);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

:root[data-screen="game"] .move-notation {
  border-color: rgba(226, 189, 107, 0.17);
  background: rgba(255, 255, 255, 0.06);
}

:root[data-theme="light"][data-screen="game"] .move-notation {
  border-color: rgba(168, 111, 31, 0.14);
  background: rgba(255, 255, 255, 0.62);
}

.move-notation.capture {
  border-color: rgba(255, 184, 184, 0.34);
  background: var(--danger-token);
  color: var(--danger-ink);
}

.move-empty {
  color: var(--move-empty);
  font-weight: 850;
}

.empty-state {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
}

.copy-buffer {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid rgba(212, 168, 79, 0.54);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px;
  font: 0.78rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.game-over-overlay {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--overlay-bg);
  padding: 16px;
}

.game-over-dialog {
  display: grid;
  width: min(360px, 100%);
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  padding: 18px;
}

:root[data-screen="game"] .game-over-dialog {
  border-color: rgba(226, 189, 107, 0.28);
  background:
    linear-gradient(145deg, rgba(226, 189, 107, 0.16), transparent 36%),
    color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
}

:root[data-theme="light"][data-screen="game"] .game-over-dialog {
  border-color: rgba(168, 111, 31, 0.22);
  background:
    linear-gradient(145deg, rgba(168, 111, 31, 0.12), transparent 38%),
    rgba(255, 255, 255, 0.9);
  box-shadow:
    0 28px 70px rgba(64, 79, 70, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.game-over-dialog h2 {
  font-size: 1.45rem;
}

.game-over-dialog p {
  color: var(--muted);
  font-weight: 750;
  line-height: 1.4;
}

.dialog-actions {
  display: grid;
  gap: 8px;
}

@media (min-width: 881px) and (max-height: 820px) {
  .setup-screen {
    align-items: start;
    padding-top: 4px;
  }

  .setup-stage {
    gap: 12px;
  }

  .setup-intro {
    gap: 4px;
  }

  .setup-intro h2 {
    font-size: clamp(1.45rem, 3vw, 2.35rem);
  }

  :root[data-screen="setup"] .setup-stage {
    gap: 16px;
  }

  :root[data-screen="setup"] .setup-intro h2 {
    font-size: clamp(1.75rem, 3.7vw, 3.35rem);
  }

  .setup-content {
    min-height: auto;
  }

  :root[data-screen="setup"] .settings-panel {
    row-gap: 9px;
    padding: 12px;
  }

  :root[data-screen="setup"] .setting-group {
    gap: 6px;
    padding-top: 8px;
  }

  :root[data-screen="setup"] .segment {
    min-height: 36px;
    font-size: 0.78rem;
  }

  :root[data-screen="setup"] .board-style-segment {
    min-height: 58px;
  }

  :root[data-screen="setup"] .setup-card > .action-panel {
    padding: 10px 12px 12px;
  }

  .side-panel {
    gap: 8px;
  }

  .settings-panel,
  .action-panel,
  .summary-panel,
  .online-panel,
  .rules-panel,
  .history-panel {
    padding: 10px;
  }

  .settings-panel {
    gap: 8px;
  }

  .setting-group {
    gap: 6px;
  }

  .segmented-control {
    grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  }

  .segment {
    min-height: 36px;
    font-size: 0.8rem;
  }

  .board-style-segment {
    min-height: 62px;
    gap: 5px;
    padding: 6px;
  }

  .board-style-preview {
    width: min(40px, 100%);
    border-width: 3px;
  }

  .board-style-name {
    font-size: 0.7rem;
  }

  .rules-panel {
    gap: 8px;
  }

  .rules-list {
    gap: 6px;
  }

  .rules-list div {
    padding: 7px 8px;
  }

  .rules-list dd {
    font-size: 0.78rem;
  }

  :root[data-screen="game"] .topbar {
    margin-bottom: 10px;
    padding: 8px;
  }

  :root[data-screen="game"] .board-panel {
    padding: 12px;
  }

  :root[data-screen="game"] .board-frame {
    --board-max: min(760px, max(320px, calc(var(--viewport-height) - 360px)));
    padding: 10px;
  }
}

@media (max-width: 1100px) {
  :root[data-screen="setup"] .setup-stage {
    grid-template-columns: 1fr;
    gap: clamp(14px, 2vh, 22px);
  }

  :root[data-screen="setup"] .setup-intro {
    max-width: 760px;
    justify-self: center;
    text-align: center;
  }

  :root[data-screen="setup"] .setup-kicker {
    justify-self: center;
  }

  :root[data-screen="setup"] .setup-content {
    justify-items: center;
  }

  :root[data-screen="setup"] .setup-card {
    width: min(100%, 900px);
  }
}

@media (max-width: 1040px) {
  .topbar {
    display: grid;
    align-items: start;
  }

  .top-controls {
    display: grid;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (max-width: 880px) {
  .app {
    width: min(100% - 20px, 680px);
    padding: 14px 0;
  }

  h1 {
    font-size: 2.2rem;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .setup-screen {
    min-height: auto;
    align-items: start;
  }

  .setup-content {
    min-height: auto;
  }

  .setup-content {
    grid-template-columns: 1fr;
  }

  :root[data-screen="setup"] .settings-panel {
    grid-template-columns: 1fr;
  }

  :root[data-screen="setup"] .board-style-control {
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  }

  .setup-card {
    order: 1;
  }

  .side-panel {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .meters {
    grid-template-columns: repeat(3, minmax(86px, 1fr));
    min-width: 0;
  }

  .board-panel {
    padding: 10px;
  }

  .board {
    border-width: 6px;
  }

  :root[data-screen="game"] .topbar {
    padding: 10px;
  }

  .board-frame {
    --label-size: clamp(16px, 2.8vw, 22px);
    --board-max: min(100%, calc(var(--viewport-width) - 44px));
    width: 100%;
    padding: 8px;
  }

  .board-frame::after {
    inset: clamp(20px, 5vw, 34px);
  }
}

@media (max-width: 480px) {
  :root[data-screen="setup"] body {
    background:
      var(--setup-vignette),
      var(--setup-wash),
      url("./assets/setup-background.png") 68% center / cover no-repeat fixed,
      var(--bg);
  }

  .top-controls {
    grid-template-columns: 1fr;
  }

  .setup-intro {
    text-align: left;
  }

  .setup-intro h2 {
    font-size: 1.65rem;
  }

  :root[data-screen="setup"] .setup-stage {
    gap: 12px;
  }

  :root[data-screen="setup"] .setup-intro {
    gap: 8px;
    text-align: left;
  }

  :root[data-screen="setup"] .setup-kicker {
    justify-self: start;
  }

  :root[data-screen="setup"] .setup-intro h2 {
    font-size: clamp(1.6rem, 9vw, 2.25rem);
    line-height: 1.04;
  }

  .setup-card {
    margin: 0 -2px;
  }

  :root[data-screen="setup"] .setup-card {
    width: calc(100% + 4px);
  }

  :root[data-screen="setup"] .settings-panel {
    gap: 10px;
    padding: 12px;
  }

  :root[data-screen="setup"] .setting-group:nth-child(2) {
    border-top: 1px solid rgba(226, 189, 107, 0.14);
    padding-top: 10px;
  }

  :root[data-screen="setup"] .board-style-segment {
    min-height: 64px;
  }

  .utility-dock {
    justify-self: end;
  }

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

  .status-row {
    display: grid;
  }

  .badge {
    max-width: 100%;
    justify-self: start;
  }

  .board-frame {
    --label-size: 16px;
    --board-max: min(100%, calc(var(--viewport-width) - 34px));
    padding: 6px;
  }

  .board-frame::before {
    inset: 5px;
  }

  .board-frame::after {
    inset: 20px;
  }

  .panel-heading,
  .history-toolbar,
  .history-actions {
    align-items: stretch;
  }

  .panel-heading {
    display: grid;
  }

  .history-toolbar,
  .history-actions {
    display: grid;
  }

  .history-toolbar {
    grid-template-columns: 1fr;
  }

  .history-toolbar .mini-toggle,
  .history-actions {
    width: 100%;
  }

  .history-toolbar .mini-toggle {
    grid-template-columns: 1fr 1fr;
  }

  .history-actions {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .history-actions .compact-action {
    width: 100%;
  }

  .online-join-row,
  .room-code-display,
  .online-room-list {
    grid-template-columns: 1fr;
  }

  .room-code-display .compact-action {
    width: 100%;
  }

  .online-room-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2rem;
  }
}
