/* ========================================
   BLOKIT - Complete Styles
   ======================================== */

:root {
    /* Player Colors */
    --blue: #2563eb;
    --blue-light: #3b82f6;
    --blue-glow: rgba(37, 99, 235, 0.5);
    
    --yellow: #ca8a04;
    --yellow-light: #eab308;
    --yellow-glow: rgba(234, 179, 8, 0.5);
    
    --red: #dc2626;
    --red-light: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.5);
    
    --green: #16a34a;
    --green-light: #22c55e;
    --green-glow: rgba(34, 197, 94, 0.5);

    /* UI Colors */
    --bg-dark: #0a0a12;
    --bg-darker: #050508;
    --bg-card: #12121f;
    --bg-card-hover: #1a1a2e;
    --bg-board: #f8fafc;
    --bg-cell: #ffffff;
    --border-cell: #e2e8f0;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #8b5cf6;
    --accent-light: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.4);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: rgba(255, 255, 255, 0.08);

    /* Sizing */
    --cell-size: 24px;
    --board-gap: 1px;
    --piece-cell-size: 14px;
    --preview-cell-size: 20px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* ========================================
   Reset & Base
   ======================================== */

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

html, body {
    height: 100%;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow-x: hidden;
    background-image: 
        radial-gradient(ellipse at 10% 10%, rgba(139, 92, 246, 0.08) 0%, transparent 40%),
        radial-gradient(ellipse at 90% 90%, rgba(37, 99, 235, 0.08) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 50%, rgba(16, 163, 74, 0.03) 0%, transparent 60%);
}

/* ========================================
   App Container & Screens
   ======================================== */

.app-container {
    min-height: 100vh;
}

.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: block;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--blue));
    color: white;
    border: none;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--accent-glow);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn-arrow {
    transition: transform var(--transition-fast);
}

