/* ===============================================
   TIC TAC TOE — PREMIUM EDITION
   Complete CSS with Neon / Gold / Glass Themes
   =============================================== */

/* --- CSS Custom Properties (Neon Dark Default) --- */
:root {
    /* Neon Dark Theme */
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(20, 20, 50, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border-glass: rgba(255, 255, 255, 0.1);
    --text-primary: #e8e8ff;
    --text-secondary: #8888bb;
    --text-muted: #555580;
    --color-x: #00e5ff;
    --color-x-glow: rgba(0, 229, 255, 0.4);
    --color-o: #ff4081;
    --color-o-glow: rgba(255, 64, 129, 0.4);
    --color-accent: #7c4dff;
    --color-accent-glow: rgba(124, 77, 255, 0.3);
    --color-win: #76ff03;
    --color-win-glow: rgba(118, 255, 3, 0.4);
    --color-warning: #ff9100;
    --color-danger: #ff1744;
    --grid-line: rgba(255, 255, 255, 0.12);
    --grid-glow: rgba(124, 77, 255, 0.2);
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(124, 77, 255, 0.2);
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --font-primary: 'Outfit', sans-serif;
    --font-display: 'Orbitron', sans-serif;
    --transition-fast: 0.15s ease;
    --transition-med: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* Gold Theme */
[data-theme="gold"] {
    --bg-primary: #0f0a1e;
    --bg-secondary: #1a1028;
    --bg-card: rgba(30, 20, 50, 0.7);
    --bg-glass: rgba(255, 215, 0, 0.04);
    --border-glass: rgba(255, 215, 0, 0.15);
    --text-primary: #fff5e0;
    --text-secondary: #c9a84c;
    --text-muted: #7a6530;
    --color-x: #ffd700;
    --color-x-glow: rgba(255, 215, 0, 0.4);
    --color-o: #ff6b35;
    --color-o-glow: rgba(255, 107, 53, 0.4);
    --color-accent: #ffd700;
    --color-accent-glow: rgba(255, 215, 0, 0.25);
    --color-win: #00e676;
    --color-win-glow: rgba(0, 230, 118, 0.4);
    --grid-line: rgba(255, 215, 0, 0.1);
    --grid-glow: rgba(255, 215, 0, 0.15);
    --shadow-glow: 0 0 20px rgba(255, 215, 0, 0.15);
}

/* Glass Theme */
[data-theme="glass"] {
    --bg-primary: #e8ecf1;
    --bg-secondary: #f0f4f8;
    --bg-card: rgba(255, 255, 255, 0.45);
    --bg-glass: rgba(255, 255, 255, 0.3);
    --border-glass: rgba(255, 255, 255, 0.5);
    --text-primary: #1a2332;
    --text-secondary: #4a5568;
    --text-muted: #a0aec0;
    --color-x: #4f46e5;
    --color-x-glow: rgba(79, 70, 229, 0.3);
    --color-o: #e11d48;
    --color-o-glow: rgba(225, 29, 72, 0.3);
    --color-accent: #6366f1;
    --color-accent-glow: rgba(99, 102, 241, 0.2);
    --color-win: #10b981;
    --color-win-glow: rgba(16, 185, 129, 0.3);
    --grid-line: rgba(0, 0, 0, 0.08);
    --grid-glow: rgba(99, 102, 241, 0.1);
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
}

#particleCanvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* --- Screen Management --- */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    overflow-y: auto;
    padding: 16px;
}
.screen > * {
    margin: auto;
}
.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

/* --- Glass Panel --- */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-soft), var(--shadow-glow);
    max-width: 480px;
    width: 100%;
}

.glass-panel-sm {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-soft);
}

/* --- Buttons --- */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-med);
    position: relative;
    overflow: hidden;
    width: 100%;
    text-align: left;
}
.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent), #9c27b0);
    color: #fff;
    box-shadow: 0 4px 16px var(--color-accent-glow);
}
.btn-primary:hover {
    box-shadow: 0 6px 24px var(--color-accent-glow);
    transform: translateY(-2px);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--color-x), #0288d1);
    color: #fff;
    box-shadow: 0 4px 16px var(--color-x-glow);
}
.btn-secondary:hover {
    box-shadow: 0 6px 24px var(--color-x-glow);
    transform: translateY(-2px);
}

.btn-outline {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--color-accent);
}

.btn-danger {
    border-color: var(--color-danger) !important;
    color: var(--color-danger) !important;
}

