/* ============================
   Whisper — Horror Tic Tac Toe
   Design tokens
============================ */
:root {
  --bg-void: #0a0908;
  --bg-panel: #1a1614;
  --blood: #8b0000;
  --blood-deep: #3d0000;
  --bone: #c9c2b8;
  --bone-dim: #7a746c;
  --glow: rgba(139, 0, 0, 0.55);

  --font-display: "Nosifer", system-ui, sans-serif;
  --font-body: "JetBrains Mono", monospace;
}

/* ============================
   Theme variants
   Applied via data-theme on <html>
============================ */

/* Ash — grey, fog-heavy, low dread */
html[data-theme="ash"] {
  --bg-void: #0d0d0d;
  --bg-panel: #1c1c1c;
  --blood: #8a8a8a;
  --blood-deep: #3a3a3a;
  --bone: #e4e0da;
  --bone-dim: #8c8c8c;
  --glow: rgba(140, 140, 140, 0.45);
}

/* Void — near-black, minimal red, pure unease */
html[data-theme="void"] {
  --bg-void: #000000;
  --bg-panel: #0c0c0c;
  --blood: #4a0000;
  --blood-deep: #1a0000;
  --bone: #9a958d;
  --bone-dim: #4a463f;
  --glow: rgba(74, 0, 0, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-void);
  overflow: hidden;
  font-family: var(--font-body);
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============================
   Shared: title & flicker
============================ */
.game-title {
  font-family: var(--font-display);
  color: var(--bone);
  font-size: clamp(2.4rem, 10vw, 4.5rem);
  text-align: center;
  text-shadow: 0 0 12px var(--glow), 0 0 40px var(--blood-deep);
  letter-spacing: 0.05em;
}

.game-title.small {
  font-size: clamp(1.4rem, 6vw, 2rem);
}

.game-subtitle {
  text-align: center;
  color: var(--bone-dim);
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 0.5rem;
}

@keyframes flicker {
  0%, 19%, 21%, 23%, 100% { opacity: 1; }
  20%, 22% { opacity: 0.35; }
  50% { opacity: 1; }
  52% { opacity: 0.6; }
  53% { opacity: 1; }
}

.flicker {
  animation: flicker 6s infinite;
}

/* ============================
   Reusable stone button
============================ */
.btn-stone {
  border: 1px solid #3a332e;
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),
    var(--bg-panel);
  color: var(--bone);
  padding: 0.9rem 1.8rem;
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.95rem;
  box-shadow: 0 0 25px rgba(0,0,0,0.6), inset 0 0 15px rgba(0,0,0,0.4);
  transition: all 0.25s ease;
}

.btn-stone:hover {
  color: #fff;
  border-color: var(--blood);
  box-shadow: 0 0 20px var(--glow), inset 0 0 15px rgba(0,0,0,0.4);
}

/* ============================
   Start screen
============================ */
#start-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 1.2s ease;
}

#start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

#bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.4) brightness(0.5);
}

.fog-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 0%, var(--bg-void) 85%);
}

.start-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  padding: 0 1.5rem;
  text-align: center;
}

#mute-toggle,
#settings-toggle {
  position: fixed;
  top: 1.2rem;
  z-index: 3;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--bone-dim);
  background: rgba(10, 9, 8, 0.6);
  color: var(--bone);
}

#mute-toggle {
  right: 1.2rem;
}

#settings-toggle {
  right: 4.4rem;
}

/* ============================
   Back arrow (mode-select & game screens)
============================ */
.back-btn {
  position: fixed;
  top: 1.2rem;
  left: 1.2rem;
  z-index: 3;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--bone-dim);
  background: rgba(10, 9, 8, 0.6);
  color: var(--bone);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.back-btn:hover {
  color: #fff;
  border-color: var(--blood);
  box-shadow: 0 0 14px var(--glow);
}

/* ============================
   Inline settings gear (mode-select & game screens)
============================ */
.settings-toggle-inline {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 3;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--bone-dim);
  background: rgba(10, 9, 8, 0.6);
  color: var(--bone);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.settings-toggle-inline:hover {
  color: #fff;
  border-color: var(--blood);
  box-shadow: 0 0 14px var(--glow);
}

/* ============================
   Generic visibility utility
   (start-screen keeps its own fade rule below, so it is excluded here)
============================ */
.hidden:not(#start-screen) {
  display: none !important;
}

