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

/* Theme tokens */
:root {
    --bg: #0f172a;
    --panel: #12192f;
    --panel-2: #19233d;
    --accent: #40f5d2;
    --accent-2: #ff7d7d;
    --text: #eef2ff;
    --muted: #a5b4fc;
    --glow: 0 0 20px rgba(64, 245, 210, 0.35);
}

body[data-theme="pastel"] {
    --bg: #f1eef7;
    --panel: #f5f0f6;
    --panel-2: #ece9f5;
    --accent: #e77fb6;
    --accent-2: #7a8fe0;
    --text: #1b2333;
    --muted: #5b657f;
    --glow: 0 0 16px rgba(231, 127, 182, 0.28);
}

body[data-theme="pastel"] .box {
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(122, 143, 224, 0.35);
    box-shadow: inset 0 0 0 1px rgba(231, 127, 182, 0.12);
}

body[data-theme="pastel"] .box:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.95);
}

body[data-theme="pastel"] .field select {
    background: linear-gradient(135deg, rgba(233, 230, 243, 0.9), rgba(226, 223, 238, 0.9));
    border-color: rgba(122, 143, 224, 0.35);
}

body[data-theme="pastel"] .ghost {
    border-color: rgba(122, 143, 224, 0.4);
    color: var(--text);
}

body[data-theme="pastel"] .repeat {
    color: #1a1f2e;
}

body[data-theme="mono"] {
    --bg: #111827;
    --panel: #0b1222;
    --panel-2: #111c30;
    --accent: #d1d5db;
    --accent-2: #93c5fd;
    --text: #f9fafb;
    --muted: #9ca3af;
    --glow: 0 0 18px rgba(209, 213, 219, 0.3);
}

/* Page layout and background */
body {
    font-family: "Space Grotesk", "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    min-height: 100vh;
    background:
        radial-gradient(1200px 600px at 15% 10%, rgba(64, 245, 210, 0.2), transparent 60%),
        radial-gradient(800px 500px at 85% 20%, rgba(255, 125, 125, 0.18), transparent 60%),
        linear-gradient(135deg, #0b1020 0%, #0f172a 50%, #0b1020 100%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 32px 16px 48px;
}

body[data-theme="pastel"] {
    background:
    radial-gradient(1000px 500px at 15% 10%, rgba(231, 127, 182, 0.18), transparent 60%),
    radial-gradient(800px 400px at 85% 20%, rgba(122, 143, 224, 0.16), transparent 60%),
    linear-gradient(135deg, #f4f1f8 0%, #eeecf6 50%, #f4f1f8 100%);
}

body[data-theme="mono"] {
    background:
        radial-gradient(900px 500px at 15% 10%, rgba(148, 163, 184, 0.18), transparent 60%),
        radial-gradient(700px 400px at 85% 20%, rgba(59, 130, 246, 0.18), transparent 60%),
        linear-gradient(135deg, #0b1020 0%, #111827 50%, #0b1020 100%);
}

/* Hero header */
.hero {
    display: grid;
    gap: 10px;
}

.heading {
    font-family: "Unbounded", "Space Grotesk", sans-serif;
    letter-spacing: 2px;
    font-size: clamp(2rem, 4vw, 3.2rem);
    text-transform: uppercase;
    text-shadow: 0 0 30px rgba(64, 245, 210, 0.2);
}

.subheading {
    color: var(--muted);
    font-size: clamp(0.95rem, 2vw, 1.1rem);
}

.container {
    width: min(720px, 96vw);
    display: flex;
    justify-content: center;
}

/* Main panel shell */
.panel {
    width: 100%;
    background: linear-gradient(160deg, var(--panel), var(--panel-2));
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(8, 10, 30, 0.5);
    display: grid;
    gap: 20px;
}

/* Toolbar controls */
.toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.field {
    display: grid;
    gap: 6px;
    text-align: left;
    font-size: 0.85rem;
    color: var(--muted);
}

.field select {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.85), rgba(25, 35, 61, 0.85));
    color: var(--text);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.15), 0 10px 18px rgba(8, 10, 30, 0.25);
     -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    line-height: 1.2;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) calc(50% - 3px),
        calc(100% - 12px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 36px;
}

.field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(64, 245, 210, 0.2);
}

.field select option {
    color: #0b1020;
    background: #f8fafc;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
}

/* Status + turn indicator */
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.status {
    font-weight: 600;
    color: var(--accent);
}

/* Turn and timer chips */
.turn-chip,
.timer-chip {
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.3);
    font-weight: 600;
}

