:root {
  --ink: #0e120f;
  --panel: #1a241c;
  --panel-lit: #26352a;
  --signal: #e8a020;
  --signal-lit: #ffc14a;
  --text: #e8e0d0;
  --muted: #9aab9a;
  --font-display: "Bungee", "Arial Black", sans-serif;
  --font-ui: "Nunito", "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 16px;
  color: var(--text);
  background: var(--ink);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* —— 3D canvas host —— */
.view-host {
  position: fixed;
  inset: 0;
  z-index: 0;
}
.board-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.board-canvas.is-grabbing {
  cursor: grabbing;
}

.orbit-fab {
  position: fixed;
  right: 0.7rem;
  top: 46%;
  transform: translateY(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: auto;
}
.orbit-glyph {
  display: inline-block;
  font-size: 1.35rem;
  line-height: 1;
}
.orbit-glyph.mirror {
  transform: scaleX(-1);
}
.orbit-hint {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: -0.35rem 0 0.85rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

button,
a.btn,
select {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  min-height: 46px;
  padding: 0.55em 1.25em;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 800;
  font-size: 0.95rem;
  transition: transform 0.12s var(--ease), filter 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:active {
  transform: scale(0.98);
}
.btn:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--signal-lit), var(--signal));
  color: #1a1206;
  box-shadow: 0 2px 0 #8a5a10;
}
.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: rgba(38, 53, 42, 0.92);
  border: 1px solid rgba(232, 224, 208, 0.2);
  color: var(--text);
  backdrop-filter: blur(6px);
}
.btn-secondary:hover {
  border-color: var(--signal);
}

.btn-ghost {
  background: rgba(20, 30, 22, 0.65);
  border: 1px solid rgba(232, 224, 208, 0.18);
  color: var(--muted);
  backdrop-filter: blur(6px);
}
.btn-ghost:hover {
  border-color: rgba(232, 224, 208, 0.4);
  color: var(--text);
}

.btn-icon {
  width: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.25rem;
  background: rgba(38, 53, 42, 0.92);
  border: 1px solid rgba(232, 224, 208, 0.18);
  border-radius: 4px;
}

.back-btn {
  background: rgba(38, 53, 42, 0.92);
  border: 1px solid rgba(232, 224, 208, 0.18);
  padding-inline: 0.85em;
  font-size: 0.95rem;
}

.hamburger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 18px;
  height: 14px;
}
.hamburger span {
  display: block;
  height: 2px;
  border-radius: 1px;
  background: var(--text);
}

.pause-card {
  width: min(340px, 100%);
}

.piece-red {
  color: #ff6b6b;
  font-weight: 800;
}
.piece-black {
  color: #c0c0c0;
  font-weight: 800;
}

/* —— Splash —— */
.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem 1rem 1.5rem;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(8, 12, 9, 0.55) 0%,
    rgba(8, 12, 9, 0.15) 38%,
    rgba(8, 12, 9, 0.75) 100%
  );
}
html.is-playing .splash {
  display: none;
}

.splash-stage {
  width: min(400px, 100%);
  text-align: center;
  pointer-events: auto;
  animation: fadeIn 0.45s var(--ease);
}

.splash-eyebrow {
  font-size: 0.8rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.splash-brand {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 10vw, 3.4rem);
  letter-spacing: 0.04em;
  line-height: 1.05;
  color: var(--signal-lit);
  text-shadow: 0 3px 0 #8a5a10, 0 0 40px rgba(232, 160, 32, 0.25);
  margin-bottom: 0.4rem;
}