.btn:hover .btn-arrow {
    transform: translateX(4px);
}

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

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   Input Groups
   ======================================== */

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-group input {
    padding: 0.875rem 1rem;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

/* ========================================
   LOGIN SCREEN
   ======================================== */

.screen-login {
    display: none;
    place-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.screen-login.active {
    display: grid;
}

.login-container {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.logo-section {
    margin-bottom: 3rem;
}

.logo-title {
    font-size: 4rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    background: linear-gradient(135deg, var(--blue-light), var(--accent), var(--red-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 80px var(--accent-glow);
    margin-bottom: 0.5rem;
}

.logo-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 2rem;
    margin-bottom: 2rem;
}

.login-card .btn-large {
    width: 100%;
}

.login-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-light);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Login Card Enhancements */
.login-welcome {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.google-signin-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.google-signin-wrapper > div {
    width: 100% !important;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.guest-login {
    margin-bottom: 1rem;
}

.guest-login .btn-large {
    width: 100%;
    margin-top: 0.75rem;
}

.login-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0.5rem;
    line-height: 1.5;
}

.login-note strong {
    color: var(--warning);
}

/* Tutorial options on login */
.tutorial-options {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.btn-tutorial-watch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-tutorial-watch .btn-icon {
    font-size: 0.9rem;
}

.btn-tutorial-read {
    font-size: 0.9rem;
}

@media (max-width: 480px) {
    .tutorial-options {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .tutorial-options .btn {
        width: 100%;
    }
}

/* Header User Section */
.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent);
}

.user-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-weight: 600;
    text-transform: uppercase;
}

.guest-badge {
    background: var(--warning);
    color: #000;
}

/* ========================================
   LOBBY SCREEN
   ======================================== */

.screen-lobby {
    display: none;
    flex-direction: column;
    min-height: 100vh;
}

.screen-lobby.active {
    display: flex;
}

.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
}

.header-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, var(--blue-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
}

.lobby-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.lobby-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
}

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

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Room List */
.room-list {
    padding: 1rem;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.room-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    transform: translateX(4px);
}

.room-item-info {
    flex: 1;
}

.room-item-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.room-item-host {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.room-item-players {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-hint {
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Quick Play Section */
.quick-play-section {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(37, 99, 235, 0.15));
    border: 1px solid var(--accent);
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    text-align: center;
}

.quick-play-section h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.quick-play-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.difficulty-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.btn-difficulty {
    flex: 1;
    max-width: 120px;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 2px solid;
}

.btn-difficulty.easy {
    background: rgba(34, 197, 94, 0.2);
    border-color: var(--green);
    color: var(--green-light);
}

.btn-difficulty.easy:hover {
    background: rgba(34, 197, 94, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px var(--green-glow);
}

.btn-difficulty.medium {
    background: rgba(234, 179, 8, 0.2);
    border-color: var(--yellow);
    color: var(--yellow-light);
}

.btn-difficulty.medium:hover {
    background: rgba(234, 179, 8, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px var(--yellow-glow);
}

.btn-difficulty.hard {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--red);
    color: var(--red-light);
}

.btn-difficulty.hard:hover {
    background: rgba(239, 68, 68, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px var(--red-glow);
}

.btn-difficulty.custom {
    background: rgba(139, 92, 246, 0.2);
    border-color: var(--accent);
    color: var(--accent-light);
}

.btn-difficulty.custom:hover {
    background: rgba(139, 92, 246, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

/* Custom CPU Modal */
.modal-custom-cpu {
    max-width: 420px;
}

.modal-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.cpu-setup-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.cpu-setup-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
}

.cpu-setup-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.cpu-color-dot {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.cpu-color-dot.yellow { background: var(--yellow); }
.cpu-color-dot.red { background: var(--red); }
.cpu-color-dot.green { background: var(--green); }

.cpu-diff-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.4rem 0.75rem;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 100px;
}

.cpu-diff-select:focus {
    outline: none;
    border-color: var(--accent);
}

.preset-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 1.5rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0.5rem;
}

.preset-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: 0.25rem;
}

.btn-tiny {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-tiny:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Leaderboard */
.leaderboard {
    padding: 0.5rem;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

.leaderboard-loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    transition: background var(--transition-fast);
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.leaderboard-item.top-3 {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(37, 99, 235, 0.1));
}

.leaderboard-rank {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    border-radius: 0.5rem;
    background: var(--bg-darker);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.leaderboard-item.top-3 .leaderboard-rank {
    background: linear-gradient(135deg, var(--accent), var(--blue));
    color: white;
}

.leaderboard-item:nth-child(1) .leaderboard-rank { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.leaderboard-item:nth-child(2) .leaderboard-rank { background: linear-gradient(135deg, #9ca3af, #6b7280); }
.leaderboard-item:nth-child(3) .leaderboard-rank { background: linear-gradient(135deg, #d97706, #b45309); }

.leaderboard-name {
    flex: 1;
    font-weight: 500;
}

.leaderboard-stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.leaderboard-wins {
    color: var(--success);
    font-weight: 600;
}

/* ========================================
   WAITING ROOM SCREEN
   ======================================== */

.screen-waiting {
    display: none;
    min-height: 100vh;
    padding: 2rem;
}

.screen-waiting.active {
    display: block;
}

.waiting-container {
    max-width: 800px;
    margin: 0 auto;
}

.waiting-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.btn-back {
    flex-shrink: 0;
}

.room-info {
    flex: 1;
}

.room-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.room-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--accent-light);
    background: var(--bg-card);
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
}

.players-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.player-slot {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    text-align: center;
    transition: all var(--transition-fast);
}

.player-slot.filled {
    border-style: solid;
}

.player-slot.slot-1.filled { border-color: var(--blue); }
.player-slot.slot-2.filled { border-color: var(--yellow); }
.player-slot.slot-3.filled { border-color: var(--red); }
.player-slot.slot-4.filled { border-color: var(--green); }

.player-slot.empty {
    border-style: dashed;
    opacity: 0.5;
}

.slot-indicator {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    margin: 0 auto 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.slot-1 .slot-indicator { background: var(--blue-light); }
.slot-2 .slot-indicator { background: var(--yellow-light); }
.slot-3 .slot-indicator { background: var(--red-light); }
.slot-4 .slot-indicator { background: var(--green-light); }

.slot-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

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

.slot-host-badge {
    display: inline-block;
    font-size: 0.75rem;
    background: var(--accent);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    margin-top: 0.5rem;
}

.slot-cpu-badge {
    display: inline-block;
    font-size: 0.75rem;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    margin-top: 0.5rem;
    margin-left: 0.25rem;
}

.player-slot.cpu-player {
    border-style: dashed;
    opacity: 0.9;
}

.player-slot.cpu-player .slot-indicator {
    animation: robotPulse 2s ease-in-out infinite;
}

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

/* CPU Player Panel Styles */
.player-panel.cpu-player {
    border-style: dashed;
}

.player-panel.cpu-player .player-name {
    color: #a78bfa;
}

.waiting-actions {
    text-align: center;
    margin-bottom: 2rem;
}

.waiting-actions .btn-large {
    min-width: 250px;
}

/* Add CPU Section */
.add-cpu-section {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(99, 102, 241, 0.1));
    border: 1px dashed var(--accent);
    border-radius: 1rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.add-cpu-section h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.cpu-controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.cpu-difficulty-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
}

.cpu-difficulty-select:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-cpu-add {
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid var(--accent);
    color: var(--accent-light);
}

.btn-cpu-add:hover {
    background: rgba(139, 92, 246, 0.4);
}

.btn-cpu-remove {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--red);
    color: var(--red-light);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

.btn-cpu-remove:hover {
    background: rgba(239, 68, 68, 0.4);
}

/* Chat */
.waiting-chat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
}

.chat-messages {
    height: 200px;
    padding: 1rem;
    overflow-y: auto;
}

.chat-message {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.chat-message-author {
    font-weight: 600;
    color: var(--accent-light);
}

.chat-message-text {
    color: var(--text-secondary);
}

.chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--bg-darker);
}

.chat-input-wrapper input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
}

.chat-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ========================================
   GAME SCREEN
   ======================================== */

.screen-game {
    display: none;
    flex-direction: column;
    height: 100vh;
}

.screen-game.active {
    display: flex;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
}

.game-header-left,
.game-header-right {
    width: 120px;
}

.game-header-right {
    text-align: right;
}

.room-code-small {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.game-status {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.5rem 1.5rem;
    background: var(--bg-card);
    border-radius: 2rem;
    border: 1px solid var(--border);
}

.game-status.player-1 { color: var(--blue-light); border-color: var(--blue); }
.game-status.player-2 { color: var(--yellow-light); border-color: var(--yellow); }
.game-status.player-3 { color: var(--red-light); border-color: var(--red); }
.game-status.player-4 { color: var(--green-light); border-color: var(--green); }

.game-main {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1.5rem;
    flex: 1;
    padding: 1rem;
    align-items: start;
    overflow: hidden;
}

/* Sidebars */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.player-panel {
    background: var(--bg-card);
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    transition: all var(--transition-normal);
}

.player-panel.active {
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.08);
}

.player-panel[data-player="1"].active { border-color: var(--blue); box-shadow: 0 0 30px var(--blue-glow); }
.player-panel[data-player="2"].active { border-color: var(--yellow); box-shadow: 0 0 30px var(--yellow-glow); }
.player-panel[data-player="3"].active { border-color: var(--red); box-shadow: 0 0 30px var(--red-glow); }
.player-panel[data-player="4"].active { border-color: var(--green); box-shadow: 0 0 30px var(--green-glow); }

.player-panel.current-player {
    transform: scale(1.02);
}

.player-panel.passed {
    opacity: 0.4;
}

.player-panel.disconnected {
    opacity: 0.5;
    position: relative;
}

.player-panel.disconnected::before {
    content: '⚡ Disconnected';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(234, 179, 8, 0.9);
    color: #000;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 10;
    white-space: nowrap;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.player-indicator {
    width: 1rem;
    height: 1rem;
    border-radius: 0.25rem;
}

.player-blue { background: var(--blue-light); }
.player-yellow { background: var(--yellow-light); }
.player-red { background: var(--red-light); }
.player-green { background: var(--green-light); }

.player-name {
    font-weight: 600;
    flex: 1;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Piece Palette */
.piece-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
}

.piece-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.4rem;
    padding: 0.3rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 2px solid transparent;
}

.piece-item:hover:not(.used) {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.08);
}

.piece-item.selected {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.2);
    box-shadow: 0 0 15px var(--accent-glow);
}

.piece-item.used {
    opacity: 0.15;
    pointer-events: none;
}

.piece-grid {
    display: grid;
    gap: 1px;
}

.piece-cell {
    width: var(--piece-cell-size);
    height: var(--piece-cell-size);
    border-radius: 2px;
}

.piece-cell.filled.player-1 { background: var(--blue-light); }
.piece-cell.filled.player-2 { background: var(--yellow-light); }
.piece-cell.filled.player-3 { background: var(--red-light); }
.piece-cell.filled.player-4 { background: var(--green-light); }

/* Game Board */
.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.board-wrapper {
    position: relative;
    background: var(--bg-board);
    padding: 3px;
    border-radius: 0.5rem;
    box-shadow: 
        0 0 0 1px rgba(255, 255, 255, 0.1),
        0 20px 50px rgba(0, 0, 0, 0.5);
}

.corner-marker {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    z-index: 10;
    opacity: 0.8;
    animation: pulse 2s infinite;
}

.corner-tl { top: -6px; left: -6px; background: var(--blue-light); box-shadow: 0 0 10px var(--blue); }
.corner-tr { top: -6px; right: -6px; background: var(--yellow-light); box-shadow: 0 0 10px var(--yellow); }
.corner-br { bottom: -6px; right: -6px; background: var(--red-light); box-shadow: 0 0 10px var(--red); }
.corner-bl { bottom: -6px; left: -6px; background: var(--green-light); box-shadow: 0 0 10px var(--green); }

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 1; }
}

.game-board {
    display: grid;
    grid-template-columns: repeat(20, var(--cell-size));
    grid-template-rows: repeat(20, var(--cell-size));
    gap: var(--board-gap);
    background: var(--border-cell);
}

.board-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--bg-cell);
    transition: var(--transition-fast);
}

