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

:root {
  /* ── Papyrus palette (updated by applyTheme) ── */
  --paper:        #f1dfb1;
  --paper-dark:   #d8be84;
  --paper-shadow: #a98447;
  --ink:          #2a1a08;
  --accent:       #8a4a1a;
  --p1-ink:       #9b3b14;
  --p1-soft:      #c97a3d;
  --p2-ink:       #3a4a8a;
  --p2-soft:      #6a7ac0;

  /* ── Legacy vars (modals, chaos, audio) ── */
  --egypt-gold:   #D4A017;
  --egypt-sand:   #F2D77E;
  --egypt-dark:   #1A0A00;
  --egypt-brown:  #7B4A1E;
  --egypt-teal:   #1B6E6E;
  --hindu-orange: #FF6B35;
  --hindu-saffron:#FF9933;
  --hindu-purple: #6A0572;
  --hindu-rose:   #E91E8C;
  --hindu-green:  #228B22;
  --bg-dark:      #0D0D0D;
  --cell-bg:      rgba(255,240,200,0.05);
  --cell-hover:   rgba(255,240,200,0.18);
  --p1-rgb:       212, 160, 23;
  --p2-rgb:       255, 153, 51;
}

/* ── Reset ── */
html, body {
  min-height: 100%;
  background: var(--paper-shadow);
  color: var(--ink);
  font-family: 'IM Fell DW Pica', 'Cormorant Garamond', Georgia, serif;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

/* ── Papyrus background layers ── */
.app-paper-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
.paper-base {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, var(--paper) 0%, var(--paper-dark) 65%, var(--paper-shadow) 100%);
  transition: background 0.5s cubic-bezier(0.4,0,0.2,1);
}
.paper-grain {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(80,50,20,0.025) 3px 4px),
    repeating-linear-gradient(90deg, transparent 0 5px, rgba(80,50,20,0.018) 5px 6px),
    repeating-linear-gradient(34deg, transparent 0 10px, rgba(120,80,40,0.015) 10px 12px);
  mix-blend-mode: multiply;
  opacity: 0.9;
}
.paper-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(40,20,0,0.18) 80%, rgba(20,10,0,0.4) 100%);
  pointer-events: none;
}

/* ── Decorative corner glyphs ── */
.corner {
  position: fixed;
  font-size: 3rem;
  color: var(--ink);
  opacity: 0.08;
  pointer-events: none;
  z-index: 0;
  animation: pulse 4s ease-in-out infinite;
}
.corner.tl { top: 12px;  left: 14px; }
.corner.tr { top: 12px;  right: 14px; animation-delay: 1s; }
.corner.bl { bottom: 12px; left: 14px; animation-delay: 2s; }
.corner.br { bottom: 12px; right: 14px; animation-delay: 3s; }
@keyframes pulse { 0%,100%{opacity:.06} 50%{opacity:.14} }

/* ── Page layout ── */
.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 28px 60px;
  gap: 28px;
}

/* ── Masthead ── */
header { width: 100%; max-width: 1240px; }

.masthead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 8px 0 4px;
}

.masthead-rule {
  height: 14px;
  background-image:
    linear-gradient(0deg,
      transparent 0, transparent 3px,
      var(--ink) 3px, var(--ink) 4px,
      transparent 4px, transparent 7px,
      var(--ink) 7px, var(--ink) 7.6px,
      transparent 7.6px, transparent 11px,
      var(--ink) 11px, var(--ink) 12px,
      transparent 12px);
  opacity: 0.55;
}

.masthead-titleblock {
  text-align: center;
  padding: 0 24px;
}

.masthead-eyebrow {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.72rem;
  letter-spacing: 0.35em;
  color: var(--ink);
  opacity: 0.6;
  margin-bottom: 8px;
}

.masthead-title {
  font-family: 'IM Fell DW Pica', serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.8rem, 4.5vw, 3.4rem);
  line-height: 0.95;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.masthead-title .amp {
  font-style: italic;
  font-size: 0.75em;
  color: var(--accent);
  margin: 0 0.05em;
  display: inline-block;
  transform: translateY(-0.05em) rotate(-4deg);
}

.masthead-sub {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.85rem;
  letter-spacing: 0.3em;
  color: var(--accent);
  margin-top: 6px;
  opacity: 0.85;
}

/* ── Player cards ── */
.players {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 1240px;
}

.player-card {
  position: relative;
  border-radius: 2px;
  padding: 18px 22px 18px;
  min-width: 150px;
  text-align: center;
  transition: transform 0.4s ease, box-shadow 0.4s ease, background 0.5s;
  cursor: default;
  background: radial-gradient(ellipse at 50% 30%, rgba(255,245,215,0.35) 0%, transparent 70%);
  border: 1px solid rgba(40,20,0,0.18);
  isolation: isolate;
}

.player-card.egypt  { transform: rotate(-0.6deg); }
.player-card.hindu  { transform: rotate(0.4deg); }

.player-card.active-turn {
  transform: translateY(-4px) rotate(0deg);
  box-shadow: 0 0 0 1px rgba(40,20,0,0.3), 0 8px 24px rgba(40,20,0,0.18);
}
.player-card.egypt.active-turn { transform: translateY(-4px) rotate(-0.2deg); }
.player-card.hindu.active-turn { transform: translateY(-4px) rotate(0.2deg); }

/* Papyrus winner glow */
@keyframes winnerGlow1 {
  0%,100% { box-shadow: 0 0 0 1px rgba(40,20,0,0.2), 0 4px 20px rgba(155,59,20,0.35); }
  50%     { box-shadow: 0 0 0 1px rgba(40,20,0,0.2), 0 8px 40px rgba(155,59,20,0.7); }
}
@keyframes winnerGlow2 {
  0%,100% { box-shadow: 0 0 0 1px rgba(40,20,0,0.2), 0 4px 20px rgba(58,74,138,0.35); }
  50%     { box-shadow: 0 0 0 1px rgba(40,20,0,0.2), 0 8px 40px rgba(58,74,138,0.7); }
}
.player-card.egypt.winner-glow { animation: winnerGlow1 1.2s ease-in-out infinite; }
.player-card.hindu.winner-glow { animation: winnerGlow2 1.2s ease-in-out infinite; }

/* dotted top rule */
.pc-rule {
  position: absolute;
  left: 12px; right: 12px;
  height: 2px;
  top: 10px;
  background: repeating-linear-gradient(90deg, var(--p1-ink) 0 6px, transparent 6px 14px);
}
.player-card.hindu .pc-rule {
  background: repeating-linear-gradient(90deg, var(--p2-ink) 0 6px, transparent 6px 14px);
}

/* symbol */
.player-symbol {
  font-size: 2.8rem;
  line-height: 1;
  filter: url(#ink-bleed-main);
  color: var(--p1-ink);
  margin-top: 10px;
  display: block;
}
.player-card.hindu .player-symbol { color: var(--p2-ink); }

/* pip below symbol */
.pc-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--p1-ink);
  margin: 6px auto 0;
  display: none;
}
.player-card.hindu .pc-pip { background: var(--p2-ink); }
.player-card.active-turn .pc-pip { display: block; animation: pip-pulse 1.4s ease-in-out infinite; }
@keyframes pip-pulse {
  0%,100% { transform: scale(1); opacity: 0.8; }
  50%     { transform: scale(1.4); opacity: 1; }
}

/* Turn crown — hidden (replaced by pip) */
.turn-crown { display: none; }

.player-name {
  font-family: 'IM Fell DW Pica', serif;
  font-style: italic;
  font-size: 1.4rem;
  line-height: 1.1;
  color: var(--ink);
  margin-top: 6px;
}
.player-card.egypt .player-name { color: var(--p1-ink); }
.player-card.hindu .player-name { color: var(--p2-ink); }

.player-title {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.68rem;
  letter-spacing: 0.24em;
  color: var(--ink);
  opacity: 0.75;
  margin-top: 3px;
}