/* ============================
   Settings panel
============================ */
#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
}

.settings-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.8rem;
  padding: 2rem 1.5rem;
  text-align: center;
  border: 1px solid #3a332e;
  border-radius: 10px;
  background: var(--bg-panel);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
  max-width: 90vw;
}

.theme-options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid #3a332e;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--bone-dim);
  padding: 0.8rem 1rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.2s ease;
}

.theme-swatch:hover {
  color: var(--bone);
  border-color: var(--bone-dim);
}

.theme-swatch.active {
  color: var(--bone);
  border-color: var(--blood);
  box-shadow: 0 0 14px var(--glow);
}

.swatch-preview {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.swatch-blood {
  background: radial-gradient(circle at 35% 30%, #8b0000, #0a0908 75%);
}

.swatch-ash {
  background: radial-gradient(circle at 35% 30%, #8a8a8a, #0d0d0d 75%);
}

.swatch-void {
  background: radial-gradient(circle at 35% 30%, #4a0000, #000000 75%);
}

/* ============================
   Mode select screen
============================ */
#mode-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: radial-gradient(ellipse at center, #1a1614 0%, var(--bg-void) 75%);
}

.mode-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 0 1.5rem;
  text-align: center;
}

.mode-title {
  font-family: var(--font-display);
  color: var(--bone);
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  text-shadow: 0 0 12px var(--glow);
  letter-spacing: 0.04em;
}

.mode-options {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.mode-btn,
.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  min-width: 9.5rem;
}

.mode-sub {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--bone-dim);
  text-transform: none;
  font-weight: 400;
}

/* ============================
   Game screen
============================ */
#game-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem 1rem;
  background:
    radial-gradient(ellipse at top, #1a1614 0%, var(--bg-void) 70%);
}

#game-screen.thinking #board {
  pointer-events: none;
  opacity: 0.85;
}

.game-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.game-header {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.turn-indicator {
  color: var(--bone-dim);
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#turn-symbol {
  color: var(--blood);
  font-weight: 700;
}

/* ============================
   Scoreboard
============================ */
.scoreboard {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid #3a332e;
  border-radius: 8px;
  background: rgba(26, 22, 20, 0.6);
  box-shadow: inset 0 0 12px rgba(0,0,0,0.5);
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.2rem;
}

.score-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bone-dim);
}

.score-value {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--bone);
  text-shadow: 0 0 8px var(--glow);
}

.score-item:first-child .score-value {
  color: var(--blood);
}

/* ============================
   Board
============================ */
#board {
  width: min(85vw, 360px);
  height: min(85vw, 360px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  background: #000;
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 0 60px rgba(0,0,0,0.7), 0 0 30px var(--blood-deep);
}

.cell {
  background:
    linear-gradient(160deg, #221d1a, #14100e);
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2rem, 9vw, 3.2rem);
  font-family: var(--font-display);
  color: transparent;
  transition: background 0.2s ease, box-shadow 0.3s ease;
}

.cell:not(:disabled):hover {
  background: linear-gradient(160deg, #2b2420, #181310);
}

.cell.mark-o {
  color: var(--blood);
  text-shadow: 0 0 14px var(--glow);
}

.cell.mark-x {
  color: var(--bone);
  text-shadow: 0 0 10px rgba(201, 194, 184, 0.4);
}

.cell.win-line {
  animation: bleed 1s ease-in-out infinite alternate;
}

@keyframes bleed {
  from { box-shadow: inset 0 0 10px var(--glow); }
  to   { box-shadow: inset 0 0 35px var(--blood); }
}

/* ============================
   Result overlay
============================ */
#result-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0);
  pointer-events: none;
  transition: background 0.6s ease;
}

#result-overlay.show {
  background: rgba(0,0,0,0.75);
  pointer-events: auto;
}

#result-text {
  font-family: var(--font-display);
  color: var(--blood);
  font-size: clamp(1.6rem, 8vw, 3rem);
  text-align: center;
  text-shadow: 0 0 20px var(--glow);
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.6s ease;
}

#result-overlay.show #result-text {
  opacity: 1;
  transform: scale(1);
}

/* ============================
   Responsive
============================ */
@media (max-width: 400px) {
  .btn-stone { padding: 0.75rem 1.4rem; font-size: 0.85rem; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .flicker, .cell.win-line { animation: none; }
}
