@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@500;700&display=swap');

/* =============================================
   KEYFRAME ANIMATIONS
   ============================================= */

/* Title "KINETIC" — slow pink/white glow pulse */
@keyframes titleGlowPink {
    0%   { text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 40px #ff00cc, 0 0 80px #ff00cc; }
    50%  { text-shadow: 0 0 6px #ffaaee, 0 0 30px #ff00cc, 0 0 60px #ff00cc, 0 0 120px #ff00cc; }
    100% { text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 40px #ff00cc, 0 0 80px #ff00cc; }
}

/* Title "REACTION" — slow green glow pulse, offset start */
@keyframes titleGlowGreen {
    0%   { text-shadow: 0 0 10px #fff, 0 0 20px #00ff44, 0 0 40px #00ff44; }
    50%  { text-shadow: 0 0 6px #aaffcc, 0 0 30px #00ff44, 0 0 70px #00ff44, 0 0 110px #00ff44; }
    100% { text-shadow: 0 0 10px #fff, 0 0 20px #00ff44, 0 0 40px #00ff44; }
}

/* Menu container border — cycles pink → cyan → pink */
@keyframes borderCycle {
    0%   { border-color: #ff8ad6; box-shadow: 0 0 30px rgba(255, 138, 214, 0.25), inset 0 0 20px rgba(255, 138, 214, 0.1); }
    33%  { border-color: #00ffff; box-shadow: 0 0 30px rgba(0, 255, 255, 0.25), inset 0 0 20px rgba(0, 255, 255, 0.1); }
    66%  { border-color: #aa88ff; box-shadow: 0 0 30px rgba(170, 136, 255, 0.25), inset 0 0 20px rgba(170, 136, 255, 0.1); }
    100% { border-color: #ff8ad6; box-shadow: 0 0 30px rgba(255, 138, 214, 0.25), inset 0 0 20px rgba(255, 138, 214, 0.1); }
}

/* Menu title text glow sweep */
@keyframes titleTextGlow {
    0%   { text-shadow: 0 0 10px rgba(0, 255, 255, 0.4); color: #00ffff; }
    50%  { text-shadow: 0 0 20px rgba(0, 255, 255, 0.9), 0 0 40px rgba(0, 255, 255, 0.4); color: #aaffff; }
    100% { text-shadow: 0 0 10px rgba(0, 255, 255, 0.4); color: #00ffff; }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: 'Rajdhani', sans-serif;
    background: #0b0c1a;
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(20, 22, 43, 1) 0%, rgba(11, 12, 26, 1) 100%),
        linear-gradient(rgba(255, 138, 214, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 138, 214, 0.03) 1px, transparent 1px);
    background-size: 100% 100%, 40px 40px, 40px 40px;
    color: white;
    overflow: hidden; /* Prevent scrolling */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* --- OVERLAYS & MENUS --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    /* Isolate compositing so child hover effects don't trigger a full-page repaint */
    isolation: isolate;
}

/* Blur on a pseudo-element so it lives on its own GPU layer and never
   repaints when buttons inside are hovered */
.overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(11, 12, 26, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: -1;
    will-change: opacity;
}

.overlay.active {
    opacity: 1;
    pointer-events: all;
}

.menu-container {
    background: rgba(20, 22, 43, 0.9);
    border: 2px solid #ff8ad6;
    border-radius: 16px;
    padding: clamp(20px, 4vh, 40px) clamp(20px, 5vw, 60px);
    text-align: center;
    box-shadow: 0 0 30px rgba(255, 138, 214, 0.2), inset 0 0 20px rgba(255, 138, 214, 0.1);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: borderCycle 6s ease-in-out infinite;
}

.overlay.active .menu-container {
    transform: scale(1);
}

.text-panel {
    max-width: 500px;
    text-align: left;
}

.text-panel p {
    font-family: 'Arial', sans-serif;
    line-height: 1.6;
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: #e0e0ff;
}

.game-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.8rem, 7vw, 4rem);
    font-weight: 900;
    line-height: 1.1;
    margin-bottom: 40px;
    color: #fff;
    text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 40px #ff00cc, 0 0 80px #ff00cc;
    letter-spacing: 4px;
    animation: titleGlowPink 4s ease-in-out infinite;
    cursor: default;
    user-select: none;
}

.game-title span {
    color: #00ff44;
    text-shadow: 0 0 10px #fff, 0 0 20px #00ff44, 0 0 40px #00ff44;
    animation: titleGlowGreen 4s ease-in-out infinite;
    animation-delay: -2s; /* offset so REACTION is out of phase with KINETIC */
}

.menu-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.2rem, 4.5vw, 2.5rem);
    margin-bottom: 30px;
    color: #00ffff;
    text-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
    text-align: center;
    animation: titleTextGlow 3s ease-in-out infinite;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: min(250px, 80vw);
    margin: 0 auto;
}

/* --- BUTTONS --- */
.neon-btn {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    padding: 12px 24px;
    background: transparent;
    color: #fff;
    border: 2px solid #00ffff;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: color 0.2s ease, box-shadow 0.2s ease, text-shadow 0.2s ease;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.2), inset 0 0 10px rgba(0, 255, 255, 0.1);
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
    /* Pre-promote to own GPU layer so hover doesn't cause a first-paint stutter */
    will-change: transform;
    transform: translateZ(0);
}

.neon-btn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #00ffff;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.neon-btn:hover {
    color: #0b0c1a;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.6), inset 0 0 20px rgba(0, 255, 255, 0.4);
    text-shadow: none;
}

.neon-btn:hover::before {
    opacity: 1;
}

.neon-btn.primary {
    border-color: #ff00cc;
    box-shadow: 0 0 15px rgba(255, 0, 204, 0.3), inset 0 0 10px rgba(255, 0, 204, 0.2);
}
.neon-btn.primary::before { background: #ff00cc; }
.neon-btn.primary:hover { box-shadow: 0 0 25px rgba(255, 0, 204, 0.8); }

.neon-btn.secondary {
    border-color: #888;
    color: #aaa;
    box-shadow: none;
}
.neon-btn.secondary::before { background: #888; }
.neon-btn.secondary:hover { color: #111; }

.neon-btn.player-color { border-color: #ff00cc; }
.neon-btn.player-color::before { background: #ff00cc; }

.neon-btn.ai-color { border-color: #00ff44; }
.neon-btn.ai-color::before { background: #00ff44; }

.neon-btn.warning {
    border-color: #ff3333;
}
.neon-btn.warning::before { background: #ff3333; }

.neon-btn.disabled {
    border-color: #333;
    color: #555;
    cursor: not-allowed;
    box-shadow: none;
    text-shadow: none;
}
.neon-btn.disabled:hover {
    color: #555;
    box-shadow: none;
}
.neon-btn.disabled::before { display: none; }

.neon-btn.small {
    font-size: 1rem;
    padding: 6px 16px;
    letter-spacing: 1px;
}

#btn-settings-game {
    padding: 6px 10px;
    font-size: 1.1rem;
    letter-spacing: 0;
    min-width: 0;
}

.mt-4 { margin-top: 25px; }

/* --- GAME UI --- */
#game-ui {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    transition: opacity 0.5s ease;
}

#game-ui.hidden {
    display: none;
}

.hidden {
    display: none !important;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 800px;
    margin-bottom: 10px;
    padding: 0 10px;
}

.left-controls {
    display: flex;
    gap: 8px;
}

/* ── Top-bar buttons: uniform consistent style ── */
.top-bar .neon-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    padding: 6px 14px;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.75);
    background: rgba(255, 255, 255, 0.04);
    box-shadow: none;
    text-shadow: none;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.top-bar .neon-btn::before {
    background: rgba(255, 255, 255, 0.08);
}

.top-bar .neon-btn:hover {
    border-color: rgba(255, 255, 255, 0.75);
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
    text-shadow: none;
}

.top-bar .neon-btn:hover::before {
    opacity: 0;
}

/* Gear icon: square, no extra letter-spacing */
#btn-settings-game.top-bar-btn,
.top-bar #btn-settings-game {
    padding: 6px 10px;
    letter-spacing: 0;
}

/* Turn indicator */
#turnText {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(13px, 2vw, 20px);
    font-weight: 700;
    letter-spacing: 2px;
    margin: 0;
    color: #fff;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.45);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 5px 18px;
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.9), 0 0 24px rgba(255, 255, 255, 0.4);
    white-space: nowrap;
}

.score-card {
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}

.score-card span {
    font-size: 1.8rem;
    font-family: 'Orbitron', sans-serif;
}

/* Score card color is set inline by JS via --player-color custom property */
.score-card {
    color: var(--player-color, #fff);
    text-shadow: 0 0 10px var(--player-glow, rgba(255,255,255,0.4));
}

#gameCanvas {
    display: block;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(255, 138, 214, 0.15),
                0 0 60px rgba(102, 126, 234, 0.1);
    background: #080914; /* Slightly darker than body */
    image-rendering: crisp-edges;
    flex-grow: 0;
}

/* --- SAVE/LOAD SLOTS --- */
.wide-panel {
    min-width: min(92vw, 400px);
}

.slots-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    max-height: 50vh;
    overflow-y: auto;
}

.save-slot {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #00ffff;
    border-radius: 8px;
    padding: 15px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.save-slot:hover {
    background: rgba(0, 255, 255, 0.1);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

.save-slot.empty {
    border-color: #555;
    color: #888;
    justify-content: center;
    font-style: italic;
}

.save-slot.empty:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #888;
    box-shadow: none;
}

.slot-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.slot-date {
    font-size: 1.1rem;
    color: #fff;
    font-weight: bold;
    font-family: 'Rajdhani', sans-serif;
}

.slot-details {
    font-size: 0.9rem;
    color: #ccc;
    font-family: 'Arial', sans-serif;
}

.slot-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-delete {
    background: transparent;
    border: 1px solid #ff3333;
    color: #ff3333;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.btn-delete:hover {
    background: #ff3333;
    color: white;
    box-shadow: 0 0 10px rgba(255, 51, 51, 0.5);
}

/* --- RATINGS WIDGET --- */
#ratings-widget {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    z-index: 10;
}

#ratings-label {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.85rem;
    color: #888;
    letter-spacing: 1px;
    text-transform: uppercase;
}

#stars {
    display: flex;
    gap: 4px;
}

.star {
    font-size: 1.8rem;
    color: #444;
    cursor: pointer;
    transition: color 0.15s ease, text-shadow 0.15s ease;
    line-height: 1;
    user-select: none;
}

.star:hover,
.star.hovered {
    color: #ffd700;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.7);
}

.star.selected {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.9), 0 0 20px rgba(255, 215, 0, 0.4);
}

/* --- CONFIRM MODAL --- */
.confirm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.confirm-backdrop.active {
    opacity: 1;
    pointer-events: all;
}

.confirm-box {
    background: rgba(20, 22, 43, 0.97);
    border: 2px solid #ff3333;
    border-radius: 12px;
    padding: 32px clamp(24px, 6vw, 48px);
    max-width: min(90vw, 480px);
    text-align: center;
    box-shadow: 0 0 30px rgba(255, 51, 51, 0.3), inset 0 0 20px rgba(255, 51, 51, 0.05);
    transform: scale(0.92);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.confirm-backdrop.active .confirm-box {
    transform: scale(1);
}

#confirm-message {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 24px;
    letter-spacing: 1px;
}

.confirm-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

/* --- MATCH SETTINGS --- */
.settings-section {
    margin-bottom: 20px;
    text-align: center;
}

.settings-label {
    display: block;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #aaa;
    margin-bottom: 10px;
}

.player-selector,
.grid-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 10px;
}

.count-btn,
.grid-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 8px 14px;
    background: transparent;
    color: #fff;
    border: 2px solid #555;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, background 0.2s ease;
    will-change: transform;
    transform: translateZ(0);
}

.count-btn:hover,
.grid-btn:hover {
    border-color: #00ffff;
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.4);
}

.count-btn.active,
.grid-btn.active {
    border-color: #00ffff;
    background: rgba(0, 255, 255, 0.15);
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.5);
    color: #00ffff;
}