.player-lore {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--ink);
  opacity: 0.6;
  margin-top: 10px;
  max-width: 220px;
  margin-left: auto;
  margin-right: auto;
}

.player-score {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dotted rgba(40,20,0,0.22);
  font-family: 'IM Fell DW Pica', serif;
  font-style: italic;
  font-size: 2.8rem;
  line-height: 1;
  color: var(--p1-ink);
}
.player-card.hindu .player-score { color: var(--p2-ink); }

.score-label {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.58rem;
  letter-spacing: 0.24em;
  color: var(--ink);
  opacity: 0.5;
  margin-top: 2px;
}

.session-rate  { font-size: .52rem; color: rgba(40,20,0,0.4); letter-spacing: .06em; margin-top: 2px; min-height: .8rem; }

/* Card corner glyphs */
.player-card-corners {
  position: absolute;
  inset: 8px;
  pointer-events: none;
  font-family: 'IM Fell DW Pica', serif;
  font-size: 1rem;
}
.pcc {
  position: absolute;
  opacity: 0.3;
}
.pcc-tl { top: 0;    left: 0; }
.pcc-tr { top: 0;    right: 0; }
.pcc-bl { bottom: 0; left: 0; }
.pcc-br { bottom: 0; right: 0; }

/* VS badge */
.vs-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  font-family: 'IM Fell DW Pica', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--ink);
  opacity: 0.45;
  align-self: center;
  flex-shrink: 0;
}

/* ── Theme selector ── */
.theme-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  border-top: 1px dotted rgba(40,20,0,0.14);
  border-bottom: 1px dotted rgba(40,20,0,0.14);
  padding: 6px 0;
}
.theme-btn {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 7px 14px;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  opacity: 0.45;
  transition: opacity 0.2s, border-color 0.2s;
  position: relative;
}
.theme-btn:hover  { opacity: 0.85; }
.theme-btn.active {
  opacity: 1;
  border-bottom: 2px solid var(--p1-ink);
  color: var(--p1-ink);
}
.theme-btn.active::before,
.theme-btn.active::after {
  content: '·';
  position: absolute;
  top: 50%; transform: translateY(-50%);
  opacity: 0.6;
}
.theme-btn.active::before { left: 4px; }
.theme-btn.active::after  { right: 4px; }

/* ── Mode selector ── */
.mode-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.mode-btn {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  border: 1px solid rgba(40,20,0,0.18);
  border-radius: 0;
  padding: 8px 16px;
  cursor: pointer;
  background: rgba(255,245,215,0.12);
  color: var(--ink);
  opacity: 0.45;
  transition: all .2s;
}
.mode-btn:hover  { opacity: 0.85; background: rgba(255,245,215,0.22); }
.mode-btn.active {
  opacity: 1;
  background: rgba(255,245,215,0.28);
  color: var(--p1-ink);
  border-color: var(--p1-ink);
}

/* ── Status bar ── */
.status {
  text-align: center;
  min-height: 40px;
  padding: 0 12px;
  width: 100%;
  max-width: 500px;
}
.status-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: center;
  font-family: 'IM Fell DW Pica', serif;
  font-style: italic;
  font-size: clamp(0.9rem, 3.2vw, 1.2rem);
  min-height: 36px;
}
@keyframes status-fade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.status-flourish {
  font-size: 1rem;
  opacity: 0.5;
  color: var(--accent);
  flex-shrink: 0;
}

.status-text { letter-spacing: 0.02em; }
.status-text.egypt-msg { color: var(--p1-ink); }
.status-text.hindu-msg { color: var(--p2-ink); }
.status-text.draw-msg  { color: var(--ink); }
.status-text.hint-msg  { color: var(--accent); }

/* ── Board wrapper ── */
.board-wrapper {
  position: relative;
  width: min(calc(100vw - 32px), 500px);
}

.board-aura {
  position: absolute;
  inset: -30px;
  border-radius: 0;
  pointer-events: none;
  z-index: -1;
  transition: background 1s;
}

/* ── Board stage ── */
.board-stage {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  padding: 20px;
}

.board-corners {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: 'IM Fell DW Pica', serif;
  font-size: 1.5rem;
}
.bc {
  position: absolute;
  opacity: 0.45;
}
.bc-tl { top: -2px;    left: -2px; }
.bc-tr { top: -2px;    right: -2px; }
.bc-bl { bottom: -2px; left: -2px; }
.bc-br { bottom: -2px; right: -2px; }

/* ── Board paper ── */
.board-paper {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: var(--paper);
  background-image: radial-gradient(ellipse at 50% 30%, rgba(255,245,215,0.35) 0%, transparent 70%);
  border: 1px solid rgba(40,20,0,0.22);
  box-shadow:
    inset 0 0 0 4px var(--paper),
    inset 0 0 0 5px rgba(40,20,0,0.1),
    0 4px 18px rgba(40,20,0,0.15);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: rotate(-0.3deg);
  transition: background-color 0.5s, border-color 0.5s;
}

.paper-wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(170,120,60,0.10) 0%, transparent 25%),
    radial-gradient(circle at 80% 70%, rgba(140,90,40,0.08) 0%, transparent 30%),
    radial-gradient(circle at 60% 20%, rgba(100,60,20,0.06) 0%, transparent 35%);
  pointer-events: none;
}
.paper-noise {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(80,50,20,0.03) 2px 3px),
    repeating-linear-gradient(90deg, transparent 0 4px, rgba(80,50,20,0.02) 4px 5px);
  pointer-events: none;
  mix-blend-mode: multiply;
}
.paper-stains {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse 30px 12px at 8% 88%, rgba(120,80,30,0.18) 0%, transparent 100%),
    radial-gradient(ellipse 18px 8px at 92% 6%, rgba(120,80,30,0.14) 0%, transparent 100%),
    radial-gradient(ellipse 14px 14px at 78% 92%, rgba(150,90,40,0.10) 0%, transparent 100%),
    radial-gradient(ellipse 22px 10px at 14% 12%, rgba(150,90,40,0.10) 0%, transparent 100%);
}

.hborder {
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.border-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Board grid ── */
.board {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  padding: 26px;
  isolation: isolate;
}

/* board locked while AI thinks */
.board.ai-thinking { pointer-events: none; opacity: .75; }
.board.ai-thinking .cell:not(.taken) { animation: aiPulse 1s ease-in-out infinite; }
@keyframes aiPulse { 0%,100%{opacity:.4} 50%{opacity:.7} }

/* board settle on game-over */
@keyframes boardSettle {
  0%  { transform: scale(1);    }
  25% { transform: scale(1.03); }
  65% { transform: scale(0.98); }
  100%{ transform: scale(1);    }
}
.board.game-over { animation: boardSettle 0.55s cubic-bezier(0.34,1.56,0.64,1); }

/* SVG grid lines (injected by JS) */
.grid-lines-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* SVG win-line */
.win-line-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}
.win-line-path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: ink-draw 0.7s 0.2s cubic-bezier(0.5,0.1,0.3,1) forwards;
}
@keyframes ink-draw {
  to { stroke-dashoffset: 0; }
}

/* Legacy win-line overlay — hidden (SVG replaces it) */
.win-line-overlay { display: none !important; }

/* ── Cells ── */
.cell {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  background: rgba(255,240,200,0.05);
  border: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s;
  z-index: 1;
  user-select: none;
}

.cell:hover:not(.taken) {
  background: rgba(255,240,200,0.18);
}
.cell.taken { cursor: default; }