.board-cell.player-1 { background: var(--blue-light); box-shadow: inset 0 -2px 0 var(--blue); }
.board-cell.player-2 { background: var(--yellow-light); box-shadow: inset 0 -2px 0 var(--yellow); }
.board-cell.player-3 { background: var(--red-light); box-shadow: inset 0 -2px 0 var(--red); }
.board-cell.player-4 { background: var(--green-light); box-shadow: inset 0 -2px 0 var(--green); }

.board-cell.preview-valid {
    background: rgba(34, 197, 94, 0.4);
    box-shadow: inset 0 0 0 2px var(--green);
}

.board-cell.preview-invalid {
    background: rgba(239, 68, 68, 0.3);
    box-shadow: inset 0 0 0 2px var(--red);
}

.board-cell.preview-1 { background: rgba(37, 99, 235, 0.6); box-shadow: inset 0 0 0 2px var(--blue); }
.board-cell.preview-2 { background: rgba(234, 179, 8, 0.6); box-shadow: inset 0 0 0 2px var(--yellow); }
.board-cell.preview-3 { background: rgba(239, 68, 68, 0.6); box-shadow: inset 0 0 0 2px var(--red); }
.board-cell.preview-4 { background: rgba(34, 197, 94, 0.6); box-shadow: inset 0 0 0 2px var(--green); }

/* Opponent hover previews - faded/ghosted appearance */
.board-cell.opponent-hover-1 { 
    background: rgba(37, 99, 235, 0.25); 
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.5);
}
.board-cell.opponent-hover-2 { 
    background: rgba(234, 179, 8, 0.25); 
    box-shadow: inset 0 0 0 1px rgba(234, 179, 8, 0.5);
}
.board-cell.opponent-hover-3 { 
    background: rgba(239, 68, 68, 0.25); 
    box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.5);
}
.board-cell.opponent-hover-4 { 
    background: rgba(34, 197, 94, 0.25); 
    box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.5);
}

/* Opponent hover with subtle pulse animation */
.board-cell[class*="opponent-hover-"] {
    animation: opponentHoverPulse 1.5s ease-in-out infinite;
}

@keyframes opponentHoverPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.board-cell.corner-hint {
    animation: cornerHint 1.5s infinite;
}

@keyframes cornerHint {
    0%, 100% { background: var(--bg-cell); }
    50% { background: rgba(139, 92, 246, 0.3); }
}

/* Hint highlighting */
.board-cell.hint-valid {
    background: rgba(34, 197, 94, 0.25) !important;
    border-color: rgba(34, 197, 94, 0.5) !important;
    animation: hintPulse 1s ease-in-out infinite;
}

@keyframes hintPulse {
    0%, 100% { 
        background: rgba(34, 197, 94, 0.2);
        box-shadow: none;
    }
    50% { 
        background: rgba(34, 197, 94, 0.4);
        box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
    }
}

/* Controls */
.controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: 0.75rem;
    border: 1px solid var(--border);
}

.control-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.6rem 0.8rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    font-size: 0.9rem;
}

.control-btn svg {
    width: 20px;
    height: 20px;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn-pass {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--red);
    color: var(--red-light);
}

.control-btn-pass:hover {
    background: rgba(239, 68, 68, 0.3);
}

.control-btn-pass.must-pass {
    animation: pulsePass 1s infinite;
}