/* Match settings panel — two-column layout */
#match-settings-menu .menu-container,
#ai-settings-menu .menu-container {
    width: min(96vw, 860px);
    max-width: 860px;
    padding: 24px 32px;
}

/* Safety net: if panel is still taller than the viewport on an unusual
   screen, make the overlay scroll rather than clip the content */
#match-settings-menu,
#ai-settings-menu {
    overflow-y: auto;
    align-items: flex-start;
}
#match-settings-menu .menu-container,
#ai-settings-menu .menu-container {
    margin: auto;
}

.match-settings-panel { /* intentionally empty — sizing handled above */ }

.match-settings-body {
    display: flex;
    gap: 28px;
    align-items: flex-start;
    margin-top: 4px;
}

/* Left column: selectors + action buttons */
.match-col-left {
    flex: 0 0 auto;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Right column: name inputs + grid preview */
.match-col-right {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.match-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
}

.optional-hint {
    font-size: 0.75rem;
    color: #666;
    letter-spacing: 1px;
    font-style: italic;
    text-transform: none;
}

/* Name inputs: 2-column grid so all 8 fit without scrolling */
#player-names-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

.player-name-row {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.player-name-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-name-input {
    flex: 1;
    min-width: 0;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 5px 9px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    outline: none;
    transition: filter 0.15s ease;
}

.player-name-input::placeholder {
    opacity: 0.55;
    font-style: italic;
    font-weight: 400;
    color: #aaaaaa;
}

.player-name-input:focus {
    filter: brightness(1.25);
}

/* --- GRID PREVIEW (Match Settings) --- */
#grid-preview {
    display: block;
    border-radius: 6px;
    max-width: 100%;  /* never wider than the column, but no upscaling */
    align-self: center;
}
#scoreboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    background: rgba(20, 22, 43, 0.6);
    padding: 10px 30px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- AI DIFFICULTY SELECTOR --- */
.difficulty-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 10px;
}