/* Cell symbol span */
.cell-sym {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 68%;
  height: 68%;
  font-family: 'IM Fell DW Pica', serif;
  font-size: 2.2rem;
  filter: url(#ink-bleed-main);
  animation: glyph-stamp 0.5s cubic-bezier(0.34,1.56,0.64,1) backwards;
}
@keyframes glyph-stamp {
  0%   { opacity: 0; transform: scale(0.4) rotate(-12deg); }
  60%  { opacity: 1; transform: scale(1.08) rotate(2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

/* winning cell glow */
.cell.win-cell {
  animation: cell-glow 1.4s ease-in-out infinite;
}
@keyframes cell-glow {
  0%,100% { background-color: rgba(255,240,200,0.15); }
  50%     { background-color: rgba(255,240,200,0.30); }
}

/* last-placed ring */
.cell.fresh .cell-sym::after {
  content: '';
  position: absolute;
  inset: -4%;
  border: 1px dashed currentColor;
  border-radius: 50%;
  opacity: 0;
  animation: last-ring 1s ease-out;
  pointer-events: none;
}
@keyframes last-ring {
  0%   { opacity: 0.5; transform: scale(0.6); }
  100% { opacity: 0;   transform: scale(1.3); }
}

/* coordinate label */
.coord-label {
  position: absolute;
  top: 5px;
  left: 7px;
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.52rem;
  letter-spacing: 0;
  color: var(--ink);
  opacity: 0.16;
  pointer-events: none;
  user-select: none;
}
.cell:hover:not(.taken) .coord-label { opacity: 0.45; }

/* hover preview */
.board:not(.game-over):not(.ai-thinking) .cell:not(.taken):hover::before {
  content: var(--hover-sym-display, '');
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IM Fell DW Pica', serif;
  font-size: clamp(1.8rem, 8vw, 3.2rem);
  color: var(--hover-ink, var(--p1-ink));
  opacity: 0.15;
  pointer-events: none;
  animation: hoverFadeIn .14s ease-out;
}
@keyframes hoverFadeIn {
  from { opacity: 0; transform: scale(.6); }
  to   { opacity: .15; transform: scale(1); }
}

/* keyboard focus */
.cell:focus { outline: none; }
.cell:focus-visible {
  box-shadow: 0 0 0 3px rgba(var(--p1-rgb),.5), 0 0 10px rgba(var(--p1-rgb),.25) !important;
  z-index: 2;
}

/* fog of war */
.cell.fog-hidden { color: rgba(40,20,0,0.25) !important; font-size: 1.4rem !important; }

/* phantom veil */
.board.phantom-veil .cell.taken { color: transparent !important; transition: color .1s; }

/* ghost cell */
.cell.ghost-cell {
  opacity: .32 !important;
  filter: blur(1.5px);
  animation: ghostFloat 2.2s ease-in-out infinite !important;
}
@keyframes ghostFloat {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-5px); }
}

/* cell shake */
@keyframes cellShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-7px); }
  40%     { transform: translateX(7px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}
.cell.shaking { animation: cellShake .4s ease-out; }

/* holy ground */
.cell.holy-cell { cursor: not-allowed !important; background: rgba(255,215,0,.06) !important; border: 1px solid rgba(255,215,0,.35) !important; }
.cell.holy-cell::before { content: '✦'; display: flex !important; align-items: center; justify-content: center; color: rgba(255,215,0,.45); font-size: 1rem; pointer-events: none; }

/* threat highlighting */
@keyframes threatPulse {
  0%,100% { box-shadow: inset 0 0 0 2px currentColor; opacity: .55; }
  50%     { box-shadow: inset 0 0 0 3px currentColor; opacity: .9; }
}
.cell.threat-egypt {
  color: rgba(var(--p1-rgb), .7);
  animation: threatPulse 1.1s ease-in-out infinite;
}
.cell.threat-hindu {
  color: rgba(var(--p2-rgb), .7);
  animation: threatPulse 1.1s ease-in-out infinite;
}
.cell.threat-egypt.threat-hindu { color: rgba(255,220,100,.75); }

/* hint cell */
@keyframes hintPulse {
  0%,100% { box-shadow: inset 0 0 0 3px rgba(40,20,0,0.5), 0 0 16px rgba(40,20,0,0.2); }
  50%     { box-shadow: inset 0 0 0 4px rgba(40,20,0,0.85), 0 0 28px rgba(40,20,0,0.4); }
}
.cell.hint-cell { animation: hintPulse .65s ease-in-out infinite !important; }

/* Board skins */
.board-wrapper.skin-marble .board-paper { filter: saturate(.5); }
.board-wrapper.skin-neon .board-paper   { filter: hue-rotate(200deg) saturate(.4) contrast(1.1); }

/* ── Undo shake ── */
@keyframes undoShake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  45%  { transform: translateX(5px); }
  70%  { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}
.board.undo-shake { animation: undoShake .38s ease-out; }

/* ── Sandstorm shake — both board-paper and board-wrapper (compat) ── */
@keyframes sandstorm {
  0%,100% { transform: translate(0,0) rotate(0deg); }
  12%     { transform: translate(-5px, 2px) rotate(-.4deg); }
  25%     { transform: translate(4px, -3px) rotate(.3deg); }
  37%     { transform: translate(-4px, 1px) rotate(-.2deg); }
  50%     { transform: translate(5px, -2px) rotate(.4deg); }
  62%     { transform: translate(-3px, 3px) rotate(-.3deg); }
  75%     { transform: translate(3px, -1px) rotate(.2deg); }
  87%     { transform: translate(-2px, 2px) rotate(-.1deg); }
}
.board-wrapper.shaking { animation: sandstorm 0.38s ease-out; }
.board-paper.shaking   { animation: sandstorm 0.38s ease-out; }

/* Board flash on win */
@keyframes boardFlash {
  0%   { opacity: 0; transform: scale(.85); }
  20%  { opacity: 1; transform: scale(1.02); }
  100% { opacity: 0; transform: scale(1.15); }
}
.board-wrapper.win-flash-egypt::after,
.board-wrapper.win-flash-hindu::after {
  content: '';
  position: absolute; inset: -24px;
  pointer-events: none; z-index: 5;
  animation: boardFlash .85s ease-out forwards;
}
.board-wrapper.win-flash-egypt::after { background: radial-gradient(circle, rgba(var(--p1-rgb),.32) 0%, transparent 68%); }
.board-wrapper.win-flash-hindu::after { background: radial-gradient(circle, rgba(var(--p2-rgb),.32) 0%, transparent 68%); }

/* ── Move quality badge ── */
.move-badge {
  position: absolute; top: 5px; right: 5px;
  width: 18px; height: 18px; border-radius: 50%;
  font-size: .6rem; font-weight: 900; line-height: 18px;
  text-align: center; pointer-events: none; z-index: 5;
  animation: badgePop 1.55s ease forwards;
}
.quality-best    { background: #22c55e; color: #fff; box-shadow: 0 0 8px #22c55e; }
.quality-fine    { background: #eab308; color: #1a1200; box-shadow: 0 0 8px #eab308; }
.quality-blunder { background: #ef4444; color: #fff; box-shadow: 0 0 8px #ef4444; }
@keyframes badgePop {
  0%  { transform: scale(0); opacity: 0; }
  15% { transform: scale(1.3); opacity: 1; }
  25% { transform: scale(1); opacity: 1; }
  70% { opacity: 1; }
  100%{ transform: scale(.5) translateY(-4px); opacity: 0; }
}

/* ── Win seal overlay ── */
.win-seal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(40,20,0,0.45) 0%, rgba(20,10,0,0.78) 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
.win-seal.visible { opacity: 1; pointer-events: auto; }

.win-seal-card {
  position: relative;
  background: var(--paper);
  background-image:
    radial-gradient(ellipse at 30% 30%, rgba(255,245,215,0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 70%, rgba(140,90,40,0.12) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(80,50,20,0.03) 3px 4px);
  border: 2px solid var(--p1-ink);
  padding: 38px 48px 30px;
  max-width: 480px;
  text-align: center;
  transform: rotate(-1.2deg);
  box-shadow:
    0 12px 40px rgba(0,0,0,0.5),
    inset 0 0 0 1px rgba(40,20,0,0.2),
    inset 0 0 0 8px var(--paper);
  animation: seal-arrive 0.6s cubic-bezier(0.2,0.8,0.3,1.4) backwards;
}
@keyframes seal-arrive {
  from { opacity: 0; transform: rotate(-12deg) scale(0.6); }
  to   { opacity: 1; transform: rotate(-1.2deg) scale(1); }
}

.win-seal-stamp {
  position: absolute;
  top: -38px;
  right: -28px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--paper);
  animation: stamp-arrive 0.7s 0.3s cubic-bezier(0.2,0.9,0.3,1.5) backwards;
}
@keyframes stamp-arrive {
  from { opacity: 0; transform: rotate(40deg) scale(2); }
  to   { opacity: 1; transform: rotate(-7deg) scale(1); }
}

.win-seal-cry {
  font-family: 'IM Fell DW Pica', serif;
  font-style: italic;
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  line-height: 1.05;
  margin-bottom: 14px;
  letter-spacing: 0.02em;
}

.win-seal-line {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--ink);
  opacity: 0.75;
  margin-bottom: 26px;
  line-height: 1.45;
  padding: 0 12px;
}

.win-seal-btn {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  padding: 12px 28px;
  border: 1.5px solid;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s;
}
.win-seal-btn:hover { background: rgba(40,20,0,0.06); }

/* ── Controls ── */
.controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1200px;
}

.btn {
  font-family: 'IM Fell DW Pica SC', 'Cinzel', serif;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  border: 1px solid rgba(40,20,0,0.3);
  border-radius: 0;
  padding: 10px 22px;
  cursor: pointer;
  background: rgba(255,245,215,0.2);
  color: var(--ink);
  transition: transform .2s, background .2s;
  position: relative;
}
.btn:hover  { background: rgba(255,245,215,0.38); transform: translateY(-1px); }
.btn:active { transform: translateY(0px); }

.btn-restart {
  background: rgba(var(--p1-rgb),.18);
  color: var(--p1-ink);
  border-color: rgba(var(--p1-rgb),.38);
}
.btn-restart:hover { background: rgba(var(--p1-rgb),.28); }

.btn-reset-score {
  background: rgba(255,245,215,0.12);
  color: rgba(40,20,0,0.55);
  border: 1px solid rgba(40,20,0,0.18);
}
.btn-reset-score:hover { background: rgba(255,245,215,0.22); color: var(--ink); }

.btn-music {
  background: rgba(255,245,215,0.12);
  color: rgba(40,20,0,0.55);
  border: 1px solid rgba(40,20,0,0.18);
}
.btn-music:hover  { background: rgba(255,245,215,0.22); color: var(--ink); }
.btn-music.on {
  background: rgba(255,245,215,0.32);
  color: var(--p1-ink);
  border-color: rgba(var(--p1-rgb),.4);
}

/* ── Volume sliders ── */
.vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 64px;
  height: 4px;
  border-radius: 2px;
  background: rgba(40,20,0,0.2);
  outline: none;
  cursor: pointer;
  vertical-align: middle;
  flex-shrink: 0;
}
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--p1-ink);
  cursor: pointer;
}
.vol-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border: none; border-radius: 50%;
  background: var(--p1-ink);
  cursor: pointer;
}
#vol-music::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--p2-ink);
  cursor: pointer;
}
#vol-music::-moz-range-thumb {
  width: 14px; height: 14px;
  border: none; border-radius: 50%;
  background: var(--p2-ink);
  cursor: pointer;
}

