:root {
  --bg: #06080f;
  --surface: rgba(18, 22, 31, 0.82);
  --surface-strong: rgba(12, 16, 24, 0.9);
  --stage-surface: rgba(10, 13, 19, 0.94);
  --glass: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --card-bg: rgba(18, 22, 31, 0.88);
  --card-shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
  --surface-shadow: 0 26px 70px rgba(0, 0, 0, 0.52);
  --text-primary: #f5f7fb;
  --text-secondary: #cfd4df;
  --text-muted: #9ea6b5;
  --accent: #7dd3ff;
  --accent-strong: #5fb7ff;
  --warn: #f2b464;
  --error: #ff6b6b;
  --success: #6cd69b;
  --button-bg: #f5f7fb;
  --button-text: #0b0d12;
  --button-surface: #202631;
  --input-bg: rgba(16, 20, 28, 0.9);
  --radius: 12px;
  --radius-tight: 8px;
  --shadow-subtle: 0 24px 60px rgba(0, 0, 0, 0.38);
  --focus-ring: 0 0 0 2px rgba(125, 211, 255, 0.65), 0 0 0 6px rgba(125, 211, 255, 0.16);
  --space-12: 12px;
  --space-16: 16px;
  --space-24: 24px;
  --space-32: 32px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.6;
  letter-spacing: 0.01em;
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("/chess/assets/bg.jpg");
  background-image: image-set(
    url("/chess/assets/bg.webp") type("image/webp"),
    url("/chess/assets/bg.jpg") type("image/jpeg")
  );
  background-attachment: fixed;
  background-size: cover;
  background-position: left center;
  background-repeat: no-repeat;
  filter: blur(4.5px) saturate(0.95) contrast(1.05);
  opacity: 0.36;
  transform: scale(1.03);
  z-index: -2;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 120% at 50% 40%, rgba(0, 0, 0, 0) 48%, rgba(0, 0, 0, 0.48) 100%),
    radial-gradient(70% 70% at 15% 20%, rgba(255, 255, 255, 0.04), transparent 38%),
    linear-gradient(180deg, rgba(4, 7, 12, 0.7) 0%, rgba(4, 7, 12, 0.86) 100%);
  background-blend-mode: multiply, screen, normal;
  z-index: -1;
}

/* Debug: add "debug-bg" class to <body> to verify background. */
body.debug-bg::before {
  opacity: 0.75;
  filter: none;
}

body.debug-bg::after {
  opacity: 0.3;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 18px 64px;
  position: relative;
  z-index: 1;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  font-weight: 800;
  letter-spacing: 0.015em;
}

h1 {
  font-size: clamp(32px, 4vw, 42px);
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

h2 {
  font-size: clamp(22px, 2.6vw, 28px);
}

h3 {
  font-size: clamp(18px, 2vw, 22px);
}

p {
  margin: 0 0 12px;
  color: var(--text-primary);
}

a {
  color: var(--text-secondary);
}

a:hover {
  color: var(--text-primary);
}

a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-tight);
}

.subhead {
  color: var(--text-secondary);
  font-weight: 650;
  letter-spacing: 0.02em;
  margin-bottom: var(--space-16);
  font-size: clamp(16px, 2vw, 18px);
  display: flex;
  gap: var(--space-12);
  flex-wrap: wrap;
  align-items: baseline;
  line-height: 1.5;
}

.meta-line span {
  display: inline-flex;
  align-items: baseline;
}

.meta-line span + span::before {
  content: "•";
  opacity: 0.6;
  margin: 0 0.6rem;
  color: var(--text-muted);
}

.subhead strong {
  color: var(--text-primary);
  letter-spacing: 0.01em;
  padding: 2px 6px;
  border-radius: var(--radius-tight);
  background: rgba(255, 255, 255, 0.04);
}