.diff-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 8px 20px;
    background: transparent;
    color: #fff;
    border: 2px solid #555;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, background 0.2s ease;
    will-change: transform;
    transform: translateZ(0);
}

/* Easy — green */
.diff-btn[data-difficulty="easy"]:hover,
.diff-btn[data-difficulty="easy"].active {
    border-color: #00ff88;
    color: #00ff88;
    box-shadow: 0 0 12px rgba(0, 255, 136, 0.5);
}
.diff-btn[data-difficulty="easy"].active {
    background: rgba(0, 255, 136, 0.12);
}

/* Medium — yellow */
.diff-btn[data-difficulty="medium"]:hover,
.diff-btn[data-difficulty="medium"].active {
    border-color: #ffe600;
    color: #ffe600;
    box-shadow: 0 0 12px rgba(255, 230, 0, 0.5);
}
.diff-btn[data-difficulty="medium"].active {
    background: rgba(255, 230, 0, 0.10);
}

/* Hard — red */
.diff-btn[data-difficulty="hard"]:hover,
.diff-btn[data-difficulty="hard"].active {
    border-color: #ff3333;
    color: #ff3333;
    box-shadow: 0 0 12px rgba(255, 51, 51, 0.5);
}
.diff-btn[data-difficulty="hard"].active {
    background: rgba(255, 51, 51, 0.10);
}

