/* ==========================================================================
   THE GENIUS SQUARE - STYLESHEET
   Tactile 3D Aesthetics, Fluid Responsiveness & Mobile Touch UX Optimization
   Includes Rolled Blockers Dice Section at Bottom with Top & Bottom Margins.
   ========================================================================== */

:root {
    /* Color Tokens */
    --bg-main: #0e1015;
    --bg-card: #161820;
    --bg-board: #0d0f14;
    --border-color: #2a2d39;
    --border-highlight: #3b3f50;
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-active: #1d4ed8;
    
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --cpu-color: #06b6d4;

    /* Piece Specific Colors (3D Beveled Palette) */
    --piece-blue: #1e40af;
    --piece-blue-light: #3b82f6;
    --piece-cyan: #0891b2;
    --piece-cyan-light: #06b6d4;
    --piece-red: #b91c1c;
    --piece-red-light: #ef4444;
    --piece-green: #047857;
    --piece-green-light: #10b981;
    --piece-yellow: #a16207;
    --piece-yellow-light: #eab308;
    --piece-white: #94a3b8;
    --piece-white-light: #f8fafc;
    --piece-orange: #c2410c;
    --piece-orange-light: #f97316;
    --piece-purple: #6d28d9;
    --piece-purple-light: #8b5cf6;
    --piece-pink: #be185d;
    --piece-pink-light: #ec4899;

    /* Metrics & Sizing */
    --cell-size: 54px;
    --grid-gap: 3px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 6px rgba(0,0,0,0.4);
    --shadow-md: 0 6px 16px rgba(0,0,0,0.5);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.7);
    --font-heading: 'Outfit', -apple-system, sans-serif;
    --font-mono: 'Space Grotesk', monospace;
}

/* Adjust cell size dynamically for tablet & mobile */
@media (max-width: 900px) {
    :root {
        --cell-size: 46px;
    }
}
@media (max-width: 600px) {
    :root {
        --cell-size: 40px;
    }
}
@media (max-width: 420px) {
    :root {
        --cell-size: 34px;
    }
}
@media (max-width: 360px) {
    :root {
        --cell-size: 30px;
    }
}

/* Reset & Global Settings */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    touch-action: manipulation;
}

body {
    font-family: var(--font-heading);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 12px 0 12px;
    background-image: 
        radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.08) 0%, transparent 60%),
        radial-gradient(circle at 100% 100%, rgba(139, 92, 246, 0.05) 0%, transparent 40%);
}

.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==========================================================================
   HEADER & STATS BAR & MODE SELECTOR
   ========================================================================== */

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    flex-wrap: wrap;
    gap: 12px;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: grid;
    grid-template-columns: repeat(2, 12px);
    grid-gap: 3px;
}

.logo-block {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.4);
}
.b-red { background: var(--piece-red-light); }
.b-yellow { background: var(--piece-yellow-light); }
.b-green { background: var(--piece-green-light); }
.b-purple { background: var(--piece-purple-light); }

.logo-area h1 {
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 1px;
    color: #fff;
    margin: 0;
}
.logo-area h1 span {
    color: var(--accent-primary);
}