.about-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius-tight);
  border: 1px solid transparent;
  transition: color 120ms ease, background 120ms ease, box-shadow 120ms ease, text-decoration-color 120ms ease, border-color 120ms ease, text-underline-offset 120ms ease;
}

.about-link:hover {
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 3px;
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border);
}

.about-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--text-secondary);
}

.project-intro h2 {
  margin-bottom: 8px;
}

.sigil-mark {
  width: 44px;
  height: 32px;
  margin: 6px 0 16px;
  color: var(--text-muted);
  opacity: 0.9;
}

.sigil-mark path,
.sigil-mark rect {
  vector-effect: non-scaling-stroke;
}

.about-section {
  margin-top: var(--space-32);
  margin-bottom: var(--space-16);
  margin-left: auto;
  margin-right: auto;
  padding: 24px 20px 18px;
  background: rgba(255, 255, 255, 0.016);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  max-width: 880px;
  line-height: 1.62;
  color: var(--text-secondary);
}

.about-section h2 {
  margin-bottom: 8px;
  font-size: clamp(20px, 2.2vw, 26px);
  color: var(--text-primary);
}

.about-section p {
  color: inherit;
  max-width: 70ch;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 14px;
}

.about-section p + p {
  margin-top: 6px;
}

.about-lede {
  color: var(--text-primary);
  font-weight: 700;
}

.about-stanza {
  margin-top: 18px;
  color: var(--text-muted);
  font-style: italic;
}

#about,
#about-heading {
  scroll-margin-top: 96px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-24);
  box-shadow: var(--card-shadow);
}

.card + .card {
  margin-top: var(--space-16);
}

.game-snapshot {
  margin: 6px 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.snapshot-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}

.snapshot-row + .snapshot-row {
  border-top: 1px solid var(--border);
  padding-top: 9px;
  margin-top: 5px;
}

.snapshot-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.snapshot-value {
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
}

.glass-card {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

.stage-card {
  background: var(--stage-surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--surface-shadow);
  padding: var(--space-24);
  position: relative;
  overflow: hidden;
}

.stage-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background:
    repeating-linear-gradient(135deg, rgba(125, 211, 255, 0.06), rgba(125, 211, 255, 0.06) 2px, transparent 2px, transparent 12px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0));
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
}

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

.board-container {
  width: 100%;
  max-width: 620px;
  margin: 4px auto 0;
}

.board-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.board-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-16);
}

.board-stack .scoreboard {
  order: -1;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}

.board-stack .board-container {
  order: 1;
}

.scoreboard {
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 28px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(4px);
  position: relative;
  overflow: hidden;
}

.scoreboard::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 15% 15%, rgba(125, 211, 255, 0.08), transparent 40%);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

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

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-12);
}

.score-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-tight);
  background: var(--glass);
  min-height: 56px;
}

.score-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 760;
}

.score-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.score-last {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.score-last:not(.show) {
  display: none;
}

.board-shell::before {
  content: '';
  display: block;
  padding-bottom: 100%;
}

@supports (aspect-ratio: 1 / 1) {
  .board-shell::before {
    display: none;
    padding-bottom: 0;
  }
}

.board-shell::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: calc(var(--radius) + 2px);
  opacity: 0.28;
  pointer-events: none;
  z-index: 0;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-strong);
  z-index: 1;
}

.sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  user-select: none;
  color: var(--text-primary);
}

.label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
}

.corner {
  background: transparent;
}

.light {
  background: #f5f7fb;
}

.dark {
  background: #7a7d83;
}

.sq.pick {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.sq.hint {
  box-shadow: inset 0 0 0 3px rgba(125, 211, 255, 0.65);
}

.sq.last {
  box-shadow: inset 0 0 0 3px rgba(255, 215, 0, 0.75);
}

#board.locked .sq,
#board.history-locked .sq {
  pointer-events: none;
}

.piece-svg {
  width: 80%;
  height: 80%;
  pointer-events: none;
}

.piece-img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  display: block;
}

