/* ============================================================
   TICTACTOE.NOW — Design System
   Clean, trustworthy, blue-accent UI (shared with Sudoku.by)
   ============================================================ */

:root {
  --blue: #3b82f6;
  --blue-dark: #1d4ed8;
  --blue-light: #eff6ff;
  --blue-border: #bfdbfe;
  --accent: #f59e0b;
  --accent-light: #fffbeb;
  --text: #1e293b;
  --text-muted: #475569;
  --text-light: #94a3b8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --x-color: #3b82f6;
  --o-color: #ef4444;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --nav-height: 62px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html { font-size: 16px; scroll-behavior: smooth; overflow-x: hidden; }
body { overflow-x: hidden; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--surface-2);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }
img, video, iframe, embed, object { max-width: 100%; display: block; }

/* ---- TYPOGRAPHY ---- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
p { margin-bottom: 1rem; color: var(--text-muted); }
p:last-child { margin-bottom: 0; }

/* ---- LAYOUT ---- */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.container-sm { max-width: 760px; margin: 0 auto; padding: 0 1.5rem; }
.container-lg { max-width: 1400px; margin: 0 auto; padding: 0 1.5rem; }
.page-wrap { padding: 2.5rem 0; }

/* ---- NAVIGATION ---- */
.site-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--nav-height);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.nav-inner {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 0;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--blue);
  letter-spacing: -0.5px;
  margin-right: 2rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-logo:hover { color: var(--blue-dark); }
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  list-style: none;
}
.nav-links a {
  display: block;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover,
.nav-links a.active { background: var(--blue-light); color: var(--blue); }

/* ---- NAV DROPDOWN ---- */
.nav-has-dropdown { position: relative; }
.nav-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.nav-dropdown-trigger:hover,
.nav-has-dropdown:hover .nav-dropdown-trigger,
.nav-has-dropdown:focus-within .nav-dropdown-trigger { background: var(--blue-light); color: var(--blue); }
.nav-dropdown-trigger svg { flex-shrink: 0; transition: transform .15s; }
.nav-has-dropdown:hover .nav-dropdown-trigger svg,
.nav-has-dropdown:focus-within .nav-dropdown-trigger svg { transform: rotate(180deg); }
.nav-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.14);
  min-width: 220px;
  padding: .5rem 0;
  z-index: 300;
  /* Animate open/close via opacity+visibility (not display) so the close can
     be delayed, giving a grace period to reach the menu. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .16s ease, transform .16s ease, visibility 0s linear .3s;
}
/* Invisible bridge spanning the gap (and slightly overlapping the trigger) so
   the cursor can travel from trigger to menu without hitting a non-hover
   dead zone that would close the dropdown. */
.nav-dropdown::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 16px;
}
.nav-has-dropdown:hover .nav-dropdown,
.nav-has-dropdown:focus-within .nav-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity .16s ease, transform .16s ease, visibility 0s;
}
.nav-dropdown a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem 1rem;
  font-size: .87rem;
  color: var(--text);
  border-radius: 4px;
  transition: background .1s, color .1s;
}
.nav-dropdown a:hover { background: var(--blue-light); color: var(--blue); }
.nav-dropdown-heading {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: .5rem 1rem .2rem;
}
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* ---- HAMBURGER / MOBILE NAV ---- */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 6px;
  transition: background .15s;
  flex-shrink: 0;
  margin-left: .25rem;
}
.nav-hamburger:hover { background: var(--blue-light); }
.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .22s, opacity .22s, width .22s;
  transform-origin: center;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; width: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-mobile-panel {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  padding: 0 0 2rem;
  transform: translateY(-6px);
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
.nav-mobile-panel.open { opacity: 1; transform: translateY(0); }
.nav-mobile-panel .mob-link {
  display: block;
  padding: .65rem 1.25rem;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
  border-radius: 0;
  transition: background .1s, color .1s;
}
.nav-mobile-panel .mob-link:hover,
.nav-mobile-panel .mob-link.active { background: var(--blue-light); color: var(--blue); }
.nav-mobile-section { border-top: 1px solid var(--border); margin-top: .4rem; padding-top: .4rem; }
.nav-mobile-acc-heading {
  font-size: .67rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: .6rem 1.25rem .2rem;
}
.nav-mobile-actions {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: 1rem 1.25rem .5rem;
  border-top: 1px solid var(--border);
  margin-top: .75rem;
}

/* Difficulty tabs */
.diff-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface-3);
  border-radius: 999px;
  padding: 0.3rem;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}