.btn-sm {
    padding: 10px 20px;
    font-size: 14px;
    border-radius: var(--radius-sm);
}
.btn-lg {
    padding: 18px 36px;
    font-size: 18px;
}

.btn-glow::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: inherit;
    filter: blur(16px);
    opacity: 0.3;
    z-index: -1;
    transition: opacity var(--transition-med);
}
.btn-glow:hover::after {
    opacity: 0.5;
}

.btn-icon {
    font-size: 20px;
    flex-shrink: 0;
}
.btn-text {
    flex: 1;
    text-align: left;
    font-weight: 700;
}
.btn-desc {
    font-size: 11px;
    opacity: 0.6;
    font-weight: 400;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    font-size: 20px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--color-accent);
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
    transition: color var(--transition-fast);
}
.back-btn:hover {
    color: var(--color-accent);
}

/* --- Splash Screen --- */
.splash-content {
    text-align: center;
    animation: splashFadeIn 0.8s ease forwards;
}
@keyframes splashFadeIn {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.splash-icon-wrap {
    width: 120px;
    height: 120px;
    margin: 0 auto 24px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 0 40px var(--color-accent-glow), var(--shadow-soft);
    animation: splashPulse 2s ease-in-out infinite;
}
@keyframes splashPulse {
    0%, 100% { box-shadow: 0 0 40px var(--color-accent-glow), var(--shadow-soft); }
    50% { box-shadow: 0 0 60px var(--color-accent-glow), 0 0 80px var(--color-x-glow); }
}

.splash-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.splash-title {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 900;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--color-x), var(--color-accent), var(--color-o));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

.splash-subtitle {
    font-family: var(--font-display);
    font-size: 12px;
    letter-spacing: 6px;
    color: var(--text-secondary);
}

.splash-loader {
    margin-top: 48px;
    width: 200px;
    margin-left: auto;
    margin-right: auto;
}
.loader-bar {
    height: 4px;
    background: var(--bg-glass);
    border-radius: 2px;
    overflow: hidden;
}
.loader-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-x), var(--color-accent), var(--color-o));
    border-radius: 2px;
    transition: width 0.3s ease;
}
.loader-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* --- Main Menu --- */
.menu-container {
    text-align: center;
    animation: slideUp 0.5s ease forwards;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-header {
    margin-bottom: 32px;
}
.menu-icon {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-md);
    box-shadow: 0 0 24px var(--color-accent-glow);
    margin-bottom: 16px;
}
.menu-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 3px;
    background: linear-gradient(135deg, var(--color-x), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.menu-edition {
    font-family: var(--font-display);
    font-size: 10px;
    letter-spacing: 5px;
    color: var(--text-muted);
    margin-top: 4px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.menu-footer {
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* --- Tutorial --- */
.tutorial-container {
    text-align: center;
    max-width: 440px;
}
.tutorial-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--color-x), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tutorial-slides {
    position: relative;
    min-height: 280px;
}
.tutorial-slide {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    opacity: 0;
    transform: translateX(40px);
    transition: all 0.4s ease;
    pointer-events: none;
}
.tutorial-slide.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}
.tutorial-slide h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}
.tutorial-slide p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 300px;
    line-height: 1.6;
}

.tutorial-visual {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
}

.tutorial-grid-demo {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 4px;
}
.demo-cell {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}
.highlight-cell {
    border-color: var(--color-accent) !important;
    box-shadow: 0 0 12px var(--color-accent-glow);
    animation: cellPulseDemo 1.5s ease-in-out infinite;
}
@keyframes cellPulseDemo {
    0%, 100% { box-shadow: 0 0 12px var(--color-accent-glow); }
    50% { box-shadow: 0 0 24px var(--color-accent-glow); }
}

.demo-x line {
    stroke: var(--color-x);
    stroke-width: 6;
    stroke-linecap: round;
}
.demo-o circle {
    fill: none;
    stroke: var(--color-o);
    stroke-width: 6;
    stroke-linecap: round;
}

.win-demo .win-cell {
    background: rgba(118, 255, 3, 0.08);
    border-color: var(--color-win);
    box-shadow: 0 0 12px var(--color-win-glow);
}

.tutorial-modes {
    display: flex;
    gap: 16px;
}
.mode-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: 1;
    font-size: 14px;
    font-weight: 600;
}
.mode-card small {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}
.mode-icon {
    font-size: 32px;
}