@keyframes pulsePass {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.control-btn-hint {
    background: rgba(34, 197, 94, 0.15);
    border-color: var(--green);
    color: var(--green-light);
}

.control-btn-hint:hover {
    background: rgba(34, 197, 94, 0.3);
}

.control-btn-hint.active {
    background: rgba(34, 197, 94, 0.4);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

/* Piece Preview */
.piece-preview {
    position: fixed;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border-radius: 0.75rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.piece-preview.visible {
    display: flex;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.preview-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.preview-grid {
    display: grid;
    gap: 0px;
}

.preview-cell {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    outline: 1px solid rgba(0, 0, 0, 0.3);
}

.preview-cell.filled.player-1 { background: var(--blue-light); box-shadow: 0 0 10px var(--blue-glow); }
.preview-cell.filled.player-2 { background: var(--yellow-light); box-shadow: 0 0 10px var(--yellow-glow); }
.preview-cell.filled.player-3 { background: var(--red-light); box-shadow: 0 0 10px var(--red-glow); }
.preview-cell.filled.player-4 { background: var(--green-light); box-shadow: 0 0 10px var(--green-glow); }

/* ========================================
   MODALS
   ======================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    place-items: center;
    z-index: 1000;
    overflow-y: auto;
    padding: 1rem;
}

.modal-overlay.visible {
    display: grid;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-card);
    border-radius: 1.5rem;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--border);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.3s ease;
}

.modal-small {
    max-width: 400px;
    padding: 2rem;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--blue-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.winner-announcement {
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.winner-name {
    font-weight: 700;
    color: var(--success);
}

.final-scores {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.score-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0.75rem;
    border-left: 4px solid transparent;
}

.score-row.winner {
    background: rgba(34, 197, 94, 0.15);
}

.score-row.player-1 { border-left-color: var(--blue); }
.score-row.player-2 { border-left-color: var(--yellow); }
.score-row.player-3 { border-left-color: var(--red); }
.score-row.player-4 { border-left-color: var(--green); }

.score-row .player-indicator {
    width: 1.25rem;
    height: 1.25rem;
}

.score-row .player-name {
    font-weight: 600;
    flex: 1;
}

.score-row .score-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.2rem;
    font-weight: 600;
}

.score-row.player-1 .score-value { color: var(--blue-light); }
.score-row.player-2 .score-value { color: var(--yellow-light); }
.score-row.player-3 .score-value { color: var(--red-light); }
.score-row.player-4 .score-value { color: var(--green-light); }

.winner-badge {
    font-size: 0.7rem;
    background: var(--success);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-weight: 600;
    text-transform: uppercase;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal-actions .btn {
    min-width: 140px;
}

/* Instructions Modal */
.modal-instructions {
    max-width: 650px;
    max-height: 85vh;
    overflow-y: auto;
}

.instructions-content {
    text-align: left;
    margin: 1.5rem 0;
}

.instruction-section {
    margin-bottom: 1.5rem;
}

.instruction-section h3 {
    color: var(--accent);
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.instruction-section p {
    color: var(--text-secondary);
    line-height: 1.6;
}

.rules-list {
    list-style: none;
    padding: 0;
    counter-reset: rules;
}

.rules-list li {
    position: relative;
    padding-left: 2rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.rules-list li::before {
    counter-increment: rules;
    content: counter(rules);
    position: absolute;
    left: 0;
    width: 1.5rem;
    height: 1.5rem;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.rules-list li strong {
    color: var(--text-primary);
}

.corner-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0.5rem;
}

.corner-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.color-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.color-dot.blue { background: var(--blue); }
.color-dot.yellow { background: var(--yellow); }
.color-dot.red { background: var(--red); }
.color-dot.green { background: var(--green); }

.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0.5rem;
}

.control-item kbd {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    padding: 0.2rem 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.control-item span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.scoring-list,
.tips-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.scoring-list li,
.tips-list li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: var(--text-secondary);
}

.scoring-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
}

.tips-list li::before {
    content: '💡';
    position: absolute;
    left: 0;
    font-size: 0.9rem;
}

.scoring-list li strong {
    color: var(--success);
}

.tips-section {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(37, 99, 235, 0.05));
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.tips-section h3 {
    margin-top: 0;
}

/* Help Button */
.btn-help {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    font-weight: 700;
    font-size: 1rem;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 500;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
    min-width: 280px;
}

.toast.player-1 { border-left: 4px solid var(--blue); }
.toast.player-2 { border-left: 4px solid var(--yellow); }
.toast.player-3 { border-left: 4px solid var(--red); }
.toast.player-4 { border-left: 4px solid var(--green); }
.toast.info { border-left: 4px solid var(--accent); }
.toast.error { border-left: 4px solid var(--error); }

.toast-icon {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.toast.player-1 .toast-icon { background: var(--blue); }
.toast.player-2 .toast-icon { background: var(--yellow); }
.toast.player-3 .toast-icon { background: var(--red); }
.toast.player-4 .toast-icon { background: var(--green); }
.toast.info .toast-icon { background: var(--accent); }
.toast.error .toast-icon { background: var(--error); }

.toast-message {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.toast-message strong {
    font-weight: 600;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 1400px) {
    :root {
        --cell-size: 20px;
        --piece-cell-size: 12px;
    }
}

@media (max-width: 1200px) {
    .lobby-main {
        grid-template-columns: 1fr;
    }

    .leaderboard-section {
        display: none;
    }
}

@media (max-width: 1100px) {
    .game-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

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

    .sidebar-left { order: 2; }
    .board-section { order: 1; }
    .sidebar-right { order: 3; }

    .player-panel {
        flex: 1;
        max-width: 280px;
        min-width: 200px;
    }
}

@media (max-width: 600px) {
    :root {
        --cell-size: 16px;
        --piece-cell-size: 10px;
    }

    .logo-title {
        font-size: 2.5rem;
    }

    .players-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        flex-direction: column;
    }

    .player-panel {
        max-width: none;
    }

    .piece-preview {
        bottom: 0.5rem;
        padding: 0.4rem 0.75rem;
    }

    .preview-cell {
        width: 10px;
        height: 10px;
    }
}

/* ========================================
   MOBILE-SPECIFIC STYLES
   ======================================== */

/* Mobile body adjustments */
body.is-mobile {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior: none;
}

/* Prevent double-tap zoom on interactive elements */
body.is-mobile .btn,
body.is-mobile .control-btn,
body.is-mobile .piece-item,
body.is-mobile .room-item,
body.is-mobile .avatar-option,
body.is-mobile .leaderboard-item {
    touch-action: manipulation;
}

/* Prevent text selection on game elements */
body.is-mobile .game-board,
body.is-mobile .piece-palette,
body.is-mobile .controls,
body.is-mobile .player-panel {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Mobile viewport adjustments */
@media (max-width: 768px) {
    :root {
        --cell-size: calc(min(4.5vw, 18px));
        --piece-cell-size: 9px;
        --preview-cell-size: 14px;
    }

    /* Login Screen Mobile */
    .screen-login {
        padding: 1rem;
    }

    .logo-title {
        font-size: 2rem;
        letter-spacing: 0.1em;
    }

    .logo-subtitle {
        font-size: 0.9rem;
    }

    .login-card {
        padding: 1.5rem;
    }

    .login-stats {
        gap: 1.5rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    /* Lobby Mobile */
    .lobby-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-title {
        font-size: 1.2rem;
    }

    .header-user {
        gap: 0.5rem;
    }

    .user-name {
        font-size: 0.9rem;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lobby-main {
        padding: 1rem;
        gap: 1rem;
    }

    .section-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .section-header h2 {
        font-size: 1rem;
    }

    /* Quick Play Section Mobile */
    .quick-play-section {
        padding: 1rem;
    }

    .quick-play-section h3 {
        font-size: 1rem;
    }

    .difficulty-buttons {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .btn-difficulty {
        padding: 0.6rem 0.75rem;
        font-size: 0.85rem;
        min-width: 70px;
    }

    /* Room List Mobile */
    .room-list {
        padding: 0.75rem;
        max-height: calc(100vh - 320px);
    }

    .room-item {
        padding: 0.75rem 1rem;
    }

    /* Waiting Room Mobile */
    .screen-waiting {
        padding: 1rem;
    }

    .waiting-header {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .room-name {
        font-size: 1.2rem;
    }

    .waiting-actions .btn-large {
        min-width: auto;
        width: 100%;
        max-width: 300px;
    }

    .add-cpu-section {
        padding: 1rem;
    }

    .cpu-controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Game Screen Mobile */
    .screen-game {
        height: 100dvh; /* Use dynamic viewport height for mobile */
    }

    .game-header {
        padding: 0.5rem 0.75rem;
    }

    .game-header-left,
    .game-header-right {
        width: auto;
        flex-shrink: 0;
    }

    .game-status {
        font-size: 0.9rem;
        padding: 0.4rem 1rem;
    }

    .game-main {
        padding: 0.5rem;
        gap: 0.5rem;
        overflow-y: auto;
        align-items: center;
    }

    /* Board Section Mobile */
    .board-section {
        gap: 0.5rem;
    }

    .board-wrapper {
        padding: 2px;
        touch-action: none; /* Prevent browser handling of touch */
    }

    .corner-marker {
        width: 8px;
        height: 8px;
    }

    .corner-tl { top: -4px; left: -4px; }
    .corner-tr { top: -4px; right: -4px; }
    .corner-br { bottom: -4px; right: -4px; }
    .corner-bl { bottom: -4px; left: -4px; }

    /* Controls Mobile */
    .controls {
        padding: 0.5rem;
        gap: 0.35rem;
    }

    .control-btn {
        padding: 0.5rem 0.7rem;
        min-width: 44px; /* Touch-friendly minimum */
        min-height: 44px;
    }

    .control-btn svg {
        width: 18px;
        height: 18px;
    }

    .control-btn-pass {
        font-size: 0.8rem;
    }

    /* Player Panels Mobile */
    .sidebar {
        width: 100%;
        padding: 0 0.25rem;
    }

    .player-panel {
        padding: 0.5rem;
        min-width: 0;
        max-width: none;
        flex: 1 1 calc(50% - 0.25rem);
    }

    .player-header {
        margin-bottom: 0.4rem;
        padding-bottom: 0.4rem;
        gap: 0.4rem;
    }

    .player-indicator {
        width: 0.75rem;
        height: 0.75rem;
    }

    .player-name {
        font-size: 0.8rem;
    }

    .player-score {
        font-size: 0.85rem;
    }

    /* Piece Palette Mobile */
    .piece-palette {
        gap: 0.25rem;
        max-height: 120px;
        overflow-y: auto;
        padding: 0.25rem;
    }

    .piece-item {
        padding: 0.2rem;
        border-radius: 0.3rem;
        min-width: 28px;
        min-height: 28px;
    }

    .piece-cell {
        width: var(--piece-cell-size);
        height: var(--piece-cell-size);
    }

    /* Piece Preview Mobile */
    .piece-preview {
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        border-radius: 0.75rem 0.75rem 0 0;
        padding: 0.5rem 1rem;
        justify-content: center;
        background: var(--bg-darker);
        box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.5);
    }

    .preview-title {
        font-size: 0.65rem;
    }

    .preview-cell {
        width: 12px;
        height: 12px;
    }

    /* Toast Mobile */
    .toast-container {
        top: auto;
        bottom: 80px;
        right: 0.75rem;
        left: 0.75rem;
    }

    .toast {
        min-width: auto;
        width: 100%;
    }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 380px) {
    :root {
        --cell-size: calc(min(4vw, 15px));
        --piece-cell-size: 7px;
    }

    .logo-title {
        font-size: 1.75rem;
    }

    .game-status {
        font-size: 0.8rem;
        padding: 0.35rem 0.75rem;
    }

    .control-btn {
        padding: 0.4rem 0.5rem;
        min-width: 40px;
        min-height: 40px;
    }

    .control-btn svg {
        width: 16px;
        height: 16px;
    }

    .player-panel {
        padding: 0.4rem;
    }

    .player-name {
        font-size: 0.75rem;
    }

    .piece-palette {
        max-height: 100px;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --cell-size: calc(min(2.5vh, 14px));
        --piece-cell-size: 8px;
    }

    .screen-game {
        height: 100dvh;
    }

    .game-header {
        padding: 0.25rem 0.5rem;
    }

    .game-status {
        font-size: 0.8rem;
        padding: 0.25rem 0.75rem;
    }

    .game-main {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        align-items: flex-start;
        padding: 0.25rem;
        gap: 0.5rem;
    }

    .sidebar {
        flex-direction: column;
        max-width: 150px;
        min-width: 120px;
    }

    .sidebar-left { order: 1; }
    .board-section { order: 2; }
    .sidebar-right { order: 3; }

    .player-panel {
        flex: none;
        max-width: none;
        width: 100%;
    }

    .piece-palette {
        max-height: 80px;
    }

    .board-wrapper {
        max-height: calc(100dvh - 80px);
    }

    .controls {
        position: fixed;
        bottom: 0.25rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 50;
    }

    .piece-preview {
        display: none;
    }
}

/* Tablet portrait */
@media (min-width: 601px) and (max-width: 900px) {
    :root {
        --cell-size: 22px;
        --piece-cell-size: 11px;
    }

    .game-main {
        grid-template-columns: 1fr;
    }

    .sidebar {
        flex-direction: row;
    }

    .player-panel {
        flex: 1;
        max-width: 220px;
    }
}

/* Touch-friendly tap targets */
body.is-mobile .btn {
    min-height: 44px;
    min-width: 44px;
}

body.is-mobile .btn-small {
    min-height: 36px;
    min-width: 36px;
}

body.is-mobile .room-item {
    min-height: 56px;
}

body.is-mobile .leaderboard-item {
    min-height: 48px;
    padding: 0.5rem 0.75rem;
}

/* Improve touch feedback */
body.is-mobile .btn:active,
body.is-mobile .control-btn:active,
body.is-mobile .piece-item:active:not(.used),
body.is-mobile .room-item:active {
    transform: scale(0.97);
    opacity: 0.9;
}

body.is-mobile .board-cell {
    transition: none; /* Remove transition for snappier touch response */
}

/* Scrollbar styling for mobile */
body.is-mobile .piece-palette::-webkit-scrollbar,
body.is-mobile .room-list::-webkit-scrollbar,
body.is-mobile .chat-messages::-webkit-scrollbar {
    width: 4px;
}

body.is-mobile .piece-palette::-webkit-scrollbar-thumb,
body.is-mobile .room-list::-webkit-scrollbar-thumb,
body.is-mobile .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Safe area insets for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body.is-mobile .piece-preview {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }
    
    body.is-mobile .toast-container {
        bottom: calc(80px + env(safe-area-inset-bottom));
    }
    
    body.is-mobile .screen-game {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ========================================
   AVATAR BUTTON & DISPLAY
   ======================================== */

.avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--blue));
    border: 2px solid var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    padding: 0;
}

.avatar-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px var(--accent-glow);
}

.avatar-emoji {
    font-size: 1.4rem;
    line-height: 1;
}

/* ========================================
   PROFILE MODAL
   ======================================== */

.modal-profile {
    max-width: 600px;
    padding: 2rem;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.profile-header {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.profile-avatar-display {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--blue));
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--accent);
    box-shadow: 0 0 30px var(--accent-glow);
}

.profile-avatar-emoji {
    font-size: 3.5rem;
    line-height: 1;
}

.profile-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.profile-name-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.profile-name {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.btn-edit-name {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
    padding: 0.25rem;
}

.btn-edit-name:hover {
    opacity: 1;
}

.profile-name-edit {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.profile-name-edit input {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    width: 200px;
}

.profile-name-edit input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-save-name {
    background: var(--success);
    color: white;
}

.btn-cancel-name {
    background: var(--bg-elevated);
}

.profile-rank {
    margin-bottom: 0.5rem;
}

.rank-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--accent), var(--blue));
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.profile-member-since {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Quick Stats */
.profile-quick-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.quick-stat {
    background: var(--bg-darker);
    border-radius: 1rem;
    padding: 1rem;
    text-align: center;
    border: 1px solid var(--border);
}

.quick-stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-light);
    margin-bottom: 0.25rem;
}

.quick-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Stats Grid */
.profile-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-card {
    background: var(--bg-darker);
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
}

.stats-card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span:first-child {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.stat-row .stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.stat-row .stat-value.positive {
    color: var(--success);
}

.stat-row .stat-value.negative {
    color: var(--error);
}

.stat-row .stat-value.streak {
    color: var(--warning);
}

/* Score Distribution */
.score-distribution {
    background: var(--bg-darker);
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.score-distribution h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.distribution-bars {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 100px;
    gap: 1rem;
}

.dist-bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    height: 100%;
}

.dist-bar {
    width: 100%;
    max-width: 50px;
    border-radius: 0.5rem 0.5rem 0 0;
    transition: height 0.5s ease;
    min-height: 4px;
}

.dist-bar.perfect {
    background: linear-gradient(to top, #22c55e, #4ade80);
}

.dist-bar.positive {
    background: linear-gradient(to top, #3b82f6, #60a5fa);
}

.dist-bar.close {
    background: linear-gradient(to top, #f59e0b, #fbbf24);
}

.dist-bar.tough {
    background: linear-gradient(to top, #ef4444, #f87171);
}

.dist-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    text-align: center;
}

/* Recent Games */
.recent-games {
    background: var(--bg-darker);
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
}

.recent-games h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.recent-games-list {
    max-height: 150px;
    overflow-y: auto;
}

.recent-game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
}

.recent-game-item.win {
    border-left: 3px solid var(--success);
}

.recent-game-item.loss {
    border-left: 3px solid var(--error);
}

.recent-game-result {
    font-weight: 600;
    font-size: 0.85rem;
}

.recent-game-item.win .recent-game-result {
    color: var(--success);
}

.recent-game-item.loss .recent-game-result {
    color: var(--error);
}

.recent-game-score {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.recent-game-pieces {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.no-games {
    color: var(--text-muted);
    text-align: center;
    padding: 1rem;
}

/* ========================================
   AVATAR PICKER MODAL
   ======================================== */

.modal-avatar-picker {
    max-width: 500px;
}

.modal-avatar-picker {
    max-width: 550px;
    max-height: 80vh;
}

.avatar-picker-content {
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.avatar-category {
    margin-bottom: 1.25rem;
}

.avatar-category-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
    padding-left: 0.25rem;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.avatar-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 0.75rem;
    background: var(--bg-darker);
    border: 2px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all var(--transition-fast);
}

.avatar-option:hover {
    border-color: var(--accent);
    transform: scale(1.15);
    background: rgba(139, 92, 246, 0.2);
    z-index: 1;
}

.avatar-option.selected {
    border-color: var(--accent);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(37, 99, 235, 0.3));
    box-shadow: 0 0 15px var(--accent-glow);
}

/* ========================================
   PROFILE RESPONSIVE
   ======================================== */

@media (max-width: 600px) {
    .profile-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .profile-quick-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .profile-stats-grid {
        grid-template-columns: 1fr;
    }

    .avatar-grid {
        grid-template-columns: repeat(6, 1fr);
    }

    .profile-name-edit {
        flex-wrap: wrap;
    }

    .profile-name-edit input {
        width: 100%;
    }
}

/* ========================================
   MODAL MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .modal-overlay {
        padding: 0.5rem;
        align-items: flex-end;
    }

    .modal {
        max-width: none;
        width: 100%;
        max-height: 90vh;
        border-radius: 1.5rem 1.5rem 0 0;
        padding: 1.5rem;
        margin-bottom: 0;
        overflow-y: auto;
    }

    .modal-small {
        padding: 1.25rem;
    }

    .modal-title {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }

    .modal-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .modal-actions .btn {
        width: 100%;
        min-width: auto;
    }

    /* Profile Modal Mobile */
    .modal-profile {
        padding: 1.25rem;
        max-height: 85vh;
    }

    .modal-close {
        top: 0.75rem;
        right: 0.75rem;
    }

    .profile-avatar-display {
        width: 80px;
        height: 80px;
    }

    .profile-avatar-emoji {
        font-size: 2.5rem;
    }

    .profile-name {
        font-size: 1.4rem;
    }

    .profile-quick-stats {
        gap: 0.5rem;
    }

    .quick-stat {
        padding: 0.75rem 0.5rem;
    }

    .quick-stat-value {
        font-size: 1.4rem;
    }

    .quick-stat-label {
        font-size: 0.7rem;
    }

    .stats-card {
        padding: 0.75rem;
    }

    .stats-card h3 {
        font-size: 0.9rem;
    }

    .stat-row {
        padding: 0.35rem 0;
    }

    .stat-row span:first-child {
        font-size: 0.8rem;
    }

    /* Avatar Picker Mobile */
    .modal-avatar-picker {
        max-height: 80vh;
    }

    .avatar-picker-content {
        max-height: 50vh;
    }

    .avatar-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.4rem;
    }

    .avatar-option {
        font-size: 1.3rem;
        border-radius: 0.5rem;
    }

    /* Instructions Modal Mobile */
    .modal-instructions {
        max-height: 85vh;
    }

    .instructions-content {
        margin: 1rem 0;
    }

    .instruction-section {
        margin-bottom: 1rem;
    }

    .instruction-section h3 {
        font-size: 1rem;
    }

    .rules-list li {
        padding-left: 1.75rem;
        margin-bottom: 0.75rem;
        font-size: 0.9rem;
    }

    .rules-list li::before {
        width: 1.25rem;
        height: 1.25rem;
        font-size: 0.7rem;
    }

    .corner-legend {
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .corner-item {
        font-size: 0.75rem;
    }

    .controls-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .control-item {
        padding: 0.4rem 0.6rem;
    }

    .control-item kbd {
        font-size: 0.7rem;
        padding: 0.15rem 0.35rem;
    }

    .control-item span {
        font-size: 0.8rem;
    }

    .tips-section {
        padding: 0.75rem;
    }

    /* Game Over Modal Mobile */
    .winner-announcement {
        font-size: 1.1rem;
    }

    .final-scores {
        margin-bottom: 1.5rem;
    }

    .score-row {
        padding: 0.6rem 0.75rem;
        gap: 0.75rem;
    }

    .score-row .player-name {
        font-size: 0.9rem;
    }

    .score-row .score-value {
        font-size: 1rem;
    }

    /* Custom CPU Modal Mobile */
    .cpu-setup-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.6rem 0.75rem;
    }

    .cpu-diff-select {
        width: 100%;
    }

    .preset-buttons {
        flex-wrap: wrap;
        gap: 0.35rem;
    }
}

/* Input focus states for mobile */
@media (max-width: 768px) {
    .input-group input:focus {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    #chat-input:focus,
    #guest-name:focus,
    #room-name-input:focus,
    #profile-name-input:focus {
        font-size: 16px;
    }
}

/* Ensure inputs don't zoom on iOS */
body.is-mobile input,
body.is-mobile select,
body.is-mobile textarea {
    font-size: 16px;
}

/* ========================================
   TUTORIAL MODAL
   ======================================== */

.modal-tutorial {
    max-width: 500px;
    padding: 0;
    overflow: visible;
    background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-darker) 100%);
    margin: 2rem auto;
}

.tutorial-container {
    padding: 2rem;
    padding-top: 1.5rem;
}

/* Progress dots */
.tutorial-progress {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    padding: 0.5rem 0;
}

.progress-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    cursor: pointer;
    border: 2px solid transparent;
    flex-shrink: 0;
}

.progress-dot:hover {
    background: rgba(255, 255, 255, 0.4);
}

.progress-dot.active {
    background: var(--accent);
    border-color: var(--accent-light);
    transform: scale(1.3);
    box-shadow: 0 0 12px var(--accent-glow);
}

.progress-dot.completed {
    background: var(--success);
    border-color: var(--success);
}

/* Tutorial steps */
.tutorial-steps {
    position: relative;
    min-height: 340px;
}

.tutorial-step {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    opacity: 0;
    transform: translateX(30px);
    transition: all 0.4s ease;
    pointer-events: none;
}

.tutorial-step.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.tutorial-step.exiting-left {
    opacity: 0;
    transform: translateX(-30px);
}

.tutorial-step.entering-right {
    transform: translateX(30px);
}

.tutorial-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tutorial-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

.tutorial-text strong {
    color: var(--accent-light);
}

/* Tutorial animations container */
.tutorial-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/* Tutorial board base */
.tut-board {
    position: relative;
    background: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
}

/* Step 1: Objective animation */
.tut-board-small {
    width: 220px;
    height: 160px;
    position: relative;
}

.tut-piece {
    position: absolute;
    border-radius: 4px;
}

.tut-piece-blue { background: var(--blue-light); box-shadow: 0 2px 10px var(--blue-glow); }
.tut-piece-yellow { background: var(--yellow-light); box-shadow: 0 2px 10px var(--yellow-glow); }
.tut-piece-red { background: var(--red-light); box-shadow: 0 2px 10px var(--red-glow); }
.tut-piece-green { background: var(--green-light); box-shadow: 0 2px 10px var(--green-glow); }

/* Piece shapes for step 1 */
.piece-L {
    width: 30px;
    height: 45px;
    clip-path: polygon(0 0, 66% 0, 66% 66%, 100% 66%, 100% 100%, 0 100%);
}

.piece-T {
    width: 45px;
    height: 30px;
    clip-path: polygon(33% 0, 66% 0, 66% 50%, 100% 50%, 100% 100%, 0 100%, 0 50%, 33% 50%);
}

.piece-Z {
    width: 45px;
    height: 30px;
    clip-path: polygon(0 0, 66% 0, 66% 50%, 100% 50%, 100% 100%, 33% 100%, 33% 50%, 0 50%);
}

.piece-I {
    width: 15px;
    height: 60px;
    border-radius: 3px;
}

/* Step 1 animation - Position pieces in each quadrant */
#tut1-piece1 { 
    top: 20px;
    left: 25px;
    animation: tut1-float 3s ease-in-out infinite; 
}
#tut1-piece2 { 
    top: 25px;
    right: 30px;
    animation: tut1-float 3s ease-in-out 0.5s infinite; 
}
#tut1-piece3 { 
    bottom: 25px;
    right: 35px;
    animation: tut1-float 3s ease-in-out 1s infinite; 
}
#tut1-piece4 { 
    bottom: 20px;
    left: 50px;
    animation: tut1-float 3s ease-in-out 1.5s infinite; 
}

