/* ============================================
   CSS Variables
   ============================================ */
:root {
    /* Game Colors */
    --color-red: #E74C3C;
    --color-red-dark: #C0392B;
    --color-yellow: #F1C40F;
    --color-yellow-dark: #D4AC0D;
    --color-board: #3498DB;
    --color-board-dark: #2980B9;

    /* UI Colors */
    --color-bg: #1A1A2E;
    --color-surface: #16213E;
    --color-surface-light: #1F3460;
    --color-text: #EAEAEA;
    --color-text-muted: #888;

    /* States */
    --color-success: #2ECC71;
    --color-error: #E74C3C;

    /* Sizing */
    --cell-size: 48px;
    --board-gap: 4px;
    --transition-speed: 0.3s;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    overflow: hidden;
}

/* ============================================
   Screens
   ============================================ */
.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.screen.active {
    display: flex;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 400px;
    width: 100%;
}

/* ============================================
   Logo & Branding
   ============================================ */
.logo {
    text-align: center;
    margin-bottom: 20px;
}

.logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 10px;
}

.logo h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
}

.subtitle {
    font-size: 18px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 24px;
    font-size: 18px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--color-board);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-board-dark);
}

.btn-secondary {
    background: var(--color-surface-light);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface);
}

.btn-text {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-text:hover {
    color: var(--color-text);
}

.btn-icon {
    font-size: 20px;
}

/* ============================================
   Form Elements
   ============================================ */
input[type="text"] {
    width: 100%;
    padding: 16px;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 8px;
    background: var(--color-surface);
    border: 2px solid var(--color-surface-light);
    border-radius: 12px;
    color: var(--color-text);
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: var(--color-board);
}

input[type="text"]::placeholder {
    letter-spacing: normal;
    color: var(--color-text-muted);
}

.input-name {
    font-size: 16px;
    text-transform: none !important;
    letter-spacing: normal;
    padding: 12px 16px;
}

.input-name::placeholder {
    text-transform: none;
}

.divider {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 16px;
    color: var(--color-text-muted);
}

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

.join-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

/* ============================================
   Waiting Screen
   ============================================ */
.room-code {
    font-size: 48px;
    font-weight: 700;
    letter-spacing: 12px;
    color: var(--color-board);
    background: var(--color-surface);
    padding: 20px 32px;
    border-radius: 16px;
}

.waiting-text {
    color: var(--color-text-muted);
    font-size: 16px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-surface-light);
    border-top-color: var(--color-board);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Game Screen
   ============================================ */
#screen-game {
    justify-content: flex-start;
    padding-top: 20px;
    gap: 20px;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 400px;
    padding: 0 10px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

.player-chip {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.player-chip.red {
    background: var(--color-red);
    box-shadow: inset 0 -3px 0 var(--color-red-dark);
}

.player-chip.yellow {
    background: var(--color-yellow);
    box-shadow: inset 0 -3px 0 var(--color-yellow-dark);
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-surface);
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.turn-chip {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    transition: background 0.3s;
}

.turn-indicator.red .turn-chip {
    background: var(--color-red);
}

.turn-indicator.yellow .turn-chip {
    background: var(--color-yellow);
}

.turn-indicator.waiting .turn-text {
    color: var(--color-text-muted);
}

/* ============================================
   Board
   ============================================ */
.board-container {
    position: relative;
    display: flex;
    justify-content: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(7, var(--cell-size));
    grid-template-rows: repeat(6, var(--cell-size));
    gap: var(--board-gap);
    background: var(--color-board);
    padding: var(--board-gap);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--color-bg);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    transition: background 0.1s;
}

.cell::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    transition: background 0.3s, transform 0.3s;
}

.cell.red::after {
    background: var(--color-red);
    box-shadow: inset 0 -4px 0 var(--color-red-dark);
}

.cell.yellow::after {
    background: var(--color-yellow);
    box-shadow: inset 0 -4px 0 var(--color-yellow-dark);
}

/* Drop Animation */
.cell.dropping::after {
    animation: drop 0.3s ease-out forwards;
}

@keyframes drop {
    from {
        transform: translateY(-300px);
    }
    to {
        transform: translateY(0);
    }
}

/* Winning Cells */
.cell.winning::after {
    animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from {
        transform: scale(1);
        box-shadow: inset 0 -4px 0 rgba(0,0,0,0.2);
    }
    to {
        transform: scale(1.1);
        box-shadow: 0 0 20px currentColor, inset 0 -4px 0 rgba(0,0,0,0.2);
    }
}

/* Column Hover */
.column-hover {
    position: absolute;
    top: 0;
    width: var(--cell-size);
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, left 0.1s;
}

.board-container:hover .column-hover {
    opacity: 1;
}

/* Disabled state when not my turn */
.board.disabled {
    pointer-events: none;
}

.board.disabled .cell {
    cursor: not-allowed;
}

/* ============================================
   Result Screen
   ============================================ */
.result-content {
    text-align: center;
    margin-bottom: 20px;
}

.result-emoji {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
}

.result-content h2 {
    font-size: 28px;
}

.result-content.win h2 {
    color: var(--color-success);
}

.result-content.lose h2 {
    color: var(--color-error);
}

.result-content.draw h2 {
    color: var(--color-yellow);
}

/* Mini board for result screen */
.board.mini {
    --cell-size: 28px;
    --board-gap: 2px;
    margin-bottom: 20px;
}

.board.mini .cell::after {
    inset: 2px;
}

/* ============================================
   Error Screen
   ============================================ */
.error-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
}

#error-title {
    color: var(--color-error);
}

#error-message {
    color: var(--color-text-muted);
    text-align: center;
}

/* ============================================
   Toast
   ============================================ */
.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ============================================
   Media Queries
   ============================================ */
@media (min-width: 768px) {
    :root {
        --cell-size: 56px;
        --board-gap: 6px;
    }

    .logo h1 {
        font-size: 40px;
    }

    .room-code {
        font-size: 56px;
    }
}

/* Landscape on mobile */
@media (max-height: 600px) and (orientation: landscape) {
    :root {
        --cell-size: 40px;
        --board-gap: 3px;
    }

    #screen-game {
        padding-top: 10px;
        gap: 10px;
    }

    .game-header {
        max-width: none;
    }
}

/* Small phones */
@media (max-width: 360px) {
    :root {
        --cell-size: 42px;
        --board-gap: 3px;
    }

    .room-code {
        font-size: 40px;
        letter-spacing: 8px;
        padding: 16px 24px;
    }
}