.tutorial-features {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.feature-badge {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
}

.tutorial-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 16px 0;
}
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--transition-med);
    cursor: pointer;
}
.dot.active {
    background: var(--color-accent);
    box-shadow: 0 0 8px var(--color-accent-glow);
    width: 24px;
    border-radius: 4px;
}

.tutorial-nav {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.tutorial-nav .btn {
    width: auto;
    min-width: 100px;
}

/* --- Level Select --- */
.level-container {
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
}
.level-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.level-header h2 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
}
.level-stats {
    font-size: 13px;
    color: var(--text-secondary);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.level-btn {
    aspect-ratio: 1;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all var(--transition-med);
    position: relative;
    font-family: var(--font-primary);
}
.level-btn:hover:not(.locked) {
    border-color: var(--color-accent);
    box-shadow: 0 0 16px var(--color-accent-glow);
    transform: translateY(-2px);
}
.level-btn:active:not(.locked) {
    transform: scale(0.95);
}

.level-num {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}
.level-stars {
    font-size: 10px;
    letter-spacing: 1px;
}
.level-tag {
    font-size: 8px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.level-btn.locked {
    opacity: 0.35;
    cursor: not-allowed;
}
.level-btn.locked .level-num {
    color: var(--text-muted);
}
.level-btn.current {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px var(--color-accent-glow);
    animation: levelPulse 2s ease infinite;
}
@keyframes levelPulse {
    0%, 100% { box-shadow: 0 0 12px var(--color-accent-glow); }
    50% { box-shadow: 0 0 24px var(--color-accent-glow); }
}

.level-btn.completed {
    border-color: var(--color-win);
    background: rgba(118, 255, 3, 0.05);
}

/* --- Multiplayer Setup --- */
.mp-setup-container {
    text-align: center;
    max-width: 440px;
}
.mp-setup-container h2 {
    font-family: var(--font-display);
    font-size: 20px;
    margin-bottom: 24px;
}

.mp-players {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}
.mp-player-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.mp-player-card label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.mp-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 900;
}
.x-avatar {
    background: linear-gradient(135deg, var(--color-x), #0288d1);
    color: #fff;
    box-shadow: 0 4px 16px var(--color-x-glow);
}
.o-avatar {
    background: linear-gradient(135deg, var(--color-o), #9c27b0);
    color: #fff;
    box-shadow: 0 4px 16px var(--color-o-glow);
}

.mp-vs {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-muted);
}

.glass-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 14px;
    text-align: center;
    outline: none;
    transition: border-color var(--transition-fast);
}
.glass-input:focus {
    border-color: var(--color-accent);
}

.mp-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}
.mp-options label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: left;
}

.grid-size-selector, .timer-selector {
    display: flex;
    gap: 8px;
}
.grid-size-btn, .timer-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.grid-size-btn.active, .timer-btn.active {
    border-color: var(--color-accent);
    color: var(--color-accent);
    background: rgba(124, 77, 255, 0.1);
    box-shadow: 0 0 8px var(--color-accent-glow);
}

/* --- Game Screen --- */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 480px;
    padding: 4px 0;
}

.game-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
}
.game-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.mode-label {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 700;
    color: var(--color-accent);
}
.diff-label {
    font-size: 11px;
    color: var(--text-muted);
}
.hud-actions {
    display: flex;
    gap: 8px;
}

/* Score Panel */
.score-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
}
.score-player, .score-draw {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
    padding: 6px 0;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.score-player.active-turn {
    background: var(--bg-glass);
    box-shadow: 0 0 12px var(--color-accent-glow);
}
.score-x .score-name { color: var(--color-x); }
.score-o .score-name { color: var(--color-o); }
.score-name {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.score-val {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 800;
}
.score-draw .score-name { color: var(--text-muted); }

/* Turn Indicator */
.turn-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 40px;
    transition: all var(--transition-med);
}
.turn-marker {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 900;
    transition: all var(--transition-med);
}
.turn-marker.marker-x {
    background: linear-gradient(135deg, var(--color-x), #0288d1);
    color: #fff;
    box-shadow: 0 0 12px var(--color-x-glow);
}
.turn-marker.marker-o {
    background: linear-gradient(135deg, var(--color-o), #9c27b0);
    color: #fff;
    box-shadow: 0 0 12px var(--color-o-glow);
}
.turn-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.timer-ring {
    position: relative;
    width: 36px;
    height: 36px;
    display: none;
}
.timer-ring.visible { display: block; }
.timer-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.timer-bg {
    fill: none;
    stroke: var(--bg-glass);
    stroke-width: 3;
}
.timer-fg {
    fill: none;
    stroke: var(--color-accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 100.53;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s linear, stroke 0.3s ease;
}
.timer-fg.warning { stroke: var(--color-warning); }
.timer-fg.danger { stroke: var(--color-danger); }

.timer-val {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 700;
    color: var(--text-primary);
}

/* --- Game Board --- */
.board-wrapper {
    position: relative;
    width: 100%;
    max-width: 360px;
    aspect-ratio: 1;
}

.game-board {
    display: grid;
    gap: 6px;
    width: 100%;
    height: 100%;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft), var(--shadow-glow), inset 0 0 60px rgba(0,0,0,0.2);
}
.grid-3 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); }

.cell {
    background: var(--bg-glass);
    border: 1px solid var(--grid-line);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}
.cell:hover:not(.taken):not(.blocked) {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--color-accent);
    box-shadow: 0 0 12px var(--color-accent-glow);
}
.cell:active:not(.taken):not(.blocked) {
    transform: scale(0.94);
}
.cell.taken {
    cursor: default;
}
.cell.blocked {
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.02);
    opacity: 0.3;
}
.cell.blocked::after {
    content: '🚫';
    font-size: 20px;
    opacity: 0.5;
}