@keyframes tut1-float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(3deg); }
}

.tut-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

/* Step 2: Corners */
.tut-board-corners {
    width: 200px;
    height: 200px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    padding: 0.5rem;
}

.tut-corner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tut-corner-tl { align-items: flex-start; justify-content: flex-start; }
.tut-corner-tr { align-items: flex-end; justify-content: flex-start; }
.tut-corner-bl { align-items: flex-start; justify-content: flex-end; }
.tut-corner-br { align-items: flex-end; justify-content: flex-end; }

.corner-marker-tut {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    animation: cornerPulse 2s ease-in-out infinite;
}

.corner-marker-tut.blue { background: var(--blue-light); box-shadow: 0 0 15px var(--blue-glow); }
.corner-marker-tut.yellow { background: var(--yellow-light); box-shadow: 0 0 15px var(--yellow-glow); }
.corner-marker-tut.red { background: var(--red-light); box-shadow: 0 0 15px var(--red-glow); }
.corner-marker-tut.green { background: var(--green-light); box-shadow: 0 0 15px var(--green-glow); }

@keyframes cornerPulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 1; }
}

.corner-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.piece-corner-demo {
    position: absolute;
    width: 45px;
    height: 30px;
    background: var(--blue-light);
    box-shadow: 0 2px 15px var(--blue-glow);
    clip-path: polygon(0 0, 66% 0, 66% 50%, 100% 50%, 100% 100%, 0 100%);
    animation: tut2-place 3s ease-in-out infinite;
}