/* ── Timer duration select ── */
.timer-select {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,245,215,0.15);
  border: 1px solid rgba(40,20,0,0.18);
  border-radius: 0;
  color: var(--ink);
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: .7rem;
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
  transition: border-color .2s;
}
.timer-select:hover { border-color: rgba(40,20,0,0.38); }
.timer-select option { background: #f1dfb1; color: #2a1a08; }

/* ── Undo button ── */
.btn-undo:disabled { opacity: .28; cursor: not-allowed; }

/* ── Hint / Replay / Analysis ── */
.btn-hint   { background: rgba(255,245,215,0.18); border: 1px solid rgba(40,20,0,0.22); color: var(--accent); }
.btn-hint:hover:not(:disabled) { background: rgba(255,245,215,0.32); }
.btn-replay { background: rgba(var(--p1-rgb),.10); border: 1px solid rgba(var(--p1-rgb),.30); color: var(--p1-ink); }
.btn-replay:hover:not(:disabled) { background: rgba(var(--p1-rgb),.20); }
.btn-share { background: rgba(255,245,215,0.12); border: 1px solid rgba(40,20,0,0.18); color: var(--ink); }
.btn-share:hover  { background: rgba(255,245,215,0.22); }
.btn-share.copied { color: #3a6a3a; border-color: rgba(58,106,58,.4); background: rgba(58,106,58,.08); }
.btn-install { background: rgba(var(--p1-rgb),.14); border: 1px solid rgba(var(--p1-rgb),.3); color: var(--p1-ink); }
.btn-install:hover { background: rgba(var(--p1-rgb),.24); }

/* ── Fun row ── */
.fun-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.fun-btn {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  border: 1px solid rgba(40,20,0,0.14);
  border-radius: 0;
  padding: 5px 12px;
  cursor: pointer;
  background: rgba(255,245,215,0.08);
  color: rgba(40,20,0,0.4);
  transition: all .2s;
}
.fun-btn:hover  { background: rgba(255,245,215,0.18); color: var(--ink); }
.fun-btn.active, .fun-btn.on {
  background: rgba(255,245,215,0.28);
  color: var(--p1-ink);
  border-color: rgba(var(--p1-rgb),.4);
}
.btn-fog.on { background: rgba(160,210,255,.12); border-color: rgba(160,210,255,.3); color: #6a8aaa; }

/* ── Match row ── */
.match-row {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; justify-content: center;
}
.match-label {
  font-family: 'IM Fell DW Pica SC', serif; font-size: .62rem;
  color: rgba(40,20,0,0.45); letter-spacing: .1em;
  text-transform: uppercase; margin-right: 4px;
}
.match-btn {
  font-family: 'IM Fell DW Pica SC', serif; font-size: .62rem;
  letter-spacing: .08em;
  border: 1px solid rgba(40,20,0,0.14);
  border-radius: 0; padding: 6px 12px;
  cursor: pointer; background: rgba(255,245,215,0.08);
  color: rgba(40,20,0,0.38); transition: all .2s;
}
.match-btn:hover { background: rgba(255,245,215,0.18); color: var(--ink); }
.match-btn.active {
  background: rgba(255,245,215,0.28);
  color: var(--p1-ink); border-color: rgba(var(--p1-rgb),.38);
}

/* ── Skin row ── */
.skin-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 2px;
}
.skin-btn {
  width: 32px; height: 32px;
  border-radius: 0;
  border: 1px solid rgba(40,20,0,0.14);
  background: rgba(255,245,215,0.08);
  cursor: pointer; font-size: .9rem;
  line-height: 32px; text-align: center;
  transition: all .2s;
}
.skin-btn:hover { background: rgba(255,245,215,0.18); }
.skin-btn.active {
  border-color: var(--p1-ink);
  background: rgba(var(--p1-rgb),.12);
}

/* ── Timer bar ── */
.timer-wrap {
  width: 100%; max-width: 380px;
  height: 5px; background: rgba(40,20,0,0.08);
  border-radius: 2px; overflow: hidden; display: none;
}
.timer-wrap.active { display: block; }
.timer-fill {
  height: 100%; border-radius: 2px; width: 100%;
  background: var(--p1-ink);
  transition: background-color .5s;
}
.timer-fill.urgent { background: #cc2200; animation: urgentPulse .5s ease-in-out infinite alternate; }
@keyframes urgentPulse { from { opacity: 1; } to { opacity: .55; } }

/* ── Eval bar ── */
.eval-wrap {
  display: flex; align-items: center; gap: 7px; justify-content: center;
  max-width: 360px; margin: 5px auto 0;
}
.eval-label {
  font-size: .6rem; font-family: 'IM Fell DW Pica SC', serif; letter-spacing: .05em;
  opacity: .55; min-width: 28px; text-align: center;
  color: var(--ink);
}
.eval-bar {
  display: flex; height: 4px; border-radius: 0; overflow: hidden;
  flex: 1; max-width: 280px;
  background: rgba(40,20,0,0.08);
}
.eval-fill { height: 100%; transition: width .55s cubic-bezier(.4,0,.2,1); }
.eval-egypt { background: linear-gradient(90deg, rgba(var(--p1-rgb),1), rgba(var(--p1-rgb),.55)); }
.eval-hindu { background: linear-gradient(90deg, rgba(var(--p2-rgb),.55), rgba(var(--p2-rgb),1)); }

/* ── Draws row ── */
.draws-row {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: .72rem; letter-spacing: .18em;
  color: rgba(40,20,0,0.45); text-align: center;
}
.draws-row span { color: var(--ink); }

/* ── Footer symbols ── */
.footer-symbols {
  display: flex; gap: 24px; font-size: 1.5rem;
  color: var(--ink); opacity: .18;
  animation: pulse 6s ease-in-out infinite;
}

/* ── Score pop ── */
@keyframes scorePop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.55); }
  100% { transform: scale(1); }
}
.player-score.pop { animation: scorePop .42s cubic-bezier(.22,1.6,.36,1); }