/* AI grid preview canvas */
#ai-grid-preview {
    display: block;
    border-radius: 6px;
    max-width: 100%;
    align-self: center;
}

/* --- AI COLOR PICKER --- */
.color-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    justify-items: center;
    justify-content: center;
    margin: 0 auto 4px auto;
    width: fit-content;
}

/* Side-by-side player + AI color pickers */
.ai-color-pickers-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

.ai-color-picker-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.ai-color-picker-col .settings-label {
    margin-bottom: 4px;
}

.ai-color-picker-divider {
    width: 1px;
    background: rgba(255, 255, 255, 0.12);
    align-self: stretch;
    margin: 20px 0;
}

/* Smaller swatches inside the PvAI panel so the right column fits on laptop */
#ai-settings-menu .color-swatch {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    /* Single 32×32 ball images — scale to fit and center */
    background-size: 70%;
    background-position: center center;
    flex-shrink: 0;
}

#ai-settings-menu .match-col-right {
    gap: 6px;
}


.color-swatch {
    position: relative;
    width: 72px;
    height: 72px;
    min-width: 72px;
    min-height: 72px;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 2px solid #333;
    border-radius: 14px;
    cursor: pointer;
    background-color: #1a1a2e;
    background-repeat: no-repeat;
    /* Sprite sheet 46×60px (2×2, each frame 23×30px).
       Scale so one frame ≈ 58px tall (fits with padding):
       factor 1.933 → sheet 88.9×116px, frame 44.5×58px.
       Center frame 0: x=(72-44.5)/2≈14px, y=(72-58)/2=7px */
    background-size: 88.9px 116px;
    background-position: 14px 7px;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    overflow: hidden;
    flex-shrink: 0;
}

/* Remove the oval pseudo-element — sprite handles the visual */
.color-swatch::after {
    content: none;
}

.color-swatch:hover {
    transform: scale(1.08);
    border-color: #666;
}

.color-swatch.active {
    border-color: var(--swatch-color, #fff);
    box-shadow: 0 0 16px var(--swatch-color, #fff);
    transform: scale(1.08);
}

/* Swatch is taken by the other picker — dim it but keep it clickable (auto-swap handles it) */
.color-swatch.taken {
    opacity: 0.3;
    filter: grayscale(60%);
    cursor: not-allowed;
}

/* =============================================
   SETTINGS PAGE
   ============================================= */

/* Settings menu container sizing */
#settings-menu .menu-container {
    width: min(96vw, 560px);
    padding: 28px 36px;
}

/* 2×2 grid of setting groups */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    text-align: left;
    margin-bottom: 4px;
}

/* Individual group box */
.settings-group {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Group heading */
.settings-group-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.68rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #00ffff;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
    margin-bottom: 2px;
}

/* Each label + control row */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 28px;
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 6px;
}

.setting-label {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.95rem;
    color: #ccc;
    flex-shrink: 0;
}