@keyframes tut2-place {
    0% { top: 50%; left: 50%; transform: translate(-50%, -50%) scale(1.2); opacity: 0.5; }
    30% { top: 50%; left: 50%; transform: translate(-50%, -50%) scale(1.1); opacity: 0.8; }
    50%, 100% { top: 8px; left: 8px; transform: translate(0, 0) scale(1); opacity: 1; }
}

/* Step 3: Corner rule */
.tut-board-rule {
    width: 220px;
    padding: 1rem;
}

.tut-grid-demo {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 4px;
    justify-content: center;
    margin-bottom: 1rem;
}

.tut-placed-piece {
    grid-column: 2;
    grid-row: 2;
    background: var(--blue-light);
    border-radius: 4px;
    box-shadow: inset 0 -2px 0 var(--blue);
}

.tut-valid-zone, .tut-invalid-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 700;
}

.tut-valid-zone {
    background: rgba(34, 197, 94, 0.3);
    border: 2px dashed var(--green);
    color: var(--green-light);
    animation: validPulse 2s ease-in-out infinite;
}

.zone-1 { grid-column: 1; grid-row: 1; }
.zone-2 { grid-column: 3; grid-row: 1; }
.zone-3 { grid-column: 1; grid-row: 3; }
.zone-4 { grid-column: 3; grid-row: 3; }