/* Mode Selector Styling */
.mode-selector-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.mode-label {
    font-size: 0.68rem;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.btn-mode {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 6px 10px;
    font-size: 0.8rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    min-height: 36px;
}

.btn-mode.active-mode {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.stats-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

.stat-card {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    padding: 4px 12px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 68px;
}

.stat-label {
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 40px;
    min-height: 40px;
}

.btn-icon:hover, .btn-icon:active {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-color: var(--border-highlight);
}

/* Buttons */
.btn {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.92rem;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    min-height: 44px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
}

.btn-primary:hover, .btn-primary:active {
    background: linear-gradient(135deg, #4f46e5 0%, var(--accent-active) 100%);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover, .btn-secondary:active {
    background: rgba(255,255,255,0.14);
    border-color: var(--border-highlight);
}

.btn-danger-text {
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
    min-height: 36px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.pulse-btn {
    animation: pulseGlow 2.5s infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
}

/* ==========================================================================
   MAIN CONTROLS & DICE SECTION AT BOTTOM
   ========================================================================== */

.controls-bar {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

/* Rolled Blockers Dice Section (Positioned at Bottom with Margins) */
.dice-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
    margin-top: 20px;
    margin-bottom: 20px;
    width: 100%;
}

.dice-section-title {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--text-muted);
}

.dice-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    min-height: 44px;
}

.dice-placeholder {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
}

/* 3D Dice styling */
.die-cube {
    width: 38px;
    height: 38px;
    background: linear-gradient(145deg, #282c37, #15171e);
    border: 2px solid #454a5c;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 800;
    font-size: 0.95rem;
    color: #ffffff;
    box-shadow: 
        inset 0 2px 0 rgba(255,255,255,0.2),
        0 4px 8px rgba(0,0,0,0.6);
}

.die-cube.rolling {
    animation: spinDie 0.6s ease-out;
}

@keyframes spinDie {
    0% { transform: rotateX(0deg) rotateY(0deg) scale(0.8); }
    50% { transform: rotateX(360deg) rotateY(180deg) scale(1.15); }
    100% { transform: rotateX(720deg) rotateY(360deg) scale(1); }
}

/* ==========================================================================
   PLAY FIELD: BOARD & TRAY
   ========================================================================== */

.play-field {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 20px;
    align-items: start;
}

/* Board Outer Frame */
.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.board-container {
    background: #181b22;
    border: 5px solid #282c38;
    border-radius: var(--radius-lg);
    padding: 8px;
    box-shadow: 
        0 16px 36px rgba(0,0,0,0.8),
        inset 0 2px 4px rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    touch-action: none;
}

/* Coordinates Styling (A-F, 1-6) */
.coord-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}
.coord-row span {
    flex: 1;
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    color: #e2e8f0;
    letter-spacing: 0.5px;
}
.coord-spacer {
    width: 20px;
    flex: none !important;
}

.board-middle {
    display: flex;
    align-items: center;
}

.coord-col {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: calc((var(--cell-size) * 6) + (var(--grid-gap) * 5));
    width: 20px;
}
.coord-col span {
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    color: #e2e8f0;
}

/* 6x6 Grid Board */
.grid-board {
    display: grid;
    grid-template-columns: repeat(6, var(--cell-size));
    grid-template-rows: repeat(6, var(--cell-size));
    gap: var(--grid-gap);
    background: #090a0e;
    padding: var(--grid-gap);
    border-radius: var(--radius-md);
    border: 2px solid #202430;
    position: relative;
    touch-action: none;
}

/* Board Cell */
.board-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: #141720;
    border-radius: 4px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,0.03);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
    transition: background 0.15s ease, border-color 0.15s ease;
    touch-action: none;
}

.board-cell.valid-hover {
    background: rgba(16, 185, 129, 0.35);
    border: 2px dashed #10b981;
}

.board-cell.invalid-hover {
    background: rgba(239, 68, 68, 0.35);
    border: 2px dashed #ef4444;
}

.board-cell.hint-cell {
    animation: hintFlash 1.2s infinite alternate;
}

@keyframes hintFlash {
    0% { background: rgba(234, 179, 8, 0.15); border: 2px solid rgba(234, 179, 8, 0.4); }
    100% { background: rgba(234, 179, 8, 0.45); border: 2px solid rgba(234, 179, 8, 0.9); }
}

/* White Blocker Peg */
.blocker-peg {
    width: calc(var(--cell-size) * 0.72);
    height: calc(var(--cell-size) * 0.72);
    background: linear-gradient(145deg, #ffffff, #d1d5db);
    border-radius: 50%;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.6),
        inset 0 -3px 4px rgba(0,0,0,0.3),
        inset 0 3px 4px rgba(255,255,255,0.9);
    position: relative;
    z-index: 5;
    pointer-events: none;
}