/* Scoreboard cards */
.scoreboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.score-card {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    padding: 12px 16px;
    display: grid;
    gap: 6px;
}

.score-card strong {
    font-size: 1.6rem;
}

.score-card[data-player="O"] strong {
    color: var(--accent);
}

.score-card[data-player="X"] strong {
    color: var(--accent-2);
}

/* Game board grid */
.game {
    width: min(420px, 80vw);
    height: min(420px, 80vw);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 0 auto;
    position: relative;
}

.game.thinking {
    animation: thinkingPulse 1.1s ease-in-out infinite;
}

.game.thinking .box {
    box-shadow: var(--glow);
}

.box {
    border: none;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-size: clamp(2.2rem, 8vw, 4rem);
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    position: relative;
    overflow: hidden;
}

.box:disabled {
    cursor: not-allowed;
}

.box:hover:not(:disabled) {
    transform: translateY(-4px);
    box-shadow: var(--glow);
    background: rgba(64, 245, 210, 0.12);
}

.box.win {
    background: rgba(64, 245, 210, 0.28);
    box-shadow: 0 0 30px rgba(64, 245, 210, 0.45);
    transform: translateY(-2px) scale(1.02);
}

.box.mark-o {
    color: var(--accent);
    text-shadow:
        0 0 8px rgba(64, 245, 210, 0.9),
        0 0 18px rgba(64, 245, 210, 0.7),
        0 0 28px rgba(64, 245, 210, 0.5);
}

.box.mark-x {
    color: var(--accent-2);
    text-shadow:
        0 0 8px rgba(255, 125, 125, 0.9),
        0 0 18px rgba(255, 125, 125, 0.7),
        0 0 28px rgba(255, 125, 125, 0.5);
}

.box.hint {
    outline: 2px dashed var(--accent);
    box-shadow: 0 0 18px rgba(64, 245, 210, 0.35);
    animation: hintPulse 1s ease-in-out infinite;
}

/* ── Dynamic cell styles (built by JS) ── */
.cell {
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-size: clamp(2.2rem, 8vw, 4rem);
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell:hover:not(.taken) {
    transform: translateY(-4px);
    box-shadow: var(--glow);
    background: rgba(64, 245, 210, 0.12);
}

.cell.x-mark {
    color: var(--accent-2);
    text-shadow:
        0 0 8px rgba(255, 125, 125, 0.9),
        0 0 18px rgba(255, 125, 125, 0.7);
}

.cell.o-mark {
    color: var(--accent);
    text-shadow:
        0 0 8px rgba(64, 245, 210, 0.9),
        0 0 18px rgba(64, 245, 210, 0.7);
}

.cell.win-cell {
    background: rgba(64, 245, 210, 0.28);
    box-shadow: 0 0 30px rgba(64, 245, 210, 0.45);
    transform: translateY(-2px) scale(1.02);
}

.win-line {
    position: absolute;
    height: 6px;
    background: var(--accent);
    border-radius: 999px;
    opacity: 0;
    transform-origin: left center;
    box-shadow: var(--glow);
    transition: opacity 0.2s ease;
}

.win-line.show {
    opacity: 1;
}

/* Primary action buttons */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.repeat,
.ghost {
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.repeat {
    background: var(--accent);
    color: #0b1020;
    box-shadow: var(--glow);
}

.repeat:hover {
    transform: translateY(-2px);
}

.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid rgba(148, 163, 184, 0.4);
}

.ghost:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.ghost[aria-pressed="false"] {
    opacity: 0.65;
}

.footer {
    color: rgba(226, 232, 240, 0.7);
    font-size: 0.9rem;
    display: grid;
    gap: 6px;
}

/* Move history panel */
.history {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    padding: 14px 16px;
    text-align: left;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.history h3 {
    font-size: 1rem;
}

#historyHint {
    font-size: 0.8rem;
    color: var(--muted);
}

#historyList {
    display: grid;
    gap: 6px;
    padding-left: 20px;
    max-height: 150px;
    overflow-y: auto;
}

#historyList li {
    font-size: 0.9rem;
    color: var(--text);
}

#confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    width: 100vw;
    height: 100vh;
    z-index: 10;
}

/* Winner modal */
.winner-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(8, 12, 26, 0.72);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
}

/* Start modal */
.start-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(8, 12, 26, 0.78);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 30;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .winner-modal {
        background: rgba(8, 12, 26, 0.9);
    }

    .start-modal {
        background: rgba(8, 12, 26, 0.92);
    }
}