@keyframes validPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.tut-invalid-zone {
    background: rgba(239, 68, 68, 0.2);
    border: 2px dashed var(--red);
    color: var(--red-light);
    opacity: 0.7;
}

.edge-1 { grid-column: 2; grid-row: 1; }
.edge-2 { grid-column: 1; grid-row: 2; }
.edge-3 { grid-column: 3; grid-row: 2; }
.edge-4 { grid-column: 2; grid-row: 3; }

.tut-legend {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    font-size: 0.8rem;
}

.legend-valid { color: var(--green-light); }
.legend-invalid { color: var(--red-light); }

/* Step 4: Placement demo */
.tut-board-demo {
    width: 220px;
    height: 180px;
    position: relative;
}

.tut-mini-grid {
    display: grid;
    grid-template-columns: repeat(8, 24px);
    grid-template-rows: repeat(6, 24px);
    gap: 1px;
    background: var(--border-cell);
    border-radius: 4px;
    overflow: hidden;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.tut-mini-cell {
    background: rgba(255, 255, 255, 0.9);
    transition: background 0.3s ease;
}

.tut-mini-cell.placed-blue {
    background: var(--blue-light);
    box-shadow: inset 0 -2px 0 var(--blue);
}

.tut-piece-moving {
    position: absolute;
    width: 48px;
    height: 48px;
    background: var(--blue-light);
    border-radius: 4px;
    box-shadow: 0 4px 20px var(--blue-glow);
    clip-path: polygon(0 0, 100% 0, 100% 50%, 50% 50%, 50% 100%, 0 100%);
    animation: tut4-move 4s ease-in-out infinite;
    opacity: 0.9;
}

@keyframes tut4-move {
    0% { top: -20px; left: 50%; transform: translate(-50%, 0) rotate(0deg); opacity: 0; }
    20% { top: 30px; left: 30%; transform: translate(-50%, 0) rotate(0deg); opacity: 1; }
    40% { top: 30px; left: 30%; transform: translate(-50%, 0) rotate(90deg); opacity: 1; }
    60% { top: 50px; left: 50%; transform: translate(-50%, -50%) rotate(90deg); opacity: 1; }
    80%, 100% { top: 50px; left: 50%; transform: translate(-50%, -50%) rotate(90deg) scale(0.95); opacity: 0.5; }
}

.tut-controls-demo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.demo-key {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-primary);
}