.blocker-peg.animate-drop {
    animation: dropPeg 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.blocker-peg::after {
    content: '';
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    background: linear-gradient(145deg, #f8fafc, #e2e8f0);
    border-radius: 50%;
}

@keyframes dropPeg {
    0% { transform: scale(1.6) translateY(-20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

.board-footer-info {
    margin-top: 2px;
}

.status-badge {
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}
.status-ready { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
.status-active { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.status-solved { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.status-warning { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }

/* ==========================================================================
   TETRIS PIECES TRAY & PER-PIECE CONTROLS
   ========================================================================== */

.tray-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    box-shadow: var(--shadow-md);
    touch-action: none;
}

.tray-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.tray-header h2 {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.desktop-shortcut-guide {
    display: inline;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.mobile-shortcut-guide {
    display: none;
    font-size: 0.78rem;
    color: var(--accent-primary);
}

.piece-actions-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 12px;
}

.piece-selection-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.piece-action-btns {
    display: flex;
    gap: 6px;
}

.btn-touch-action {
    min-height: 40px;
    padding: 6px 14px;
    font-size: 0.85rem;
}

.pieces-tray {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    padding: 4px;
    max-height: 480px;
    overflow-y: auto;
    touch-action: pan-y;
}

/* Individual Polyomino Piece Item */
.piece-item {
    background: #11131a;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 6px 6px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    transition: all 0.15s ease;
    position: relative;
    min-height: 110px;
    touch-action: none;
}

.piece-item:hover {
    border-color: var(--accent-primary);
    background: #171a24;
}

.piece-item.selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
    background: #191c28;
}

.piece-item.placed {
    opacity: 0.25;
    cursor: default;
    filter: grayscale(0.8);
}
.piece-item.placed .piece-item-actions {
    pointer-events: none;
    opacity: 0.3;
}

.piece-item.just-returned {
    animation: returnPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 18px rgba(59, 130, 246, 0.85) !important;
    background: #1e2436 !important;
    z-index: 50;
}

@keyframes returnPop {
    0% { transform: scale(0.6); opacity: 0.2; filter: brightness(1.8); }
    50% { transform: scale(1.15); opacity: 1; filter: brightness(1.4); }
    100% { transform: scale(1); opacity: 1; filter: brightness(1); }
}

/* Per-piece Rotate & Flip Buttons */
.piece-item-actions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    width: 100%;
    justify-content: center;
}

.piece-btn-mini {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 32px;
}

.piece-btn-mini:hover, .piece-btn-mini:active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* Grid Matrix for Polyomino Shapes */
.polyomino-grid {
    display: grid;
    gap: 2px;
    margin: auto;
}

.poly-cell {
    width: 24px;
    height: 24px;
    border-radius: 3px;
    box-shadow: 
        inset 0 1px 0 rgba(255,255,255,0.4),
        inset 0 -2px 0 rgba(0,0,0,0.4),
        0 1px 3px rgba(0,0,0,0.3);
    position: relative;
    border: 1px solid rgba(0,0,0,0.2);
}

.poly-cell.empty {
    visibility: hidden;
    box-shadow: none;
    border: none;
}

/* Board Placed Piece Cells */
.placed-block {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 4px;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    box-shadow: 
        inset 0 2px 0 rgba(255,255,255,0.4),
        inset 0 -3px 0 rgba(0,0,0,0.5),
        0 2px 4px rgba(0,0,0,0.4);
    border: 1px solid rgba(0,0,0,0.3);
    touch-action: none;
}

/* Wrong Placed Piece Overlay (Highlighted with Red Border & Pulsing ❌) */
.placed-block.wrong-piece {
    border: 3px solid #ef4444 !important;
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.95), inset 0 0 10px rgba(239, 68, 68, 0.8) !important;
    animation: wrongPulse 0.8s infinite alternate ease-in-out !important;
    z-index: 20 !important;
}

.placed-block.wrong-piece::after {
    content: '❌';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--cell-size) * 0.52);
    z-index: 25;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.9));
    pointer-events: none;
}

@keyframes wrongPulse {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.06); filter: brightness(1.35); }
}