.cell.win-cell {
    animation: winCellPulse 0.6s ease infinite alternate;
    border-color: var(--color-win) !important;
    background: rgba(118, 255, 3, 0.08) !important;
    box-shadow: 0 0 16px var(--color-win-glow) !important;
}
@keyframes winCellPulse {
    to { box-shadow: 0 0 28px var(--color-win-glow) !important; }
}

.cell.hint-cell {
    animation: hintPulse 0.8s ease infinite alternate;
    border-color: var(--color-warning) !important;
    box-shadow: 0 0 16px rgba(255, 145, 0, 0.3) !important;
}
@keyframes hintPulse {
    to { box-shadow: 0 0 24px rgba(255, 145, 0, 0.5) !important; }
}

/* SVG X and O inside cells */
.cell svg {
    width: 55%;
    height: 55%;
}
.cell .x-mark line {
    stroke: var(--color-x);
    stroke-width: 8;
    stroke-linecap: round;
    filter: drop-shadow(0 0 6px var(--color-x-glow));
    stroke-dasharray: 85;
    stroke-dashoffset: 85;
    animation: drawLine 0.35s ease forwards;
}
.cell .x-mark line:nth-child(2) {
    animation-delay: 0.1s;
}
@keyframes drawLine {
    to { stroke-dashoffset: 0; }
}

.cell .o-mark circle {
    fill: none;
    stroke: var(--color-o);
    stroke-width: 7;
    stroke-linecap: round;
    filter: drop-shadow(0 0 6px var(--color-o-glow));
    stroke-dasharray: 188.5;
    stroke-dashoffset: 188.5;
    animation: drawCircle 0.4s ease forwards;
}
@keyframes drawCircle {
    to { stroke-dashoffset: 0; }
}

/* Cell tap ripple */
.cell-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0);
    animation: rippleAnim 0.5s ease forwards;
    pointer-events: none;
}
@keyframes rippleAnim {
    to { transform: scale(4); opacity: 0; }
}

.win-line-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* --- Power-ups --- */
.powerup-bar {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.powerup-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 20px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    font-family: var(--font-primary);
}
.powerup-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.powerup-btn:not(:disabled):hover {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px var(--color-accent-glow);
}
.pu-icon { font-size: 18px; }
.pu-label { font-size: 10px; color: var(--text-secondary); font-weight: 600; }
.pu-count {
    position: absolute;
    top: -4px; right: -4px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Streak */
.streak-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition-med);
}
.streak-bar.hot {
    border-color: var(--color-warning);
    color: var(--color-warning);
    box-shadow: 0 0 16px rgba(255, 145, 0, 0.2);
}

.game-bottom-bar {
    display: flex;
    gap: 12px;
}
.game-bottom-bar .btn { width: auto; }