/* ── Match pips ── */
.match-pips {
  display: flex; gap: 5px; justify-content: center;
  margin-top: 6px; min-height: 12px;
}
.match-pip {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(40,20,0,.15);
  transition: background .3s, transform .3s;
}
.match-pip.filled {
  background: var(--p1-ink); transform: scale(1.2);
  box-shadow: 0 0 6px rgba(var(--p1-rgb),.5);
}
#pips-hindu .match-pip.filled {
  background: var(--p2-ink);
  box-shadow: 0 0 6px rgba(var(--p2-rgb),.5);
}
.match-need { font-size: .52rem; letter-spacing: .06em; color: rgba(40,20,0,.38); margin-top: 3px; }

/* Match-point state */
@keyframes matchPointPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(var(--p1-rgb), 0); }
  50%     { box-shadow: 0 0 0 8px rgba(var(--p1-rgb), .22); }
}
.player-card.egypt.match-point { animation: matchPointPulse 1.4s ease-in-out infinite; }
@keyframes matchPointPulse2 {
  0%,100% { box-shadow: 0 0 0 0 rgba(var(--p2-rgb), 0); }
  50%     { box-shadow: 0 0 0 8px rgba(var(--p2-rgb), .22); }
}
.player-card.hindu.match-point { animation: matchPointPulse2 1.4s ease-in-out infinite; }
.player-card.match-point .match-need { color: var(--p1-ink); font-weight: 700; }
.player-card.hindu.match-point .match-need { color: var(--p2-ink); }

/* ── Match victory overlay ── */
.match-victory {
  position: fixed; inset: 0; background: rgba(0,0,0,.88);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  z-index: 2000; opacity: 0; pointer-events: none;
  transition: opacity .4s;
}
.match-victory.visible { opacity: 1; pointer-events: auto; }
.mv-symbol { font-size: clamp(4rem, 18vw, 8rem); animation: mvSymPulse 1.5s ease-in-out infinite; }
@keyframes mvSymPulse {
  0%,100% { transform: scale(1);    filter: drop-shadow(0 0 20px rgba(var(--p1-rgb),.6)); }
  50%     { transform: scale(1.12); filter: drop-shadow(0 0 40px rgba(var(--p1-rgb),1)); }
}
.mv-title {
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: clamp(1.4rem, 6vw, 2.8rem);
  color: var(--p1-ink); text-align: center;
  animation: fadeSlideUp .6s .15s both;
}
.mv-subtitle {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: clamp(.8rem, 3vw, 1.1rem);
  color: rgba(40,20,0,.6); text-align: center;
  animation: fadeSlideUp .6s .3s both;
}
.mv-btn {
  margin-top: 8px; font-family: 'IM Fell DW Pica SC', serif;
  font-size: .9rem; letter-spacing: .12em;
  border: 1px solid rgba(40,20,0,.4); border-radius: 0;
  padding: 14px 36px; cursor: pointer;
  background: rgba(255,245,215,.22);
  color: var(--ink); transition: all .25s;
  animation: fadeSlideUp .6s .45s both;
}
.mv-btn:hover { background: rgba(255,245,215,.38); }
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Restore game banner ── */
.restore-banner {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  background: rgba(var(--p1-rgb), .08); border: 1px solid rgba(var(--p1-rgb), .2);
  border-radius: 2px; padding: 10px 16px; margin: 8px auto;
  max-width: 420px; font-size: .78rem; color: var(--ink);
  animation: statsSlideIn .35s cubic-bezier(.22,1,.36,1);
}
.restore-msg { flex: 1; }
.restore-yes, .restore-no {
  font-size: .7rem; font-weight: 700; letter-spacing: .06em;
  border: 1px solid rgba(40,20,0,.18); border-radius: 2px; padding: 5px 12px; cursor: pointer;
}
.restore-yes { background: rgba(var(--p1-rgb), .18); color: var(--p1-ink); }
.restore-no  { background: rgba(255,245,215,.12); color: rgba(40,20,0,.5); }
.restore-yes:hover { background: rgba(var(--p1-rgb), .30); }
.restore-no:hover  { background: rgba(255,245,215,.22); }

/* ── Game summary toast ── */
.game-summary {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(235,220,180,.96);
  border: 1px solid rgba(40,20,0,.22);
  border-radius: 2px; padding: 8px 20px;
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: .74rem; color: var(--ink);
  letter-spacing: .06em; pointer-events: none;
  z-index: 2000; opacity: 0;
  transition: opacity .35s, transform .35s; white-space: nowrap;
}
.game-summary.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Intro overlay ── */
.intro-overlay {
  position: fixed; inset: 0; background: rgba(5,2,0,.93);
  backdrop-filter: blur(6px); z-index: 200;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 32px; cursor: pointer; opacity: 0;
  pointer-events: none; transition: opacity .35s;
}
.intro-overlay.active { opacity: 1; pointer-events: all; }
.intro-inner {
  display: flex; align-items: center; gap: 28px;
  width: 90%; max-width: 560px;
}
.intro-player {
  flex: 1; text-align: center;
  opacity: 0; transition: opacity .5s, transform .5s;
}
.intro-left  { transform: translateX(-50px); }
.intro-right { transform: translateX(50px);  }
.intro-player.shown { opacity: 1; transform: translateX(0); }
.intro-symbol {
  font-size: clamp(3.2rem, 10vw, 4.8rem);
  line-height: 1;
  animation: introBob 2.4s ease-in-out infinite;
}
@keyframes introBob {
  0%,100% { transform: translateY(0) scale(1); }
  50%     { transform: translateY(-7px) scale(1.1); }
}
.intro-name {
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: clamp(.8rem, 3vw, 1.1rem); font-weight: 400;
  letter-spacing: .08em; margin-top: 10px;
}
.intro-tagline {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: clamp(.55rem, 2vw, .7rem); letter-spacing: .06em;
  color: rgba(255,255,255,.55); margin-top: 8px;
  line-height: 1.55; padding: 0 4px;
}
.intro-vs {
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: clamp(1.2rem, 5vw, 1.9rem); font-weight: 400;
  color: rgba(255,255,255,.18); flex-shrink: 0;
  opacity: 0; transition: opacity .4s;
}
.intro-vs.shown { opacity: 1; }
.intro-begin {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: clamp(.85rem, 3.5vw, 1.35rem);
  letter-spacing: .28em; color: rgba(255,245,215,.85);
  opacity: 0; transform: scale(.85);
  transition: opacity .5s, transform .5s;
}
.intro-begin.shown { opacity: 1; transform: scale(1); }
.intro-skip {
  font-size: .52rem; letter-spacing: .25em;
  opacity: .18; text-transform: uppercase; color: #fff;
}