/* Color Classes */
.color-monomino { background: linear-gradient(145deg, var(--piece-blue-light), var(--piece-blue)); }
.color-domino { background: linear-gradient(145deg, var(--piece-cyan-light), var(--piece-cyan)); }
.color-tromino-i { background: linear-gradient(145deg, var(--piece-red-light), var(--piece-red)); }
.color-tromino-l { background: linear-gradient(145deg, var(--piece-green-light), var(--piece-green)); }
.color-tetromino-o { background: linear-gradient(145deg, var(--piece-yellow-light), var(--piece-yellow)); }
.color-tetromino-i { background: linear-gradient(145deg, var(--piece-white-light), var(--piece-white)); }
.color-tetromino-l { background: linear-gradient(145deg, var(--piece-orange-light), var(--piece-orange)); }
.color-tetromino-t { background: linear-gradient(145deg, var(--piece-purple-light), var(--piece-purple)); }
.color-tetromino-z { background: linear-gradient(145deg, var(--piece-pink-light), var(--piece-pink)); }

/* ==========================================================================
   DRAGGING GHOST (FINGER-OFFSET TOUCH PREVIEW)
   ========================================================================== */

.drag-ghost {
    position: fixed;
    pointer-events: none !important;
    z-index: 99999;
    opacity: 0.94;
    filter: drop-shadow(0 14px 28px rgba(0,0,0,0.8));
    touch-action: none;
}

.drag-ghost .poly-cell {
    width: var(--cell-size);
    height: var(--cell-size);
}

.drag-ghost .polyomino-grid {
    gap: var(--grid-gap);
}

/* ==========================================================================
   GAME FOOTER
   ========================================================================== */

.game-footer {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}

.desktop-footer-text { display: block; }
.mobile-footer-text { display: none; }

kbd {
    background: rgba(255,255,255,0.12);
    border: 1px solid var(--border-highlight);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: #fff;
}

/* ==========================================================================
   STATISTICS & SAVES MODALS (MOBILE-OPTIMIZED)
   ========================================================================== */

.modal-lg {
    max-width: 1100px !important;
    width: 94vw !important;
    max-height: 92vh !important;
}