.diff-tab {
  flex: 1;
  text-align: center;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
  color: var(--text-muted);
  border: none;
  background: none;
  text-decoration: none;
  white-space: nowrap;
}
.diff-tab:hover { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
/* Active states with per-difficulty colour */
.diff-tab.diff-easy.active     { background: #16a34a; color: #fff; box-shadow: 0 2px 6px rgba(22,163,74,.35); }
.diff-tab.diff-medium.active   { background: #2563eb; color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,.35); }
.diff-tab.diff-hard.active     { background: #dc2626; color: #fff; box-shadow: 0 2px 6px rgba(220,38,38,.35); }
.diff-tab.diff-5x5.active      { background: #7c3aed; color: #fff; box-shadow: 0 2px 6px rgba(124,58,237,.35); }
.diff-tab.diff-2-player.active { background: #d97706; color: #fff; box-shadow: 0 2px 6px rgba(217,119,6,.35); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--blue); border-color: var(--blue); }
.btn-outline:hover { background: var(--blue-light); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: #d97706; border-color: #d97706; color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; }
.btn-xl { padding: 1rem 2.5rem; font-size: 1.1rem; border-radius: var(--radius); }
.btn-full { width: 100%; }

/* ---- CARDS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.5rem; }
.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: inherit;
}
.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---- FORMS ---- */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-weight: 600; font-size: 0.875rem; margin-bottom: 0.4rem; color: var(--text); }
.form-control {
  width: 100%;
  padding: 0.6rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font);
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-control.is-invalid { border-color: #ef4444; }
.form-error { font-size: 0.8rem; color: #ef4444; margin-top: 0.25rem; }
textarea.form-control { min-height: 120px; resize: vertical; }
select.form-control { cursor: pointer; }

/* ---- ALERTS / FLASH ---- */
.alert {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-danger { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-warning { background: var(--accent-light); border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: var(--blue-light); border: 1px solid var(--blue-border); color: #1e40af; }

/* ---- BADGES ---- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-blue { background: var(--blue-light); color: var(--blue-dark); }
.badge-green { background: #f0fdf4; color: #166534; }
.badge-yellow { background: var(--accent-light); color: #92400e; }
.badge-red { background: #fef2f2; color: #991b1b; }
.badge-gray { background: var(--surface-3); color: var(--text-muted); }

/* ---- DIFFICULTY COLORS ---- */
.diff-easy { color: #16a34a; }
.diff-medium { color: #2563eb; }
.diff-hard { color: #dc2626; }
.diff-5x5 { color: #7c3aed; }
.diff-2-player { color: #d97706; }

/* ---- GAME LAYOUT ---- */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 2rem;
  align-items: start;
  max-width: 820px;
  margin: 0 auto;
}
.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  gap: 1.25rem;
}
.game-stats {
  display: flex;
  gap: 1.5rem;
  justify-content: space-between;
  width: min(100%, var(--board-w, 400px));
}
.game-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}
.game-stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.game-stat-value { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.timer { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.game-controls {
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---- TIC TAC TOE BOARD ---- */
.ttt-board {
  display: grid;
  /* minmax(0, 1fr) on BOTH axes: rows must stay equal regardless of cell
     content, otherwise a row holding a large X/O mark grows and squeezes
     the empty rows. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, var(--board-w, 400px));
  aspect-ratio: 1 / 1;
  background: var(--text);
  border: 3px solid var(--text);
  border-radius: 12px;
  padding: 0;
  user-select: none;
  position: relative;
  contain: layout style;
}
.ttt-board.ttt-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.ttt-board.ttt-4 .ttt-cell { font-size: clamp(1.6rem, 7vw, 2.6rem); }
.ttt-board.ttt-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 5px;
}
.ttt-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  position: relative;
  transition: background 0.12s, transform 0.08s;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  padding: 0;
}
.ttt-board.ttt-5 .ttt-cell { font-size: clamp(1.3rem, 5.5vw, 2.2rem); border-radius: 5px; }
.ttt-cell:hover:not(.filled):not(.locked) { background: var(--blue-light); }
.ttt-cell:active:not(.filled):not(.locked) { transform: scale(.96); }
.ttt-cell.filled { cursor: default; }
.ttt-cell.locked { cursor: not-allowed; }
.ttt-cell.x { color: var(--x-color); }
.ttt-cell.o { color: var(--o-color); }
.ttt-cell.win { background: #dcfce7; }
.ttt-cell.win.x { color: #16a34a; }
.ttt-cell.win.o { color: #16a34a; }
.ttt-cell.last-move { background: var(--surface-3); }
.ttt-cell.win.last-move { background: #dcfce7; }
.ttt-cell .mark { display: block; animation: markPop .18s ease-out; }
@keyframes markPop {
  0% { transform: scale(.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Ghost preview of your mark on hover (desktop) */
@media (hover: hover) {
  .ttt-cell:hover:not(.filled):not(.locked)::after {
    content: attr(data-ghost);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--blue-border);
    font-weight: 800;
  }
}

/* Turn indicator */
.turn-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .45rem 1.25rem;
  min-height: 2.4rem;
}
.turn-banner .mark-x { color: var(--x-color); font-weight: 800; }
.turn-banner .mark-o { color: var(--o-color); font-weight: 800; }
.turn-banner.thinking { color: var(--text-muted); }
.turn-banner.result-win { background: #f0fdf4; border-color: #86efac; color: #166534; }
.turn-banner.result-loss { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.turn-banner.result-draw { background: var(--accent-light); border-color: #fde68a; color: #92400e; }

/* Session scoreboard */
.score-strip {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  width: min(100%, var(--board-w, 400px));
}
.score-box {
  flex: 1;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .25rem;
}
.score-box.active { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(59,130,246,.15); }
.score-box-label { font-size: .68rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.score-box-label .mark-x { color: var(--x-color); }
.score-box-label .mark-o { color: var(--o-color); }
.score-box-value { font-size: 1.25rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }

/* Control buttons row under board */
.controls-row {
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  width: min(100%, var(--board-w, 400px));
}
.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.15s;
  position: relative;
  font-family: var(--font);
}
.control-btn:hover { background: var(--surface-3); color: var(--blue); }
.control-btn.active { color: var(--blue); background: var(--blue-light); }
.control-btn svg { width: 22px; height: 22px; }
.ctrl-badge {
  position: absolute;
  top: 2px; right: 2px;
  font-size: .58rem; font-weight: 800;
  line-height: 1; padding: .18rem .32rem;
  border-radius: 999px; pointer-events: none;
  letter-spacing: .01em;
}
.ctrl-badge-off  { background: #9ca3af; color: #fff; }
.ctrl-badge-on   { background: var(--blue); color: #fff; }

.game-instruction {
  font-size: .8rem;
  color: var(--blue);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: .55rem .5rem .55rem 1rem;
  min-height: 2.2rem;
  transition: opacity .25s;
  width: min(100%, var(--board-w, 400px));
}

/* Win line flash */
@keyframes cellFlash {
  0%  { background: inherit; }
  35% { background: rgba(34,197,94,.55); }
  100%{ background: #dcfce7; }
}
.ttt-cell.win { animation: cellFlash .6s ease-out; }

/* ---- ULTIMATE TIC TAC TOE BOARD ---- */
.ult-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 480px);
  aspect-ratio: 1 / 1;
  background: var(--text);
  border: 3px solid var(--text);
  border-radius: 12px;
  padding: 0;
  user-select: none;
  position: relative;
}
.ult-sub {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  background: #cbd5e1;
  border-radius: 6px;
  padding: 4px;
  position: relative;
  transition: box-shadow .15s, background .15s;
}
.ult-sub.active { background: var(--blue); box-shadow: 0 0 0 2px var(--blue); }
.ult-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-size: clamp(.85rem, 3vw, 1.35rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  border: none;
  border-radius: 3px;
  color: var(--text);
  font-family: var(--font);
  padding: 0;
  aspect-ratio: 1;
  transition: background .1s;
}
.ult-sub.active .ult-cell:hover:not(.filled) { background: var(--blue-light); }
.ult-cell.filled { cursor: default; }
.ult-cell.x { color: var(--x-color); }
.ult-cell.o { color: var(--o-color); }
/* Claimed sub-boards: dim cells, overlay the winner's mark */
.ult-sub.won-x, .ult-sub.won-o, .ult-sub.sub-draw { background: #e2e8f0; }
.ult-sub.won-x .ult-cell, .ult-sub.won-o .ult-cell, .ult-sub.sub-draw .ult-cell { opacity: .18; cursor: default; }
.ult-sub.won-x::after, .ult-sub.won-o::after {
  content: attr(data-winner);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.6rem, 11vw, 4.5rem);
  font-weight: 800;
  font-family: var(--font);
  pointer-events: none;
}
.ult-sub.won-x::after { color: var(--x-color); }
.ult-sub.won-o::after { color: var(--o-color); }
.ult-sub.meta-win { background: #86efac; }

/* ---- ONLINE MULTIPLAYER ---- */
.online-dimmed .ttt-board { opacity: .35; pointer-events: none; }
#wait-panel, #fatal-panel { order: -1; }

/* ---- PRINTABLE BOARDS ---- */
.print-sheet {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2rem;
}
.print-ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  aspect-ratio: 1;
}
.print-ttt-board.print-5 { grid-template-columns: repeat(5, 1fr); }
.print-ttt-board .pcell { border: 2px solid #0f172a; aspect-ratio: 1; }
/* Only inner gridlines, like a hand-drawn board */
.print-ttt-board .pcell { border-top: none; border-left: none; }
.print-ttt-board .pcell:nth-child(3n) { border-right: none; }
.print-ttt-board.print-5 .pcell:nth-child(3n) { border-right: 2px solid #0f172a; }
.print-ttt-board.print-5 .pcell:nth-child(5n) { border-right: none; }
.print-ttt-board .pcell:nth-last-child(-n+3) { border-bottom: none; }
.print-ttt-board.print-5 .pcell:nth-last-child(-n+3) { border-bottom: 2px solid #0f172a; }
.print-ttt-board.print-5 .pcell:nth-last-child(-n+5) { border-bottom: none; }
@media print {
  .site-nav, .site-footer, .no-print, .breadcrumb { display: none !important; }
  body { background: #fff; }
  body.print-page > * { visibility: hidden; }
  body.print-page #print-area,
  body.print-page #print-area * { visibility: visible; }
  body.print-page #print-area {
    position: fixed;
    top: 0; left: 0;
    width: 100%; margin: 0; padding: 1cm;
    box-sizing: border-box;
  }
}

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table thead tr { background: var(--surface-2); }
.data-table th { padding: .65rem 1rem; font-weight: 700; color: var(--text); text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: .6rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: top; line-height: 1.55; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:nth-child(even) { background: var(--surface-2); }
.data-table tbody tr:hover td { background: var(--blue-light); }

/* ---- HERO ---- */
.hero {
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 60%, #60a5fa 100%);
  color: white;
  padding: 4rem 0 3rem;
  text-align: center;
}
.hero h1 { color: white; font-size: 2.8rem; margin-bottom: 1rem; }
.hero p { color: rgba(255,255,255,0.85); font-size: 1.1rem; max-width: 600px; margin: 0 auto 2rem; }

/* ---- GRID SECTION LAYOUTS ---- */
.section { padding: 3rem 0; }
.section-title { font-size: 1.75rem; font-weight: 800; margin-bottom: 0.5rem; }
.section-subtitle { color: var(--text-muted); margin-bottom: 2rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.25rem; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.25rem; }

/* Difficulty / mode card */
.diff-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.75rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--border);
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text);
}
.diff-card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  color: var(--text);
}
.diff-card-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
}
.diff-card-name { font-weight: 700; font-size: 1.05rem; margin-bottom: 0.25rem; }
.diff-card-desc { font-size: 0.8rem; color: var(--text-muted); }

/* Feature card */
.feature-card {
  padding: 1.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.feature-card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.feature-card-icon svg { width: 40px; height: 40px; color: var(--blue); display: block; }
.feature-card h3 { margin-bottom: 0.4rem; }

/* ---- FOOTER ---- */
.site-footer {
  background: #0f172a;
  color: #94a3b8;
  padding: 3rem 0 1.5rem;
  margin-top: 4rem;
}
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 2rem; margin-bottom: 2.5rem; }
.footer-brand { font-size: 1.5rem; font-weight: 800; color: #60a5fa; margin-bottom: 0.75rem; }
.footer-desc { font-size: 0.875rem; line-height: 1.6; margin-bottom: 0; }
.footer-heading { font-weight: 700; color: #e2e8f0; font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 1rem; }
.footer-links { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.footer-links a { color: #94a3b8; font-size: 0.875rem; transition: color 0.15s; }
.footer-links a:hover { color: #60a5fa; }
.footer-bottom {
  border-top: 1px solid #1e293b;
  padding-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

/* ---- BREADCRUMB ---- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--blue); }
.breadcrumb .sep { color: var(--text-light); }
/* Breadcrumb bar: sits just beneath the nav, aligned with the logo (.container). */
.breadcrumb-bar { padding: 1.25rem 0 0; }
.breadcrumb-bar .breadcrumb { margin-bottom: 0; }

/* ---- CONTENT / ARTICLE TYPOGRAPHY (rules, how-to-win, legal) ---- */
.article-body h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 2.25rem;
  margin-bottom: .75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: 5.5rem;
}
.article-body h2:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.article-body h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: .5rem;
  scroll-margin-top: 5.5rem;
}
.article-body p {
  font-size: .97rem;
  line-height: 1.85;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.article-body ul,
.article-body ol {
  padding-left: 1.4rem;
  margin-bottom: 1.25rem;
  color: var(--text-muted);
  font-size: .94rem;
  line-height: 1.75;
}
.article-body li { margin-bottom: .35rem; }
.article-body strong { color: var(--text); }
.article-body em { font-style: italic; }
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0 1.75rem;
  font-size: .88rem;
}
.article-body table th {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
  padding: .6rem .9rem;
  text-align: left;
  border: 1px solid var(--border);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.article-body table td {
  padding: .55rem .9rem;
  border: 1px solid var(--border);
  color: var(--text-muted);
  vertical-align: top;
  line-height: 1.5;
}
.article-body table tr:nth-child(even) td { background: var(--surface-2); }
.article-body blockquote {
  border-left: 4px solid var(--blue);
  background: var(--blue-light);
  margin: 1.25rem 0;
  padding: 1rem 1.25rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
  font-size: .95rem;
  font-style: normal;
}
.article-body .callout {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: .9rem 1.2rem;
  margin: 1.25rem 0;
  font-size: .88rem;
  color: #166534;
  line-height: 1.6;
}
.article-body .callout-warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

/* ---- ARTICLE PAGE LAYOUT (content + related sidebar) ---- */
.article-page-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 2.5rem;
  align-items: start;
}
.article-content { max-width: 720px; }
.article-sidebar { position: sticky; top: 5rem; display: flex; flex-direction: column; gap: 1.25rem; }
.sidebar-card-heading {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: .75rem;
}
.sidebar-related-item {
  display: block; padding: .65rem 0; border-bottom: 1px solid var(--border);
  font-size: .87rem; font-weight: 600; color: var(--text); line-height: 1.4;
}
.sidebar-related-item:last-child { border-bottom: none; padding-bottom: 0; }
.sidebar-related-item:hover { color: var(--blue); }
.sidebar-coming-soon {
  padding: .6rem 0; border-bottom: 1px solid var(--border);
  font-size: .82rem; color: var(--text-muted); line-height: 1.4;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.sidebar-coming-soon:last-child { border-bottom: none; padding-bottom: 0; }
@media (max-width: 900px) {
  .article-page-layout { grid-template-columns: 1fr; }
  .article-sidebar { position: static; }
  .article-content { max-width: none; }
}

/* Jump-to-section box */
.jump-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin: 1.5rem 0 2rem;
}
.jump-box-title {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: .65rem;
}
.jump-box ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.jump-box a { font-size: .88rem; font-weight: 600; display: flex; align-items: center; gap: .45rem; }
.jump-box a::before { content: '→'; color: var(--text-light); font-weight: 400; }

/* Single "read next" CTA card */
.next-read-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1.25rem;
  background: var(--blue-light); border: 1px solid var(--blue-border);
  border-radius: var(--radius-lg); padding: 1.5rem; margin-top: 2.75rem; flex-wrap: wrap;
}
.next-read-label {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--blue-dark); margin-bottom: .35rem;
}
.next-read-title { font-size: 1.1rem; font-weight: 800; color: var(--text); margin: 0; }
.next-read-blurb { font-size: .85rem; color: var(--text-muted); margin: .25rem 0 0; }

/* Key Points box */
.key-points {
  background: var(--blue-light);
  border: 1px solid var(--blue-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}
.key-points .kp-title {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--blue-dark);
  margin-bottom: .6rem;
}
.key-points ul { margin: 0; padding-left: 1.2rem; }
.key-points ul li {
  font-size: .88rem;
  color: var(--text);
  margin-bottom: .3rem;
  line-height: 1.55;
}

/* Mini demo boards inside content pages */
.demo-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 150px;
  background: var(--text);
  border: 2px solid var(--text);
  border-radius: 8px;
  margin: .5rem 0 1rem;
}
.demo-board .demo-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-size: 1.5rem;
  font-weight: 800;
  border-radius: 4px;
}
.demo-board .demo-cell.x { color: var(--x-color); }
.demo-board .demo-cell.o { color: var(--o-color); }
.demo-board .demo-cell.hl { background: #fef9c3; }

/* ---- FAQ ACCORDION ---- */
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  overflow: hidden;
}
.faq-item summary {
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.faq-item summary::-webkit-details-marker { display: none; }
/* Real <h2> lives inside <summary> for heading structure/SEO — reset it
   to look identical to the plain-text summary it replaces. */
.faq-item summary h2 { margin: 0; font-size: inherit; font-weight: inherit; line-height: inherit; }
.faq-item summary::after {
  content: '+';
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform .2s;
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item .faq-answer {
  padding: 0 1.25rem 1.1rem;
  font-size: .9rem;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  max-width: 480px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-icon { font-size: 3rem; margin-bottom: 1rem; display: flex; align-items: center; justify-content: center; }
.modal-icon svg { width: 60px; height: 60px; }
.modal-title { font-size: 1.75rem; margin-bottom: 0.5rem; }
.modal-stats { display: flex; justify-content: center; gap: 2rem; margin: 1rem 0 1.5rem; }
.modal-stat { text-align: center; }
.modal-stat-val { font-size: 1.25rem; font-weight: 700; }
.modal-stat-lbl { font-size: 0.75rem; color: var(--text-muted); }

/* ---- UTILITIES ---- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-blue { color: var(--blue); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.1rem; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.flex-wrap { flex-wrap: wrap; }

/* ---- HOME GAME SECTION ---- */
.home-game-wrap { padding: 1.5rem 0 2rem; }
.home-game-wrap .game-layout { max-width: 820px; }

/* ---- MOBILE ---- */
@media (max-width: 768px) {
  html { overflow-x: hidden; }
  body { overflow-x: hidden; max-width: 100vw; }
  .container, .container-sm, .container-lg { padding: 0 1rem; max-width: 100%; }
  .page-wrap { padding: 1.5rem 0; }

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
  .hero { padding: 2.5rem 0 2rem; }
  .hero h1 { font-size: 2rem; }
  .hero p { font-size: 1rem; }
  .grid-2, .grid-3, .grid-5 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .footer-grid { grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
  .footer-grid > div:first-child { grid-column: 1 / -1; padding-bottom: 1rem; border-bottom: 1px solid #1e293b; }
  .site-footer { padding: 2rem 0 1rem; margin-top: 2rem; }
  .footer-brand { font-size: 1.25rem; margin-bottom: .5rem; }
  .footer-desc { font-size: .82rem; }
  .footer-heading { font-size: .75rem; margin-bottom: .6rem; }
  .footer-links { gap: .35rem; }
  .footer-links a { font-size: .82rem; }
  .footer-bottom { flex-direction: column; gap: .3rem; text-align: center; padding-top: 1rem; font-size: .75rem; }
  .game-layout { grid-template-columns: 1fr; }
  .game-controls { width: 100%; }
  .controls-row { padding: .4rem .25rem; margin: .25rem 0; }
  .control-btn { padding: .65rem .5rem; font-size: .74rem; }
  .control-btn svg { width: 28px; height: 28px; }
  .timer { font-size: 1.6rem; }
  .nav-links { display: none; }
  .nav-actions .btn { display: none; }
  .nav-actions { margin-left: auto; }
  .nav-hamburger { display: flex; }
  .nav-mobile-panel { display: block; pointer-events: none; overflow-x: hidden; max-width: 100vw; padding-top: 0; }
  .nav-mobile-panel.open { pointer-events: all; }
  .diff-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; flex-wrap: nowrap; padding: 0.2rem; }
  .diff-tabs::-webkit-scrollbar { display: none; }
  .diff-tab { flex: none; padding: 0.3rem 0.75rem; font-size: 0.78rem; white-space: nowrap; flex-shrink: 0; }
  .table-wrap { overflow-x: auto; }
  .card { border-radius: var(--radius-sm); max-width: 100%; }
  .card-body { overflow-x: auto; }
  .section { padding: 2rem 0; }
  .section-title { font-size: 1.4rem; }
  .mb-8 { margin-bottom: 1.25rem; }
}

/* ---- SMALL PHONES (≤ 480px) — must come last to win cascade ---- */
@media (max-width: 480px) {
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  .hero h1 { font-size: 1.65rem; }
  .page-wrap { padding: 1rem 0; }
  .container { padding: 0 .75rem; }
  .nav-logo { font-size: 1.15rem; margin-right: 0; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .diff-card { padding: 1.25rem .75rem; }
  .diff-card-icon { width: 44px; height: 44px; font-size: 1.2rem; }
  .diff-card-name { font-size: .9rem; }
  .card-body { padding: .875rem; }
  .card-header { padding: .75rem .875rem; font-size: .85rem; }
  .btn-lg { padding: .6rem 1.25rem; font-size: .9rem; }
  .data-table th { white-space: normal; font-size: .8rem; padding: .5rem .75rem; }
  .data-table td { font-size: .82rem; padding: .5rem .75rem; }
  .footer-grid { grid-template-columns: 1fr 1fr; gap: 1rem; }
  .footer-links a { font-size: .78rem; }
  .site-footer { padding: 1.5rem 0 1rem; }
  .breadcrumb { font-size: .8rem; flex-wrap: wrap; }
  .modal-overlay { align-items: flex-start; padding: 1.25rem .75rem 2rem; }
  .modal-overlay .modal {
    padding: 1.25rem 1rem;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: var(--radius);
    transform: none !important;
  }
  .modal-title { font-size: 1.3rem; }
  .modal-stats { gap: 1rem; margin: .75rem 0 1.25rem; flex-wrap: wrap; justify-content: center; }
  .modal-stat-val { font-size: 1.1rem; }
  .modal-icon { font-size: 2.25rem; margin-bottom: .75rem; }
  .modal-icon svg { width: 48px; height: 48px; }
  .game-stats { width: 100%; }
  .score-strip { width: 100%; }
  .controls-row { width: 100%; }
  .game-instruction { width: 100%; }
}