button,
.button-link {
  padding: var(--space-12) var(--space-16);
  border-radius: var(--radius-tight);
  border: 1px solid var(--border-strong);
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
}

button:hover,
.button-link:hover {
  background: #ffffff;
}

button:focus-visible,
.button-link:focus-visible,
textarea:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary,
.button-link.secondary {
  background: var(--button-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.ghost-button {
  background: var(--glass);
  color: var(--text-secondary);
  border-color: var(--border);
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.button-compact {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.controls {
  display: flex;
  gap: var(--space-12);
  flex-wrap: wrap;
}

.control-bay {
  margin-top: var(--space-24);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  padding: var(--space-16);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.control-row {
  display: flex;
  gap: var(--space-16);
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.action-row .status-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 260px;
  align-items: flex-start;
}

.status-line {
  display: flex;
  gap: var(--space-12);
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
  font-size: 14px;
  color: #e6ebf7;
  font-weight: 600;
}

.status-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
}

.action-meta {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.action-row .action-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  flex: 0 0 260px;
}

.primary-buttons {
  display: flex;
  gap: var(--space-12);
  width: 100%;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.primary-buttons button {
  flex: 1 1 auto;
  min-width: 140px;
}

.turnstile-wrap {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.review-row {
  align-items: center;
  gap: var(--space-12);
}

.review-row .history-controls {
  flex-wrap: wrap;
}

.control-bay .banner,
.control-bay .error-block {
  width: 100%;
  margin-top: var(--space-12);
}

.control-bay .selected-move {
  margin: 6px 0 0;
}

.selected-move {
  margin-top: var(--space-12);
  font-size: 14px;
}

.promotion-chooser {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3;
}

.promotion-chooser.show {
  display: flex;
}

.promotion-chooser .promotion-band {
  background: rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  padding: 10px 12px;
  display: flex;
  gap: var(--space-12);
  align-items: center;
  pointer-events: auto;
  flex-wrap: wrap;
}

.promotion-buttons {
  display: flex;
  gap: var(--space-12);
}

.promotion-buttons .promo-btn {
  background: rgba(255, 255, 255, 0);
  color: var(--text-primary);
  border: none;
  padding: 6px 8px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 64px;
  outline: none;
}

.promotion-buttons .promo-btn.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.promotion-piece {
  width: 52px;
  height: 52px;
  display: block;
}

code {
  background: var(--surface-strong);
  padding: 2px 6px;
  border-radius: var(--radius-tight);
  border: 1px solid var(--border);
}

.muted {
  color: var(--text-secondary);
}

.error {
  color: var(--error);
  font-weight: 700;
}

.ok {
  color: var(--success);
  font-weight: 700;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.score-line {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-16);
  padding-top: 10px;
  letter-spacing: 0.02em;
  border-top: 1px solid var(--border);
  display: block;
  opacity: 0.9;
}

textarea,
input,
select {
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px;
  background: var(--input-bg);
  color: var(--text-primary);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  flex-wrap: wrap;
  margin-top: var(--space-12);
}

.copy-note {
  min-width: 70px;
  color: var(--success);
  font-weight: 700;
}

.banner {
  display: none;
  margin-top: var(--space-12);
  padding: 12px 14px;
  background: rgba(16, 20, 28, 0.7);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent-strong);
  border-radius: var(--radius);
  color: var(--text-primary);
}

.banner.show {
  display: flex;
  gap: var(--space-12);
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

.spinner.show {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-block {
  display: none;
  margin-top: var(--space-12);
  padding: 12px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: var(--radius);
  color: var(--error);
  white-space: pre-line;
}

.error-block.show {
  display: block;
}

.gameover-banner {
  display: none;
  margin-top: var(--space-12);
  padding: 14px;
  border: 1px solid var(--warn);
  background: rgba(242, 180, 100, 0.08);
  border-radius: var(--radius);
  gap: var(--space-12);
}

.gameover-banner.show {
  display: flex;
  flex-direction: column;
}

.gameover-banner h3 {
  margin: 0 0 4px;
}

#gameOverBody {
  margin: 0;
}

.gameover-actions {
  display: flex;
  gap: var(--space-12);
  flex-wrap: wrap;
}

.history-row {
  margin-top: var(--space-16);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.history-controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
}

.history-buttons {
  display: flex;
  gap: var(--space-12);
  flex-wrap: wrap;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 90px;
  justify-content: center;
  text-align: center;
}

.history-chip.ok {
  color: var(--success);
  border-color: rgba(108, 214, 155, 0.5);
}

.history-chip.error {
  color: var(--error);
  border-color: rgba(255, 107, 107, 0.6);
}

.history-status {
  font-size: 14px;
  margin: 0;
  font-weight: 700;
}

.extra-actions {
  display: flex;
  gap: var(--space-12);
  flex-wrap: wrap;
  margin-top: var(--space-12);
  align-items: center;
  font-size: 14px;
}

.board-disabled {
  pointer-events: none;
  opacity: 0.6;
  filter: grayscale(1);
}

.hidden {
  display: none !important;
}

.app-footer {
  margin-top: var(--space-32);
  padding: 14px 0 6px;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

.app-footer .footer-note {
  margin: 0;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus-visible {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.state-card {
  display: none;
  margin-top: var(--space-12);
}

.copy-status,
.resend-status,
#redirectNote {
  color: var(--text-secondary);
}

.hud-details {
  margin-top: var(--space-12);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.details-toggle {
  align-self: flex-start;
  background: var(--glass);
  color: var(--text-primary);
  border-color: var(--border);
  padding: 10px 14px;
}

.details-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.hud-details-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-details-panel .notation-controls {
  display: flex;
  gap: var(--space-12);
  align-items: center;
  flex-wrap: wrap;
}

.hud-details-panel #notationMount {
  margin-top: 2px;
}

.game-snapshot {
  margin: 6px 0 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tight);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.details-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
  margin: 2px 0 4px;
  opacity: 0.7;
}

.details-advanced {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
}

.details-advanced-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-12);
}

.details-advanced-title {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.notation-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notation-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
}

.notation-label {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.notation-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.notation-readout {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: var(--radius-tight);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.6;
  margin: 0;
}

.notation-readout--fen {
  white-space: pre;
  overflow-x: auto;
  overflow-wrap: normal;
  word-break: normal;
  line-height: normal;
}

.notation-readout--pgn {
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.6;
  max-height: 260px;
  overflow-y: auto;
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--glass);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 140ms ease, transform 140ms ease, background 120ms ease, border-color 120ms ease;
  z-index: 60;
  touch-action: manipulation;
  overflow: visible;
}

.back-to-top.visible {
  opacity: 0.92;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border);
}

.back-to-top:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.back-to-top svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (min-width: 1024px) {
  .wrap {
    padding-left: 32px;
    padding-right: 32px;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding: 24px 14px 48px;
  }

  button,
  .button-link {
    width: 100%;
    justify-content: center;
  }

  .controls,
  .history-controls,
  .extra-actions,
  .gameover-actions,
  .copy-row,
  .primary-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .control-bay {
    padding: var(--space-12);
  }

  .copy-note {
    min-width: auto;
  }
}

@media (max-width: 768px) {
  body::before {
    filter: blur(3px) saturate(0.95) contrast(1.02);
    opacity: 0.28;
    position: absolute;
    background-attachment: scroll;
  }

  body::after {
    position: absolute;
    background:
      radial-gradient(120% 120% at 50% 40%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.42) 100%),
      radial-gradient(70% 70% at 15% 20%, rgba(255, 255, 255, 0.03), transparent 38%),
      linear-gradient(180deg, rgba(4, 7, 12, 0.7) 0%, rgba(4, 7, 12, 0.84) 100%);
  }

  .stage-card {
    padding: 18px;
  }

  .control-row {
    flex-direction: column;
    align-items: stretch;
  }

  .action-row .action-stack {
    width: 100%;
    align-items: stretch;
    flex: 0 0 auto;
    min-height: 0;
    gap: 6px;
  }

  .action-row .status-stack {
    flex: 1 1 auto;
    gap: 4px;
  }

  .primary-buttons {
    justify-content: stretch;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .primary-buttons button {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.3;
  }

  .turnstile-wrap {
    justify-content: flex-start;
    margin-top: 0;
  }

  .turnstile-wrap .cf-turnstile {
    margin: 0;
  }

  .board-stack {
    gap: var(--space-12);
  }

  .scoreboard {
    padding: 10px 12px;
    gap: 6px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
  }

  .score-grid {
    gap: 8px;
  }

  .score-item {
    min-height: 52px;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
  }

  .score-label {
    font-size: 11px;
  }

  .score-value {
    font-size: 20px;
  }

  .control-bay {
    padding: 12px;
    gap: 6px;
    margin-top: var(--space-16);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
    background: rgba(255, 255, 255, 0.015);
  }

  .status-line {
    gap: 8px;
    font-size: 13px;
  }

  .control-row.review-row {
    margin-top: 0;
  }

  .review-row {
    gap: 10px;
  }

  .history-controls {
    gap: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  .history-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .history-chip {
    padding: 6px 10px;
    min-width: auto;
    font-size: 13px;
  }

  .banner {
    margin-top: 8px;
    padding: 10px 12px;
    font-size: 13px;
    border-width: 1px;
  }

  .banner.show {
    gap: 8px;
  }

  #updateBanner button {
    width: auto;
    padding: 8px 10px;
    font-size: 14px;
  }

  .control-bay .selected-move,
  .selected-move {
    margin-top: 6px;
    font-size: 13px;
  }

  .hud-details {
    margin-top: 8px;
    gap: 6px;
  }

  .details-toggle {
    padding: 9px 12px;
    font-size: 14px;
  }

  .hud-details-panel {
    padding: 10px;
    gap: 8px;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
  }

  .game-snapshot {
    padding: 8px 10px;
    gap: 6px;
  }

  .snapshot-row {
    gap: 8px;
  }

  .details-advanced {
    gap: 6px;
  }

  .notation-readout {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .wrap {
    padding-left: 12px;
    padding-right: 12px;
  }

  .stage-card {
    padding: 14px;
  }

  .board-stack {
    gap: 10px;
  }

  .scoreboard {
    padding: 9px 10px;
    gap: 6px;
  }

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

  .score-item:nth-child(3) {
    grid-column: 1 / -1;
  }

  .score-item {
    min-height: 50px;
    padding: 8px 10px;
  }

  .score-label {
    font-size: 10px;
    letter-spacing: 0.06em;
  }

  .score-value {
    font-size: 18px;
  }

  .score-last {
    font-size: 12px;
  }

  .control-bay {
    padding: 10px;
    gap: 4px;
  }

  .status-line {
    font-size: 12.5px;
  }

  .primary-buttons {
    gap: 8px;
  }

  .primary-buttons button {
    padding: 9px 10px;
    font-size: 14px;
  }

  .turnstile-wrap {
    margin-top: 0;
    margin-bottom: 2px;
  }

  .history-buttons {
    gap: 6px;
  }

  .history-chip {
    font-size: 12px;
    padding: 6px 8px;
  }

  #historyNotice {
    font-size: 12px;
    padding: 8px 10px;
  }

  #updateBanner {
    align-items: flex-start;
  }

  #updateBanner button {
    margin-left: auto;
  }

  .control-bay .selected-move,
  .selected-move {
    font-size: 12.5px;
    margin-top: 4px;
  }

  .hud-details-panel {
    padding: 9px;
  }

  .game-snapshot {
    padding: 7px 9px;
  }
}

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

  .spinner {
    animation: none;
  }
}