.stats-mode-tabs {
    display: flex;
    gap: 6px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    padding: 6px;
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.btn-stats-mode {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-stats-mode.active, .btn-stats-mode:hover {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.badge-mode {
    font-weight: 800;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
}

.badge-standard { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-train2 { background: rgba(168, 85, 247, 0.15); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.3); }
.badge-train3 { background: rgba(236, 72, 153, 0.15); color: #f472b6; border: 1px solid rgba(236, 72, 153, 0.3); }
.badge-train4 { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }

.modal-desc {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.stats-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
}

.stat-box {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-box-num {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 900;
    color: #fff;
}

.stat-box-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
}

.box-success .stat-box-num { color: var(--success-color); }
.box-danger .stat-box-num { color: var(--danger-color); }
.box-warning .stat-box-num { color: var(--warning-color); }
.box-cpu .stat-box-num { color: var(--cpu-color); }

.history-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.history-header h3 {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-secondary);
}

.history-filters {
    display: flex;
    gap: 4px;
}

.btn-filter {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-filter.active, .btn-filter:hover {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.history-list-wrapper {
    max-height: 380px;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #111319;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    text-align: left;
}

.history-table th {
    background: #1a1c24;
    padding: 10px 12px;
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

.history-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text-secondary);
    white-space: nowrap;
}

.history-table tr:hover {
    background: rgba(255,255,255,0.04);
}

.badge-yes { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 0.72rem; }
.badge-cpu { background: rgba(6, 182, 212, 0.15); color: #38bdf8; border: 1px solid rgba(6, 182, 212, 0.3); padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 0.72rem; }
.badge-no { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 0.72rem; }

.scheme-code {
    font-family: var(--font-mono);
    font-weight: 700;
    color: #fff;
}

.saves-slots-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
}

.slot-card {
    background: #11131a;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

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

.slot-title {
    font-weight: 800;
    font-size: 0.88rem;
    color: #fff;
}

.slot-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.slot-actions {
    display: flex;
    gap: 4px;
}

.modal-footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    padding: 12px;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-highlight);
    border-radius: var(--radius-lg);
    padding: 22px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: modalIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalIn {
    0% { transform: scale(0.88); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: #fff; }

.instructions-content ol {
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.victory-card {
    text-align: center;
    align-items: center;
}

.trophy-icon {
    font-size: 3.5rem;
    margin-bottom: -6px;
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-8px); }
}

.victory-card h2 {
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
}

.win-subtitle {
    color: var(--success-color);
    font-weight: 700;
}

.win-stats {
    display: flex;
    gap: 14px;
    justify-content: center;
    width: 100%;
    margin: 8px 0;
}

.win-stat {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.win-stat .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
}

.win-stat .val {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 800;
    color: #fff;
}

.modal-action-btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 1rem;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   RESPONSIVE MOBILE BREAKPOINTS & SPACE-SAVING OVERHAUL
   ========================================================================== */

@media (max-width: 950px) {
    .play-field {
        grid-template-columns: 1fr;
        justify-items: center;
    }
}

@media (max-width: 768px) {
    body {
        padding: 6px;
    }

    /* Hide piece-actions-bar DIV on mobile view */
    #piece-actions-bar, .piece-actions-bar {
        display: none !important;
    }

    /* Hide "TETRIS PIECES" tray header section on mobile view */
    .tray-header {
        display: none !important;
    }

    /* Hide "ready to roll" solvability status badge on mobile view */
    .board-footer-info {
        display: none !important;
    }

    .game-header {
        flex-direction: column;
        align-items: center;
        padding: 8px 12px;
        gap: 8px;
    }

    .logo-area h1 {
        font-size: 1.2rem;
    }

    .mode-selector-bar {
        width: 100%;
        justify-content: center;
    }

    .mode-label {
        display: none;
    }

    .btn-mode {
        flex: 1;
        padding: 5px 6px;
        font-size: 0.75rem;
        text-align: center;
    }

    .stats-bar {
        width: 100%;
        justify-content: space-around;
    }

    .stat-card {
        flex: 1;
        min-width: 0;
        padding: 4px 6px;
    }

    .controls-bar {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .controls-bar .btn {
        width: 100%;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .controls-bar #btn-roll {
        grid-column: span 2;
    }

    .desktop-shortcut-guide { display: none; }
    .mobile-shortcut-guide { display: inline; }

    .desktop-footer-text { display: none; }
    .mobile-footer-text { display: block; }

    /* Pieces Tray horizontal-friendly scrollable layout */
    .pieces-tray {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
        max-height: 360px;
    }

    .piece-item {
        min-height: 96px;
        padding: 6px 4px 4px 4px;
    }

    .poly-cell {
        width: 20px;
        height: 20px;
    }

    /* Stats Modal Mobile Optimization */
    .modal-card.modal-lg {
        width: 98vw !important;
        max-width: 98vw !important;
        padding: 14px 10px !important;
        max-height: 94vh !important;
        gap: 10px !important;
    }

    .modal-card h2 {
        font-size: 1.1rem !important;
        padding-right: 28px;
    }

    .stats-mode-tabs {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        flex-wrap: nowrap;
        padding: 4px;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .btn-stats-mode {
        flex: 0 0 auto;
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .stats-overview-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .stat-box {
        padding: 6px 4px;
    }

    .stat-box-num {
        font-size: 1.1rem;
    }

    .stat-box-label {
        font-size: 0.62rem;
    }

    .history-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .history-header h3 {
        font-size: 0.82rem;
    }

    .history-filters {
        width: 100%;
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        gap: 4px;
    }

    .btn-filter {
        flex: 1;
        text-align: center;
        padding: 6px 6px;
        font-size: 0.72rem;
    }

    .history-list-wrapper {
        max-height: 280px;
    }

    .history-table th, .history-table td {
        padding: 6px 8px;
        font-size: 0.72rem;
    }

    .modal-footer-actions {
        flex-direction: column-reverse;
        gap: 8px;
        width: 100%;
    }

    .modal-footer-actions .btn {
        width: 100%;
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .app-container {
        gap: 8px;
    }

    .board-container {
        padding: 4px;
        border-width: 3px;
    }

    .coord-spacer, .coord-col {
        width: 14px;
        font-size: 0.72rem;
    }

    .coord-row span, .coord-col span {
        font-size: 0.72rem;
    }

    .stats-overview-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