/* Step 5: Tips */
.tut-tips-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    width: 100%;
    max-width: 300px;
}

.tut-tip {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    animation: tipFadeIn 0.5s ease forwards;
    opacity: 0;
}

.tut-tip:nth-child(1) { animation-delay: 0.1s; }
.tut-tip:nth-child(2) { animation-delay: 0.2s; }
.tut-tip:nth-child(3) { animation-delay: 0.3s; }
.tut-tip:nth-child(4) { animation-delay: 0.4s; }

@keyframes tipFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tip-icon {
    font-size: 1.5rem;
}

.tip-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.btn-start-playing {
    margin-top: 1.5rem;
    width: 100%;
}

/* Tutorial navigation */
.tutorial-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.tut-nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tut-nav-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: var(--accent);
}

.tut-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tut-nav-btn svg {
    width: 18px;
    height: 18px;
}

.tut-next {
    background: linear-gradient(135deg, var(--accent), var(--blue));
    border: none;
    color: white;
}

.tut-next:hover:not(:disabled) {
    box-shadow: 0 4px 15px var(--accent-glow);
    transform: translateY(-1px);
}

/* Tutorial modal mobile */
@media (max-width: 768px) {
    .modal-tutorial {
        max-height: 90vh;
    }

    .tutorial-container {
        padding: 1.25rem;
        padding-top: 0.75rem;
    }

    .tutorial-steps {
        min-height: 320px;
    }

    .tutorial-title {
        font-size: 1.25rem;
    }

    .tutorial-text {
        font-size: 0.9rem;
    }

    .tut-board-small {
        width: 180px;
        height: 130px;
    }

    .tut-board-corners {
        width: 180px;
        height: 180px;
    }

    .tut-grid-demo {
        grid-template-columns: repeat(3, 35px);
        grid-template-rows: repeat(3, 35px);
    }

    .tut-mini-grid {
        grid-template-columns: repeat(8, 20px);
        grid-template-rows: repeat(6, 20px);
    }

    .tut-tips-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .tut-tip {
        padding: 0.6rem;
    }

    .tip-icon {
        font-size: 1.25rem;
    }

    .tip-text {
        font-size: 0.8rem;
    }

    .tut-nav-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}