/* --- Toggle Switch --- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #555;
    border-radius: 12px;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #888;
    border-radius: 50%;
    transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-switch input:checked + .toggle-track {
    background: rgba(0, 255, 255, 0.15);
    border-color: #00ffff;
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.4);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(20px);
    background: #00ffff;
}

/* --- Neon Range Slider --- */
.slider-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.neon-slider {
    -webkit-appearance: none;
    appearance: none;
    width: clamp(60px, 12vw, 100px);
    height: 3px;
    background: rgba(0, 255, 255, 0.25);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.neon-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00ffff;
    box-shadow: 0 0 6px rgba(0, 255, 255, 0.7);
    cursor: pointer;
    transition: box-shadow 0.15s ease;
}

.neon-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 0 12px rgba(0, 255, 255, 1);
}

.neon-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: none;
    border-radius: 50%;
    background: #00ffff;
    box-shadow: 0 0 6px rgba(0, 255, 255, 0.7);
    cursor: pointer;
}

.slider-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    color: #00ffff;
    min-width: 32px;
    text-align: right;
}

/* --- Segmented Control --- */
.segmented-control {
    display: flex;
    border: 1px solid #444;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
}

.seg-btn {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0;
    padding: 4px 9px;
    background: transparent;
    color: #666;
    border: none;
    border-right: 1px solid #444;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.seg-btn:last-child {
    border-right: none;
}

.seg-btn:hover {
    color: #aaa;
    background: rgba(255, 255, 255, 0.05);
}

.seg-btn.active {
    background: rgba(0, 255, 255, 0.15);
    color: #00ffff;
}

/* --- Reduce Motion Overrides --- */
body.reduce-motion .game-title,
body.reduce-motion .game-title span,
body.reduce-motion .menu-title,
body.reduce-motion .menu-container {
    animation: none !important;
}

/* =============================================
   HOW TO PLAY — TABBED LAYOUT
   ============================================= */

.htp-panel {
    width: min(700px, 92vw);
    max-width: 700px;
    text-align: left;
}

/* --- Tab navigation --- */
.htp-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    border-bottom: 2px solid rgba(0, 255, 255, 0.15);
    padding-bottom: 8px;
}

.htp-tab-btn {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 5px 16px;
    background: transparent;
    color: #666;
    border: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.htp-tab-btn:hover {
    color: #aaa;
}

.htp-tab-btn.active {
    color: #00ffff;
    border-color: #00ffff;
    background: rgba(0, 255, 255, 0.07);
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
}

/* --- Scrollable content area --- */
.htp-content {
    max-height: 52vh;
    overflow-y: auto;
    padding-right: 6px;
}

.htp-content::-webkit-scrollbar { width: 5px; }
.htp-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 4px; }
.htp-content::-webkit-scrollbar-thumb { background: rgba(0,255,255,0.35); border-radius: 4px; }

/* --- Section visibility --- */
.htp-section { display: none; }
.htp-section.active { display: block; }

/* --- Section headings --- */
.htp-heading {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    color: #00ffff;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 18px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(0, 255, 255, 0.18);
}

.htp-heading:first-child { margin-top: 0; }

/* --- Sub-text --- */
.htp-sub {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.95rem;
    color: #888;
    margin-bottom: 10px;
    line-height: 1.5;
}

/* --- Rule rows (icon + text) --- */
.htp-rule {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 9px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.05rem;
    color: #d0d0f0;
    line-height: 1.5;
}

.htp-rule-icon {
    flex-shrink: 0;
    font-size: 1rem;
    margin-top: 2px;
    color: #00ffff;
}