.start-modal.show {
    opacity: 1;
    pointer-events: auto;
}

.start-card {
    width: min(440px, 92vw);
    background: radial-gradient(500px 200px at 50% 0%, rgba(64, 245, 210, 0.18), transparent 60%),
        linear-gradient(160deg, rgba(18, 25, 47, 0.98), rgba(25, 35, 61, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 22px;
    padding: 26px;
    box-shadow: 0 30px 70px rgba(4, 8, 24, 0.65);
    display: grid;
    gap: 14px;
}

.start-badge {
    justify-self: center;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent);
    border: 1px solid rgba(64, 245, 210, 0.6);
    box-shadow: 0 0 18px rgba(64, 245, 210, 0.45);
}

.start-title {
    font-family: "Unbounded", "Space Grotesk", sans-serif;
    font-size: clamp(1.7rem, 4vw, 2.3rem);
    text-shadow: 0 0 18px rgba(64, 245, 210, 0.35);
}

.start-subtitle {
    color: var(--muted);
    font-size: 0.98rem;
}

.start-actions {
    display: flex;
    justify-content: center;
}

.winner-card {
    width: min(420px, 92vw);
    background: linear-gradient(160deg, rgba(18, 25, 47, 0.98), rgba(25, 35, 61, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 25px 60px rgba(4, 8, 24, 0.6);
    display: grid;
    gap: 12px;
}

.winner-badge {
    justify-self: center;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent);
    border: 1px solid rgba(64, 245, 210, 0.6);
    box-shadow: 0 0 16px rgba(64, 245, 210, 0.45);
}

.winner-title {
    font-family: "Unbounded", "Space Grotesk", sans-serif;
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    text-shadow: 0 0 18px rgba(64, 245, 210, 0.35);
}

.winner-subtitle {
    color: var(--muted);
    font-size: 0.95rem;
}

.winner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

/* Animations */
@keyframes hintPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

@keyframes thinkingPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.01);
    }
}

@media (max-width: 560px) {
    .panel {
        padding: 18px;
    }

    .status-row {
        justify-content: center;
    }
}

@media (max-width: 900px) {
    body {
        padding: 28px 14px 40px;
    }

    .panel {
        border-radius: 20px;
    }

    .toolbar {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .game {
        width: min(380px, 84vw);
        height: min(380px, 84vw);
        gap: 10px;
    }
}

@media (max-width: 700px) {
    .status-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar-actions {
        justify-content: center;
    }

    .scoreboard {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }

    .controls {
        flex-direction: column;
    }

    .winner-card,
    .start-card {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 22px 12px 32px;
        gap: 18px;
    }

    .heading {
        letter-spacing: 1px;
    }

    .panel {
        padding: 16px;
    }
}

/* ── Mode screen ─────────────────────────── */
#mode-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top left, #0f2bff22, transparent 40%),
    radial-gradient(circle at top right, #ff00cc22, transparent 40%),
    #050816;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 998;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#mode-screen.show { display: flex; opacity: 1; }
#mode-screen.hide { opacity: 0; }

.mode-title {
  font-family: var(--font);
  font-size: 48px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 4px;
  margin-bottom: 8px;
  text-align: center;
}
.mode-sub {
  color: #aaa;
  font-family: var(--font);
  font-size: 16px;
  margin-bottom: 40px;
  letter-spacing: 2px;
}
.mode-btns {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 170px;
  padding: 32px 20px;
  border-radius: 20px;
  border: 2px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  font-family: var(--font);
  color: #fff;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  backdrop-filter: blur(10px);
}
.mode-btn:hover {
  transform: scale(1.07);
  border-color: #ff2cdf;
  box-shadow: 0 0 30px #ff2cdf88;
}
.mode-icon  { font-size: 40px; line-height: 1; }
.mode-label { font-size: 20px; font-weight: 900; letter-spacing: 1px; }
.mode-desc  { font-size: 12px; color: #aaa; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }

/* ── Fixed: start-modal visible by default via .show class ── */
.start-modal.show,
.winner-modal.show {
    opacity: 1;
    pointer-events: auto;
}

/* ── Fixed: win cell highlight ── */
.box.win {
    background: rgba(64, 245, 210, 0.28);
    box-shadow: 0 0 30px rgba(64, 245, 210, 0.45);
    transform: translateY(-2px) scale(1.02);
}

/* ── Fixed: score card X color ── */
.score-card[data-player="X"] strong {
    color: var(--accent-2);
}
.score-card[data-player="O"] strong {
    color: var(--accent);
}