/* ── Lore toast ── */
.lore-toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: rgba(235,220,180,.97);
  border: 1px solid rgba(40,20,0,.22);
  border-radius: 2px; padding: 13px 18px;
  max-width: min(440px, calc(100vw - 32px));
  display: flex; gap: 12px; align-items: flex-start;
  opacity: 0; transition: opacity .45s, transform .45s;
  z-index: 150; pointer-events: none;
  box-shadow: 0 6px 28px rgba(0,0,0,.25);
}
.lore-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.lore-toast-icon { font-size: 1.25rem; flex-shrink: 0; margin-top: 1px; }
.lore-toast-text {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: .72rem; letter-spacing: .05em;
  line-height: 1.65; color: var(--ink);
}

/* ── Chaos bar ── */
.chaos-bar {
  display: flex; gap: 6px; justify-content: center;
  flex-wrap: wrap; min-height: 0; overflow: hidden;
  transition: min-height .3s, margin-bottom .3s;
}
.chaos-bar.active { min-height: 28px; margin-bottom: 2px; }
.chaos-rule-chip {
  font-size: .66rem; padding: 3px 10px;
  border-radius: 2px;
  background: rgba(255,200,0,.10);
  border: 1px solid rgba(255,200,0,.25);
  color: rgba(255,220,100,.8);
  letter-spacing: .04em;
  animation: chipIn .4s ease-out forwards; opacity: 0;
  transition: opacity .3s;
}
.chaos-rule-chip.used { opacity: 0.25; text-decoration: line-through; }
@keyframes chipIn { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.chaos-gear-btn {
  background: none; border: 1px solid rgba(255,200,0,.18);
  border-radius: 50%; width: 24px; height: 24px;
  font-size: .72rem; cursor: pointer;
  color: rgba(255,220,100,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 0; transition: color .2s, border-color .2s; flex-shrink: 0;
}
.chaos-gear-btn:hover { color: rgba(255,220,100,.9); border-color: rgba(255,200,0,.45); }

.chaos-config-panel {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  padding: 10px 12px;
  background: rgba(235,220,180,.55);
  border: 1px solid rgba(40,20,0,.14);
  border-radius: 0; margin-top: -4px; margin-bottom: 4px;
}
.chaos-config-title {
  width: 100%; text-align: center; font-size: .6rem;
  letter-spacing: .1em; color: rgba(40,20,0,.45);
  text-transform: uppercase; font-family: 'IM Fell DW Pica SC', serif; margin-bottom: 2px;
}
.chaos-rule-toggle {
  font-size: .63rem; padding: 3px 9px; border-radius: 2px;
  cursor: pointer; border: 1px solid rgba(40,20,0,.14);
  background: rgba(255,245,215,.12); color: rgba(40,20,0,.4);
  transition: all .18s;
}
.chaos-rule-toggle.on {
  background: rgba(255,200,0,.14); border-color: rgba(255,200,0,.35);
  color: rgba(120,80,0,.9);
}
.chaos-rule-toggle:hover { opacity: .85; }

/* Chaos overlay */
.chaos-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.93);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; z-index: 1100; opacity: 0;
  pointer-events: none; transition: opacity .3s;
}
.chaos-overlay.active { opacity: 1; pointer-events: all; }
.chaos-title {
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: clamp(1.1rem, 4vw, 1.6rem); font-weight: 400;
  letter-spacing: .12em; color: #fff;
  animation: chaosPulse 1s ease-in-out infinite alternate;
}
@keyframes chaosPulse {
  from { text-shadow: 0 0 20px rgba(255,200,0,.5), 0 0 40px rgba(255,100,0,.3); }
  to   { text-shadow: 0 0 55px rgba(255,255,0,.95), 0 0 90px rgba(255,150,0,.65); }
}
.chaos-subtitle {
  font-size: .7rem; letter-spacing: .12em;
  color: rgba(255,255,255,.45); text-transform: uppercase;
}
.chaos-list {
  display: flex; flex-direction: column; gap: 10px;
  max-width: 360px; width: 90%;
}
.chaos-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: rgba(255,200,0,.06); border: 1px solid rgba(255,200,0,.14);
  border-radius: 2px; padding: 10px 14px;
  opacity: 0; animation: chaosSlideUp .45s ease-out forwards;
}
.chaos-item:nth-child(1) { animation-delay: .08s; }
.chaos-item:nth-child(2) { animation-delay: .22s; }
.chaos-item:nth-child(3) { animation-delay: .36s; }
@keyframes chaosSlideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.chaos-item-icon { font-size: 1.25rem; flex-shrink: 0; }
.chaos-item-text strong {
  font-family: 'Cinzel', serif; font-size: .72rem;
  color: rgba(255,220,100,1); display: block; margin-bottom: 3px;
}
.chaos-item-text span { font-size: .62rem; color: rgba(255,255,255,.48); }
.chaos-skip {
  font-size: .58rem; letter-spacing: .12em;
  color: rgba(255,255,255,.28); text-transform: uppercase; margin-top: 6px;
}

/* Chaos event toast */
.chaos-event {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.85);
  background: rgba(235,220,180,.97);
  border: 2px solid rgba(40,20,0,.3);
  border-radius: 2px; padding: 11px 22px;
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: .88rem; letter-spacing: .04em;
  color: var(--ink); text-align: center;
  z-index: 900; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 82vw;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
}
.chaos-event.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* Solar flare */
.solar-flare {
  position: fixed; inset: 0; background: #fff8;
  z-index: 2000; pointer-events: none; opacity: 0;
}
.solar-flare.flash { animation: solarFlash .65s ease-out forwards; }
@keyframes solarFlash { 0% { opacity: .85; } 100% { opacity: 0; } }

/* ── AI thinking dots ── */
@keyframes thinkDot {
  0%,80%,100% { opacity: .2; }
  40%         { opacity: 1;  }
}
.thinking-dots span { animation: thinkDot 1.4s ease-in-out infinite; display: inline-block; }
.thinking-dots span:nth-child(2) { animation-delay: .2s; }
.thinking-dots span:nth-child(3) { animation-delay: .4s; }

/* ── Cell placement pop ── */
@keyframes cellPop {
  0%   { transform: scale(0.25) rotate(-8deg); opacity: 0; }
  60%  { transform: scale(1.18) rotate(2deg);  opacity: 1; }
  100% { transform: scale(1)    rotate(0deg);  opacity: 1; }
}
.cell.fresh { animation: cellPop .3s cubic-bezier(.22, 1.6, .36, 1); }

/* ── Lore modal ── */
.lore-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.65); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.lore-modal.visible { opacity: 1; pointer-events: all; }
.lore-inner {
  background: #1a0f00;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 2px; padding: 28px 28px 20px;
  max-width: 420px; width: 90%; max-height: 78vh; overflow-y: auto;
}
.lore-title {
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: 1rem; color: var(--egypt-sand);
  text-align: center; margin-bottom: 18px;
}
.lore-item {
  display: flex; gap: 10px; margin-bottom: 14px;
  font-size: .82rem; line-height: 1.65; color: rgba(255,255,255,.75);
}
.lore-num { color: var(--egypt-gold); font-weight: 700; flex-shrink: 0; min-width: 16px; }
.btn-lore-close { display: block; margin: 8px auto 0; }