/* --- Result Modal --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 16px;
}
.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    z-index: 1;
    max-width: 400px;
    width: 100%;
    text-align: center;
    animation: modalPop 0.4s ease forwards;
}
@keyframes modalPop {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.result-panel { padding: 32px 24px; }

.result-icon {
    font-size: 56px;
    margin-bottom: 8px;
    animation: resultBounce 0.6s ease;
}
@keyframes resultBounce {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    80% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.result-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 4px;
}
.result-title.win {
    background: linear-gradient(135deg, var(--color-win), var(--color-x));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.result-title.lose {
    color: var(--color-danger);
}
.result-title.draw {
    color: var(--color-warning);
}

.result-sub {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.result-stars {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    gap: 8px;
}
.result-stars .star {
    font-size: 32px;
    opacity: 0.2;
    transition: all 0.3s ease;
    transform: scale(0.8);
}
.result-stars .star.earned {
    opacity: 1;
    transform: scale(1);
    animation: starPop 0.4s ease forwards;
}
@keyframes starPop {
    0% { transform: scale(0); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 20px;
}
.rstat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.rstat-val {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--color-accent);
}
.rstat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.result-achievement {
    margin-bottom: 16px;
    min-height: 0;
}
.result-achievement:not(:empty) {
    padding: 10px 16px;
    background: rgba(255, 215, 0, 0.08);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: #ffd700;
    font-weight: 600;
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.result-buttons .btn { justify-content: center; }

/* --- Achievements --- */
.achieve-container {
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
}
.achieve-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}
.achieve-header h2 {
    font-family: var(--font-display);
    font-size: 20px;
    flex: 1;
}

.achieve-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.achieve-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}
.achieve-item.unlocked {
    border-color: rgba(255, 215, 0, 0.3);
    background: rgba(255, 215, 0, 0.04);
}
.achieve-item.locked {
    opacity: 0.5;
}
.achieve-icon {
    font-size: 28px;
    flex-shrink: 0;
}
.achieve-info { flex: 1; text-align: left; }
.achieve-name {
    font-size: 14px;
    font-weight: 700;
}
.achieve-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}
.achieve-status {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-win);
}
.achieve-item.locked .achieve-status {
    color: var(--text-muted);
}

/* --- Settings --- */
.settings-panel {
    padding: 28px;
}
.settings-panel h2 {
    font-family: var(--font-display);
    font-size: 20px;
    margin-bottom: 24px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-glass);
    font-size: 14px;
    color: var(--text-primary);
}
.setting-row:last-of-type {
    border-bottom: none;
    margin-bottom: 20px;
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-glass);
    border-radius: 13px;
    border: 1px solid var(--border-glass);
    cursor: pointer;
    transition: all var(--transition-med);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    top: 3px; left: 3px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--transition-med);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--color-accent);
    border-color: var(--color-accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
    background: #fff;
}

.theme-selector {
    display: flex;
    gap: 10px;
}
.theme-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border-glass);
    background: none;
    cursor: pointer;
    padding: 3px;
    transition: all var(--transition-fast);
}
.theme-btn.active {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px var(--color-accent-glow);
}
.theme-preview {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
}
.neon-preview { background: linear-gradient(135deg, #0a0a1a, #7c4dff); }
.gold-preview { background: linear-gradient(135deg, #0f0a1e, #ffd700); }
.glass-preview { background: linear-gradient(135deg, #e8ecf1, #6366f1); }

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 12px 24px;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    z-index: 200;
    transition: transform 0.4s ease;
    box-shadow: var(--shadow-soft);
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* --- Responsive --- */
@media (max-width: 480px) {
    .glass-panel { padding: 20px 16px; }
    .splash-title { font-size: 26px; }
    .menu-title { font-size: 22px; }
    .board-wrapper { max-width: 320px; }
    .level-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
    .score-val { font-size: 18px; }
    .tutorial-grid-demo { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); }
    .result-panel { padding: 24px 16px; }
}

@media (max-width: 360px) {
    .board-wrapper { max-width: 280px; }
    .level-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .score-panel { padding: 8px 10px; }
    .game-container { gap: 8px; }
}

@media (min-width: 768px) {
    .board-wrapper { max-width: 400px; }
    .level-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (max-height: 700px) {
    .board-wrapper { max-width: 320px; }
    .glass-panel { padding: 20px 16px; }
    .game-container { gap: 8px; }
    .splash-title { font-size: 28px; }
    .menu-title { font-size: 24px; }
}

@media (max-height: 600px) {
    .board-wrapper { max-width: 260px; }
    .score-panel { padding: 6px 10px; }
    .turn-indicator { padding: 6px 16px; }
    .splash-icon-wrap { width: 80px; height: 80px; margin-bottom: 16px; }
    .menu-icon { width: 56px; height: 56px; margin-bottom: 12px; }
    .btn { padding: 10px 20px; font-size: 14px; }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: 2px;
}

/* Accessibility - reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