.splash-tag {
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1.35;
  margin-bottom: 0.9rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

.board-picker {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  text-align: left;
}
.board-picker-label {
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.board-picker select {
  width: 100%;
  min-height: 44px;
  padding: 0.5em 0.85em;
  border-radius: 4px;
  background: rgba(26, 36, 28, 0.92);
  border: 1px solid rgba(232, 224, 208, 0.22);
  color: var(--text);
  font-weight: 700;
  backdrop-filter: blur(6px);
}

.splash-cta {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.splash-cta .btn {
  width: 100%;
}

/* —— Overlays —— */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 12, 9, 0.72);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease;
}
.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, var(--panel-lit), var(--panel));
  border: 1px solid rgba(232, 224, 208, 0.15);
  border-radius: 8px;
  padding: 1.35rem 1.25rem 1.15rem;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.overlay-card h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  color: var(--signal-lit);
  margin-bottom: 0.5rem;
}

.overlay-sub {
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.4;
  margin-bottom: 1rem;
}

.diff-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.diff-grid .btn {
  width: 100%;
}

.tutorial-card {
  width: min(460px, 100%);
  text-align: left;
}
.tutorial-card h2 {
  text-align: center;
}

.tut-body {
  min-height: 180px;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.45;
  margin-bottom: 1rem;
}
.tut-body h3 {
  font-size: 1.1rem;
  color: var(--signal-lit);
  margin-bottom: 0.4rem;
}
.tut-body p + p,
.tut-body ul {
  margin-top: 0.65rem;
}
.tut-body ul {
  padding-left: 1.15rem;
}
.tut-body li {
  margin-bottom: 0.35rem;
}
.tut-body strong {
  color: #fff;
}

.tut-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.tut-page {
  font-size: 0.9rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

/* —— Game HUD —— */
.game-app {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  animation: fadeIn 0.35s var(--ease);
}
.game-app[hidden] {
  display: none !important;
}
/* Keep chrome clear of the top ad strip when it is visible. */
body.fg-ads-reserve .game-app {
  top: var(--fg-ad-h);
}
.game-app .hud,
.game-app .side-panels {
  pointer-events: auto;
}

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: rgba(20, 30, 22, 0.82);
  border-bottom: 1px solid rgba(232, 224, 208, 0.08);
  backdrop-filter: blur(8px);
}

.hud-center {
  text-align: center;
  min-width: 0;
}
.turn-label {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}
.status-label {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.1em;
}

.blitz-clocks {
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 0.35rem;
}
.blitz-clocks.hidden {
  display: none;
}
.clock {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 5.6rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(8, 12, 9, 0.55);
  border: 1px solid rgba(232, 224, 208, 0.14);
  font-variant-numeric: tabular-nums;
}
.clock-label {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.clock-time {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.clock-red .clock-time {
  color: #ff8a80;
}
.clock-black .clock-time {
  color: #eceff1;
}
.clock.is-active {
  border-color: rgba(255, 213, 79, 0.65);
  box-shadow: 0 0 0 1px rgba(255, 213, 79, 0.25), 0 0 12px rgba(255, 193, 7, 0.18);
}
.clock.is-low .clock-time {
  color: #ff5252;
  animation: clockPulse 0.7s ease-in-out infinite;
}
.clock.is-flagged {
  opacity: 0.55;
}

#rushScore .clock,
#kingScore .clock,
#chainScore .clock {
  min-width: 4.8rem;
}

@keyframes clockPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.hud-actions {
  display: flex;
  gap: 0.35rem;
}

.side-panels {
  margin-top: auto;
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem 0.85rem;
  justify-content: space-between;
  background: linear-gradient(180deg, transparent, rgba(8, 12, 9, 0.55));
}
.capture-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-height: 22px;
  flex: 1;
}
.capture-tray .chip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  opacity: 0.85;
}
.capture-tray .chip.red {
  background: #c62828;
}
.capture-tray .chip.black {
  background: #333;
  border: 1px solid #555;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

html.is-playing .orbit-fab {
  top: 40%;
}

@media (max-width: 420px) {
  .hud {
    padding: 0.5rem;
  }
  .turn-label {
    font-size: 0.95rem;
  }
  .splash {
    align-items: flex-end;
  }
}