/* ── Stats modal ── */
.stats-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 2100; opacity: 0; pointer-events: none; transition: opacity .3s;
}
.stats-modal.visible { opacity: 1; pointer-events: auto; }
.stats-inner {
  background: linear-gradient(160deg, rgba(var(--p1-rgb),.12), rgba(var(--p2-rgb),.08));
  border: 1px solid rgba(var(--p1-rgb),.25);
  border-radius: 2px; padding: 28px 24px;
  max-width: 360px; width: 90%;
  box-shadow: 0 8px 60px rgba(0,0,0,.7);
  animation: statsSlideIn .35s cubic-bezier(.22,1,.36,1);
}
@keyframes statsSlideIn {
  from { transform: scale(.88); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.stats-title {
  font-family: 'IM Fell DW Pica', serif; font-style: italic;
  font-size: 1.1rem; color: var(--egypt-gold);
  text-align: center; margin-bottom: 20px;
}
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px;
}
.stat-card { background: rgba(255,255,255,.05); border-radius: 2px; padding: 12px; text-align: center; }
.stat-val  { font-family: 'IM Fell DW Pica', serif; font-style: italic; font-size: 1.5rem; color: var(--egypt-gold); }
.stat-lbl  { font-family: 'IM Fell DW Pica SC', serif; font-size: .6rem; color: rgba(255,255,255,.4); letter-spacing: .1em; margin-top: 2px; }
.recent-games { text-align: center; margin: 14px 0 4px; }
.recent-label { font-size: .58rem; letter-spacing: .12em; color: rgba(255,255,255,.35); margin-bottom: 8px; }
.recent-dots { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.recent-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; box-shadow: 0 0 6px currentColor; }
.heat-section { text-align: center; margin: 16px 0 8px; }
.heat-title { font-size: .58rem; letter-spacing: .12em; color: rgba(255,255,255,.35); margin-bottom: 10px; }
.heat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px;
  max-width: 108px; margin: 0 auto;
}
.heat-cell {
  aspect-ratio: 1; border-radius: 2px;
  border: 1px solid rgba(255,255,255,.09);
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; font-weight: 700; color: rgba(255,255,255,.55); transition: background .3s;
}
.theme-stats-section { margin-bottom: 20px; }
.theme-stats-title {
  font-family: 'IM Fell DW Pica SC', serif; font-size: .65rem; letter-spacing: .12em;
  color: rgba(255,255,255,.38); text-align: center; margin-bottom: 12px;
}
.theme-stat-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; margin-bottom: 8px; }
.theme-stat-name { font-size: .72rem; color: rgba(255,255,255,.65); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theme-stat-bar { width: 90px; height: 6px; background: rgba(255,255,255,.08); border-radius: 2px; overflow: hidden; }
.theme-stat-fill { height: 100%; border-radius: 2px; background: linear-gradient(90deg, rgba(var(--p1-rgb),.7), rgba(var(--p2-rgb),.7)); transition: width .5s ease; }
.theme-stat-pct { font-size: .7rem; color: rgba(255,255,255,.45); width: 32px; text-align: right; }
.stats-actions { display: flex; gap: 10px; justify-content: center; }
.btn-stats-reset { background: rgba(255,68,68,.2); border: 1px solid rgba(255,68,68,.3); color: #ff8888; }
.btn-stats-reset:hover { background: rgba(255,68,68,.35); }
.btn-stats-close { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.15); color: rgba(255,255,255,.7); }
.btn-stats-close:hover { background: rgba(255,255,255,.12); }

/* ── Move log panel ── */
.move-log-panel { width: 100%; max-width: 420px; margin: 0 auto; }
.move-log-body {
  background: rgba(235,220,180,.35); border: 1px solid rgba(40,20,0,.12);
  border-radius: 2px; padding: 8px 10px; max-height: 120px; overflow-y: auto;
  margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-content: flex-start;
}
.log-entry { display: flex; align-items: center; gap: 3px; font-size: .65rem; opacity: .75; }
.egypt-entry { color: var(--p1-ink); }
.hindu-entry { color: var(--p2-ink); }
.log-turn { color: rgba(40,20,0,.38); font-size: .58rem; min-width: 14px; }
.log-sym  { font-size: .72rem; }
.log-pos  { font-family: monospace; font-size: .62rem; }
.log-badge { font-size: .55rem; font-weight: 700; opacity: .8; }
.log-badge.quality-best    { color: #3a8a3a; }
.log-badge.quality-fine    { color: rgba(40,20,0,.4); }
.log-badge.quality-blunder { color: #8a2a2a; }
.log-empty { font-size: .62rem; color: rgba(40,20,0,.3); font-style: italic; }
.btn-log.on { background: rgba(var(--p1-rgb),.15); border-color: rgba(var(--p1-rgb),.35); color: var(--p1-ink); }

/* ── Keyboard shortcut help ── */
.shortcut-help {
  position: fixed; inset: 0; z-index: 2200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.72); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.shortcut-help.visible { opacity: 1; pointer-events: auto; }
.shortcut-inner {
  background: #1a0f00; border: 1px solid rgba(255,255,255,.12);
  border-radius: 2px; padding: 28px 32px; max-width: 400px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.shortcut-title { font-family: 'IM Fell DW Pica', serif; font-style: italic; font-size: 1rem; color: var(--egypt-sand); margin-bottom: 18px; text-align: center; letter-spacing: .1em; }
.shortcut-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; align-items: center; }
.shortcut-grid kbd { font-family: monospace; font-size: .78rem; background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.22); border-radius: 3px; padding: 3px 8px; color: #fff; white-space: nowrap; text-align: center; }
.shortcut-grid span { font-size: .8rem; color: rgba(255,255,255,.65); }
.shortcut-close { text-align: center; margin-top: 18px; font-size: .72rem; color: rgba(255,255,255,.3); }

/* ── Rank badge ── */
.rank-badge {
  font-family: 'IM Fell DW Pica SC', serif; font-size: .6rem;
  letter-spacing: .07em; margin-top: 3px; min-height: 1em;
  transition: color .4s; opacity: .85;
}

/* ── Streak badge ── */
.streak-badge { font-size: .7rem; font-weight: 700; letter-spacing: .04em; min-height: 1em; color: var(--p1-ink); opacity: 0; transition: opacity .35s; }
.streak-badge.visible { opacity: 1; }

/* ── Achievement toast ── */
.ach-toast {
  position: fixed; top: 72px; right: -320px;
  background: rgba(235,220,180,.97);
  border: 1px solid rgba(40,20,0,.3);
  border-radius: 2px; padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
  z-index: 3000; transition: right .4s cubic-bezier(.22,1,.36,1);
  max-width: 280px; width: calc(100vw - 32px);
  box-shadow: 0 4px 32px rgba(0,0,0,.25);
}
.ach-toast.show { right: 16px; }
.ach-icon  { font-size: 1.9rem; flex-shrink: 0; }
.ach-label { font-family: 'IM Fell DW Pica SC', serif; font-size: .58rem; color: rgba(40,20,0,.55); letter-spacing: .12em; text-transform: uppercase; }
.ach-name  { font-family: 'IM Fell DW Pica', serif; font-style: italic; font-size: .9rem; color: var(--p1-ink); margin-top: 3px; }

/* ── Achievements modal ── */
.achievements-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.78); z-index: 3000;
  align-items: center; justify-content: center;
}
.achievements-modal.visible { display: flex; }
.achievements-inner {
  background: linear-gradient(145deg, #1a0f00, #2a1a08);
  border: 1px solid rgba(212,160,23,.35);
  border-radius: 2px; padding: 28px 20px 22px;
  max-width: 540px; width: 94%; max-height: 82vh;
  display: flex; flex-direction: column; gap: 12px;
}
.achievements-title { font-family: 'IM Fell DW Pica', serif; font-style: italic; font-size: 1.05rem; color: var(--egypt-gold); letter-spacing: .12em; text-align: center; }
.achievements-count { text-align: center; font-size: .72rem; color: rgba(255,255,255,.42); letter-spacing: .06em; }
.achievements-list { overflow-y: auto; display: flex; flex-direction: column; gap: 5px; flex: 1; padding-right: 4px; }
.ach-card { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 2px; border: 1px solid transparent; transition: all .2s; }
.ach-card.unlocked { background: rgba(212,160,23,.10); border-color: rgba(212,160,23,.24); }
.ach-card.locked { background: rgba(255,255,255,.03); border-color: rgba(255,255,255,.06); opacity: .52; filter: grayscale(.55); }
.ach-card-icon { font-size: 1.45rem; min-width: 32px; text-align: center; line-height: 1; }
.ach-card.locked .ach-card-icon { filter: grayscale(1); opacity: .38; }
.ach-card-body { display: flex; flex-direction: column; gap: 1px; }
.ach-card-name { font-family: 'Cinzel', serif; font-size: .76rem; font-weight: 700; color: rgba(255,255,255,.85); }
.ach-card.locked .ach-card-name { color: rgba(255,255,255,.32); }
.ach-card-desc { font-size: .7rem; color: rgba(255,255,255,.44); }
.ach-card-date { font-size: .64rem; color: var(--egypt-gold); opacity: .72; margin-top: 1px; }
.btn-achievements-close { align-self: center; }

/* ── Analysis modal ── */
.analysis-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.75); z-index: 3000;
  align-items: center; justify-content: center;
}
.analysis-modal.visible { display: flex; }
.analysis-inner {
  background: linear-gradient(145deg, #1a0f00, #2a1a08);
  border: 1px solid rgba(212,160,23,.35);
  border-radius: 2px; padding: 28px 24px 22px;
  max-width: 480px; width: 92%; max-height: 80vh;
  display: flex; flex-direction: column; gap: 14px;
}
.analysis-title { font-family: 'IM Fell DW Pica', serif; font-style: italic; font-size: 1.05rem; color: var(--egypt-gold); letter-spacing: .12em; text-align: center; }
.analysis-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; max-height: 52vh; padding-right: 4px; }
.analysis-entry { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.04); border-radius: 2px; padding: 7px 10px; font-size: .82rem; }
.analysis-turn { color: rgba(255,255,255,.35); min-width: 22px; font-size: .75rem; }
.analysis-sym { font-size: 1rem; min-width: 22px; text-align: center; }
.analysis-sym.egypt-entry { color: var(--egypt-gold); }
.analysis-sym.hindu-entry  { color: var(--hindu-saffron); }
.analysis-pos { font-family: monospace; color: rgba(255,255,255,.7); min-width: 28px; }
.analysis-badge { border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 700; flex-shrink: 0; }
.analysis-badge.quality-best   { background: rgba(72,199,116,.2); color: #48C774; }
.analysis-badge.quality-fine   { background: rgba(255,193,7,.2);  color: #FFC107; }
.analysis-badge.quality-blunder{ background: rgba(255,56,96,.2);  color: #FF3860; }
.analysis-best { font-size: .72rem; color: rgba(255,255,255,.4); font-style: italic; margin-left: auto; }
.analysis-empty { text-align: center; color: rgba(255,255,255,.35); padding: 20px 0; font-size: .88rem; }
.btn-analysis-close { align-self: center; }
.analysis-chaos-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.analysis-chaos-title { font-size: .67rem; letter-spacing: .1em; color: rgba(255,255,255,.32); text-transform: uppercase; margin-bottom: 6px; font-family: 'Cinzel', serif; }
.analysis-chaos-entry { display: flex; align-items: center; gap: 8px; font-size: .77rem; color: rgba(255,255,255,.58); padding: 3px 0; }

/* ── Keyboard focused cell ── */
.cell:focus { outline: none; }

/* ── Cell quality badge ── */
.cell-quality-badge {
  position: absolute; top: 4px; right: 5px;
  font-size: .6rem; font-weight: 700;
  pointer-events: none; z-index: 5;
  animation: cellBadgeFade 1.4s ease forwards;
}
.cell-quality-badge.quality-best    { color: #3a8a3a; }
.cell-quality-badge.quality-fine    { color: rgba(40,20,0,.35); }
.cell-quality-badge.quality-blunder { color: #8a2a2a; }
@keyframes cellBadgeFade {
  0%   { opacity: 1; transform: translateY(0) scale(1.2); }
  55%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px) scale(.85); }
}

/* ── Floating background particles ── */
.bg-particles { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-sym {
  position: absolute; bottom: -8%; opacity: 0;
  animation: bgFloat linear infinite;
  user-select: none; will-change: transform, opacity;
  color: var(--ink);
}
@keyframes bgFloat {
  0%   { transform: translateY(0)       rotate(0deg);   opacity: 0; }
  8%   { opacity: .055; }
  92%  { opacity: .028; }
  100% { transform: translateY(-110vh)  rotate(360deg); opacity: 0; }
}

/* ── Editable player names ── */
.player-name[contenteditable] {
  cursor: text; outline: none;
  border-bottom: 1px dashed transparent;
  transition: border-color .2s; padding-bottom: 2px;
}
.player-name[contenteditable]:hover { border-bottom-color: rgba(40,20,0,.28); }
.player-name[contenteditable]:focus { border-bottom-color: rgba(40,20,0,.55); background: rgba(255,245,215,.12); }

/* ── Touch action ── */
.cell, .btn, .fun-btn, .mode-btn, .theme-btn, .match-btn, .mv-btn,
.btn-stats-reset, .btn-stats-close { touch-action: manipulation; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;  /* infinite loops at .001ms would flicker */
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  /* Highlights that only exist inside a looping animation: show them statically */
  .cell.hint-cell    { box-shadow: inset 0 0 0 4px rgba(40,20,0,0.85), 0 0 20px rgba(40,20,0,0.3) !important; }
  .cell.threat-egypt,
  .cell.threat-hindu { box-shadow: inset 0 0 0 3px currentColor; opacity: .9; }
  .cell.win-cell     { background-color: rgba(255,240,200,0.35); }
  .player-card.egypt.winner-glow { box-shadow: 0 0 0 1px rgba(40,20,0,0.2), 0 6px 30px rgba(155,59,20,0.6); }
  .player-card.hindu.winner-glow { box-shadow: 0 0 0 1px rgba(40,20,0,0.2), 0 6px 30px rgba(58,74,138,0.6); }
  .player-card.egypt.match-point { box-shadow: 0 0 0 6px rgba(var(--p1-rgb), .22); }
  .player-card.hindu.match-point { box-shadow: 0 0 0 6px rgba(var(--p2-rgb), .22); }
}

/* ── Keyboard focus for controls that reset their outline ── */
.vol-slider:focus-visible,
.timer-select:focus-visible {
  outline: 2px solid var(--ink, #2a1a08);
  outline-offset: 3px;
}

/* ── Responsive ── */
@media (max-width: 540px) {
  .page { padding: 16px 12px 32px; gap: 16px; }
  .players { gap: 8px; flex-wrap: nowrap; width: 100%; }
  .player-card { padding: 10px 8px; min-width: 0; flex: 1; }
  .player-symbol { font-size: 2rem; }
  .player-name   { font-size: 1.1rem; }
  .player-title  { font-size: .56rem; letter-spacing: .1em; }
  .player-score  { font-size: 2rem; margin-top: 6px; }
  .score-label   { font-size: .52rem; }
  .vs-badge      { width: 34px; height: 34px; font-size: .8rem; flex-shrink: 0; }
  .board { gap: 6px; padding: 16px; }
  .controls { gap: 10px; width: 100%; flex-wrap: wrap; }
  .btn { padding: 12px 16px; font-size: .72rem; flex: 1; min-width: 100px; }
  .corner { font-size: 2rem; }
  .footer-symbols { gap: 14px; font-size: 1.1rem; }
  .player-card-corners { display: none; }
  .player-lore { display: none; }
}

@media (max-width: 360px) {
  .corner { display: none; }
  .player-title { display: none; }
  .player-lore  { display: none; }
}