.htp-rule strong { color: #fff; }

/* --- Cell type grid diagram --- */
.htp-cell-layout {
    display: flex;
    gap: 22px;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.htp-cell-grid {
    display: grid;
    grid-template-columns: repeat(4, 34px);
    gap: 4px;
}

.htp-grid-caption {
    font-size: 0.75rem;
    color: #555;
    text-align: center;
    margin-top: 5px;
}

.htp-cell {
    width: 34px;
    height: 34px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    border: 2px solid;
}

.htp-cell.corner  { background: rgba(255, 51, 51, 0.15);  border-color: #ff3333; color: #ff6666; }
.htp-cell.edge    { background: rgba(255, 166, 0, 0.15);  border-color: #ffa600; color: #ffcc44; }
.htp-cell.interior{ background: rgba(0, 204, 68, 0.12);   border-color: #00cc44; color: #44ff88; }

/* --- Cell legend --- */
.htp-cell-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.htp-cell-legend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    color: #d0d0f0;
}

.htp-legend-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 2px solid;
    flex-shrink: 0;
}

.htp-legend-swatch.corner   { background: rgba(255, 51, 51, 0.2);  border-color: #ff3333; }
.htp-legend-swatch.edge     { background: rgba(255, 166, 0, 0.2);  border-color: #ffa600; }
.htp-legend-swatch.interior { background: rgba(0, 204, 68, 0.15);  border-color: #00cc44; }

/* Color labels */
.corner-label   { color: #ff6666; }
.edge-label     { color: #ffcc44; }
.interior-label { color: #44ff88; }

/* --- Explosion diagram --- */
.htp-explosion-layout {
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.htp-explosion-diagram {
    display: grid;
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
    gap: 4px;
}

.htp-exp-cell {
    width: 42px;
    height: 42px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.htp-exp-cell.empty  { background: transparent; border: 1px solid rgba(255,255,255,0.05); }
.htp-exp-cell.arrow  { background: rgba(0,255,255,0.07); border: 1px solid rgba(0,255,255,0.2); color: #00ffff; font-size: 1.25rem; }
.htp-exp-cell.center { background: rgba(255,0,204,0.22); border: 2px solid #ff00cc; box-shadow: 0 0 8px rgba(255,0,204,0.4); font-size: 1.3rem; }

.htp-exp-notes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.htp-exp-note-row {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    color: #c0c0e0;
    line-height: 1.4;
}

/* --- Callout boxes --- */
.htp-tip {
    background: rgba(0, 255, 255, 0.05);
    border-left: 3px solid #00ffff;
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 8px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.03rem;
    color: #d0d0f0;
    line-height: 1.5;
}

.htp-tip strong { color: #00ffff; }

.htp-note {
    background: rgba(170, 136, 255, 0.07);
    border-left: 3px solid #aa88ff;
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
    margin-top: 12px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.97rem;
    color: #c0b0f0;
    line-height: 1.5;
}

/* --- AI difficulty badges --- */
.htp-diff-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.03rem;
    color: #d0d0f0;
    line-height: 1.5;
}

.htp-diff-badge {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 4px;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 2px;
}

.htp-diff-badge.easy   { background: rgba(0, 204, 68, 0.18);  border: 1px solid #00cc44; color: #00ff55; }
.htp-diff-badge.medium { background: rgba(255,166, 0, 0.18);  border: 1px solid #ffa600; color: #ffcc00; }
.htp-diff-badge.hard   { background: rgba(255, 51, 51, 0.18); border: 1px solid #ff3333; color: #ff5555; }

.htp-diff-row strong { color: #fff; }

/* --- GAME OVER SCOREBOARD --- */
#gameover-overlay {
    z-index: 200;
    /* Allow scrolling if the panel is taller than the viewport */
    overflow-y: auto;
    align-items: flex-start;
    padding: clamp(8px, 2vh, 24px) 0;
}

.scoreboard-panel {
    min-width: min(92vw, 380px);
    max-width: min(92vw, 500px);
    /* Ensure the panel itself never exceeds the viewport height */
    max-height: calc(100vh - clamp(16px, 4vh, 48px));
    display: flex;
    flex-direction: column;
    margin: auto; /* keep it centred when overlay scrolls */
}

.gameover-title {
    font-size: clamp(1.8rem, 4.5vh, 3rem);
    margin-bottom: clamp(6px, 1vh, 10px);
    animation: titleGlowPink 2s ease-in-out infinite;
    flex-shrink: 0;
}

.gameover-winner {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1rem, 2.5vh, 1.6rem);
    font-weight: 700;
    margin-bottom: clamp(10px, 2vh, 25px);
    padding: clamp(8px, 1.5vh, 12px) clamp(12px, 2vw, 20px);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid currentColor;
    flex-shrink: 0;
}

.gameover-winner .winner-name {
    display: block;
}

.gameover-winner .winner-subtitle {
    font-size: clamp(0.65rem, 1.2vh, 0.8rem);
    font-weight: 400;
    opacity: 0.8;
    margin-top: 4px;
}

.gameover-rankings {
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 0.8vh, 8px);
    margin-bottom: clamp(12px, 2vh, 30px);
    /* Let the list scroll inside the panel on short screens */
    overflow-y: auto;
    flex-shrink: 1;
    min-height: 0;
}

/* Custom scrollbar for rankings list */
.gameover-rankings::-webkit-scrollbar { width: 4px; }
.gameover-rankings::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 4px; }
.gameover-rankings::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.ranking-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: clamp(6px, 1.2vh, 10px) clamp(10px, 1.5vw, 16px);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: transform 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
}

.ranking-row:first-child {
    background: rgba(255, 215, 0, 0.1);
    border-color: rgba(255, 215, 0, 0.3);
    transform: scale(1.02);
}

.ranking-row:first-child .ranking-position {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.ranking-position {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.85rem, 1.8vh, 1.2rem);
    font-weight: 700;
    min-width: 44px;
    color: #888;
}

.ranking-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
    flex-shrink: 0;
}

.ranking-name {
    font-family: 'Rajdhani', sans-serif;
    font-size: clamp(0.9rem, 1.8vh, 1.1rem);
    font-weight: 600;
    flex: 1;
    color: #e0e0ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ranking-status {
    font-size: clamp(0.6rem, 1.1vh, 0.75rem);
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.ranking-status.winner {
    background: rgba(255, 215, 0, 0.2);
    color: #ffd700;
    border: 1px solid rgba(255, 215, 0, 0.4);
}

.ranking-status.eliminated {
    background: rgba(255, 51, 51, 0.15);
    color: #ff5555;
    border: 1px solid rgba(255, 51, 51, 0.3);
}

.gameover-actions {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.2vh, 12px);
    align-items: center;
    flex-shrink: 0;
}

.gameover-actions .neon-btn {
    width: 100%;
    max-width: 260px;
}

/* ── Laptop / medium screens (height 600–850px) ── */
@media (max-height: 850px) and (min-width: 601px) {
    .gameover-title {
        font-size: clamp(1.5rem, 3.5vh, 2.2rem);
        margin-bottom: 6px;
    }

    .gameover-winner {
        font-size: clamp(0.95rem, 2vh, 1.3rem);
        padding: 8px 16px;
        margin-bottom: 12px;
    }

    .gameover-rankings {
        gap: 5px;
        margin-bottom: 14px;
    }

    .ranking-row {
        padding: 6px 12px;
        gap: 10px;
    }

    .ranking-position {
        font-size: 0.95rem;
        min-width: 38px;
    }

    .ranking-name {
        font-size: 0.95rem;
    }

    .ranking-status {
        font-size: 0.65rem;
        padding: 2px 8px;
    }

    .gameover-actions {
        gap: 8px;
    }

    .gameover-actions .neon-btn {
        padding: 10px 20px;
        font-size: 1.1rem;
    }
}

/* =============================================================
   RESPONSIVE — TABLET (≤ 860px) & MOBILE (≤ 600px)
   ============================================================= */

/* ── Tablet & below: stack the two-column match/AI settings ── */
@media (max-width: 860px) {
    .match-settings-body {
        flex-direction: column;
        gap: 20px;
    }

    .match-col-left {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 16px;
        justify-content: center;
    }

    .match-col-left .settings-section {
        margin-bottom: 0;
    }

    .match-actions {
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
    }

    #ai-settings-menu .match-col-left {
        align-items: center;
    }

    /* Center right-column content (color picker, names, grid preview) */
    .match-col-right {
        align-items: center;
        text-align: center;
        width: 100%;
    }

    .match-col-right .settings-label {
        display: block;
        text-align: center;
        width: 100%;
    }

    .match-col-right .color-picker {
        justify-content: center;
        margin-left: auto;
        margin-right: auto;
    }

    /* AI panel: single player name row */
    .match-col-right .player-name-row {
        justify-content: center;
        width: 100%;
        max-width: 280px;
        margin-left: auto;
        margin-right: auto;
    }

    /* PvP panel: player names grid */
    .match-col-right #player-names-list {
        width: 100%;
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
        justify-items: stretch;
    }

    /* Grid preview canvases */
    .match-col-right #grid-preview,
    .match-col-right #ai-grid-preview {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }
}

/* ── Mobile ── */
@media (max-width: 600px) {

    /* --- Overlays: don't let them overflow the screen --- */
    .overlay {
        padding: 12px;
    }

    /* --- Default panel --- */
    .menu-container {
        border-radius: 12px;
        width: 96vw;
        max-width: 96vw;
    }

    /* --- Main menu title --- */
    .game-title {
        font-size: clamp(1.5rem, 9vw, 2.4rem);
        letter-spacing: 2px;
        margin-bottom: 24px;
    }

    .menu-title {
        font-size: clamp(1.1rem, 5.5vw, 1.7rem);
        margin-bottom: 18px;
    }

    .menu-buttons {
        gap: 11px;
    }

    /* --- Buttons (menus only — NOT the in-game top bar) --- */
    .neon-btn {
        font-size: 1.05rem;
        padding: 10px 18px;
        letter-spacing: 1px;
    }

    .neon-btn.small {
        font-size: 0.85rem;
        padding: 7px 13px;
    }

    /* Re-assert top-bar button style so menu .neon-btn rules don't bleed in */
    .top-bar .neon-btn {
        font-family: 'Orbitron', sans-serif;
        font-size: 0.6rem;
        font-weight: 700;
        letter-spacing: 1.5px;
        padding: 5px 10px;
        border: 1.5px solid rgba(255, 255, 255, 0.35);
        border-radius: 6px;
        color: rgba(255, 255, 255, 0.75);
        background: rgba(255, 255, 255, 0.04);
        box-shadow: none;
        text-shadow: none;
    }

    .top-bar #btn-settings-game {
        padding: 5px 8px;
        letter-spacing: 0;
    }

    /* --- Match & AI settings panels --- */
    #match-settings-menu .menu-container,
    #ai-settings-menu .menu-container {
        padding: 16px 14px;
    }

    .match-col-left {
        gap: 12px;
    }

    /* Match settings right column: stay centered on mobile */
    .match-col-right {
        align-items: center;
        text-align: center;
        width: 100%;
    }

    .match-col-right .settings-label {
        display: block;
        text-align: center;
        width: 100%;
    }

    .match-col-right .color-picker {
        justify-content: center;
        margin-left: auto;
        margin-right: auto;
    }

    .match-col-right .player-name-row {
        justify-content: center;
        width: 100%;
        max-width: 280px;
        margin-left: auto;
        margin-right: auto;
    }

    .match-col-right #player-names-list {
        width: 100%;
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
        grid-template-columns: 1fr;
    }

    .match-col-right #grid-preview,
    .match-col-right #ai-grid-preview {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }

    /* --- Settings panel --- */
    #settings-menu .menu-container {
        padding: 18px 14px;
    }

    /* 2-col grid → 1-col on mobile */
    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* Sliders: allow to grow inside the now-wider single-column group */
    .neon-slider {
        width: clamp(80px, 30vw, 140px);
    }

    /* --- Save / Load panel --- */
    .wide-panel {
        padding: 20px 16px;
    }

    .slots-container {
        max-height: 45vh;
    }

    /* --- Game Over panel --- */
    .scoreboard-panel {
        padding: 20px 16px;
        max-height: calc(100vh - 24px);
    }

    .gameover-title {
        font-size: clamp(1.6rem, 7vw, 2.4rem);
        margin-bottom: 8px;
    }

    .gameover-winner {
        font-size: clamp(1rem, 4.5vw, 1.4rem);
        padding: 10px 14px;
        margin-bottom: 16px;
    }

    .ranking-row {
        padding: 8px 10px;
        gap: 8px;
    }

    .ranking-position {
        font-size: 1rem;
        min-width: 34px;
    }

    .ranking-name {
        font-size: 0.95rem;
    }

    .gameover-actions .neon-btn {
        max-width: 100%;
    }

    /* --- Confirm modal --- */
    .confirm-box {
        padding: 24px 20px;
    }

    /* --- Game UI (in-game overlay) --- */
    #game-ui {
        padding: 6px 6px 4px;
    }

    .top-bar {
        flex-wrap: wrap;
        row-gap: 6px;
        padding: 0 4px;
        margin-bottom: 6px;
    }

    /* Turn text fills the full top row on mobile */
    #turnText {
        order: -1;
        width: 100%;
        text-align: center;
        font-size: clamp(11px, 3.5vw, 16px);
        padding: 4px 14px;
    }

    .left-controls {
        gap: 6px;
    }

    #scoreboard {
        padding: 6px 14px;
        gap: 10px;
        margin-bottom: 8px;
    }

    .score-card {
        font-size: 1.1rem;
        gap: 6px;
    }

    .score-card span {
        font-size: 1.3rem;
    }

    /* --- How To Play --- */
    .htp-content {
        max-height: 42vh;
    }

    /* --- Ratings widget: too small to be useful on mobile --- */
    #ratings-widget {
        display: none;
    }

    /* --- AI color swatches on mobile: 40px so both pickers can still fit side-by-side --- */
    #ai-settings-menu .color-swatch {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        background-size: 65%;
        background-position: center center;
    }

    /* Hide the vertical divider between the two color pickers when they wrap */
    .ai-color-picker-divider {
        display: none;
    }
}

/* ── Very small phones (≤ 380px) ── */
@media (max-width: 380px) {
    .game-title {
        font-size: clamp(1.3rem, 10vw, 2rem);
    }

    .menu-title {
        font-size: clamp(1rem, 6vw, 1.4rem);
    }

    .neon-btn {
        font-size: 0.95rem;
        padding: 9px 14px;
    }

    /* Keep top-bar buttons small and consistent */
    .top-bar .neon-btn {
        font-size: 0.55rem;
        padding: 4px 8px;
    }

    .top-bar #btn-settings-game {
        padding: 4px 7px;
    }

    /* AI color swatches: slightly smaller on tiny screens */
    #ai-settings-menu .color-swatch {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        background-size: 65%;
        background-position: center center;
    }

    .color-picker {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
}
