/* Super Tateti - Mobile-first dark theme */

:root {
    /* Base */
    --bg-main: #1a1a2e;
    --bg-surface: #16213e;
    --bg-mini: #0f3460;

    /* Players */
    --color-x: #e94560;
    --color-o: #00d9ff;

    /* States */
    --color-active: #ffc107;
    --color-won-x: rgba(233, 69, 96, 0.4);
    --color-won-o: rgba(0, 217, 255, 0.4);
    --color-tie: rgba(128, 128, 128, 0.4);

    /* UI */
    --color-text: #ffffff;
    --color-text-muted: #a0a0a0;
    --color-primary: #e94560;
    --color-secondary: #0f3460;
    --color-success: #2ecc71;
    --color-error: #e74c3c;

    --transition-speed: 0.2s;
    --border-radius: 12px;
    --border-radius-sm: 6px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    padding: 16px;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

.container {
    max-width: 400px;
    width: 100%;
    margin: 0 auto;
    text-align: center;
}

/* Typography */
h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}

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

.btn-primary:hover {
    background: #d63a52;
}

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

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

.btn-secondary:hover {
    background: #0d2a4a;
}

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

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

.btn-link {
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    min-height: 40px;
    text-decoration: underline;
}

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

.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

/* Inputs */
.input-group {
    margin-bottom: 1rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    background: var(--bg-surface);
    border: 2px solid var(--color-secondary);
    border-radius: var(--border-radius);
    color: var(--color-text);
    transition: border-color var(--transition-speed);
}

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

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

.code-input {
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: 0.5rem;
    text-transform: uppercase;
    font-weight: bold;
}

/* Room Code Display */
.room-code-display {
    margin: 2rem 0;
}

.room-code-display p {
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.code {
    font-size: 2.5rem;
    font-weight: bold;
    letter-spacing: 0.5rem;
    color: var(--color-primary);
    background: var(--bg-surface);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    display: inline-block;
}

/* Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--color-secondary);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 1rem auto;
}

.spinner.small {
    width: 24px;
    height: 24px;
    border-width: 3px;
}

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

/* Game Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-surface);
    border-radius: var(--border-radius);
}

.player-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 2px solid transparent;
    transition: all var(--transition-speed);
}

.player-info.player-x {
    border-color: var(--color-x);
    background: rgba(233, 69, 96, 0.1);
}

.player-info.player-o {
    border-color: var(--color-o);
    background: rgba(0, 217, 255, 0.1);
}

.player-info .symbol {
    font-size: 1.25rem;
}

.player-info .name {
    font-size: 0.75rem;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-info.player-x .name {
    color: var(--color-x);
}

.player-info.player-o .name {
    color: var(--color-o);
}

.player-info.current {
    transform: scale(1.05);
}

.player-info.current .name {
    font-weight: bold;
}

.vs {
    font-weight: bold;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* Turn Indicator */
.turn-indicator {
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    transition: all var(--transition-speed);
    display: inline-block;
}

.turn-indicator.your-turn {
    background: var(--color-success);
    color: white;
}

.turn-indicator.opponent-turn {
    background: var(--color-secondary);
    color: var(--color-text-muted);
}

.turn-indicator.turn-x {
    background: var(--color-x);
    color: white;
}

.turn-indicator.turn-o {
    background: var(--color-o);
    color: #1a1a2e;
}

/* Super Board: 3x3 of Mini Boards */
.super-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-width: 320px;
    margin: 0 auto;
    padding: 8px;
    background: var(--bg-surface);
    border-radius: var(--border-radius);
}

/* Mini Board: 3x3 cells */
.mini-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 4px;
    background: var(--bg-mini);
    border-radius: var(--border-radius-sm);
    border: 2px solid transparent;
    position: relative;
    transition: all var(--transition-speed);
}

.mini-board.active {
    border-color: var(--color-active);
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.4);
}

.mini-board.won-x {
    background: var(--color-won-x);
}

.mini-board.won-o {
    background: var(--color-won-o);
}

.mini-board.tie {
    background: var(--color-tie);
}

.mini-board.won-x .cell,
.mini-board.won-o .cell,
.mini-board.tie .cell {
    opacity: 0.3;
    pointer-events: none;
}

/* Mini board overlay for winner symbol */
.mini-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity var(--transition-speed);
}

.mini-board.won-x .mini-overlay,
.mini-board.won-o .mini-overlay,
.mini-board.tie .mini-overlay {
    opacity: 1;
}

.mini-board.won-x .mini-overlay::after {
    content: '❌';
}

.mini-board.won-o .mini-overlay::after {
    content: '⭕';
}

.mini-board.tie .mini-overlay::after {
    content: '➖';
    opacity: 0.5;
}

/* Cells */
.cell {
    aspect-ratio: 1;
    width: 100%;
    min-height: 28px;
    background: var(--bg-surface);
    border: 1px solid var(--bg-mini);
    border-radius: 4px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell:hover:not(:disabled):not(.taken) {
    background: var(--color-secondary);
    border-color: var(--color-active);
}

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

.cell.taken {
    cursor: default;
}

.cell.x {
    color: var(--color-x);
}

.cell.o {
    color: var(--color-o);
}

.cell.winning {
    animation: cellPulse 0.5s ease infinite alternate;
}

@keyframes cellPulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Active Indicator Text */
.active-indicator {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

#active-board-text {
    padding: 4px 10px;
    background: var(--bg-surface);
    border-radius: 12px;
}

/* Abandon Button */
.btn-abandon {
    margin-top: 1rem;
    font-size: 0.875rem;
    padding: 8px 16px;
    min-height: 36px;
}

/* Result Screen */
.result-symbol {
    font-size: 4rem;
    margin: 1rem 0;
}

.result-symbol.win {
    animation: bounce 0.5s ease;
}

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

/* Error Screen */
#error-message {
    color: var(--color-error);
    margin-bottom: 1.5rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--border-radius);
    padding: 24px;
    max-width: 360px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 1rem;
}

.help-text {
    text-align: left;
    line-height: 1.6;
}

.help-text p {
    margin-bottom: 0.75rem;
}

.help-example {
    background: var(--bg-mini);
    padding: 12px;
    border-radius: var(--border-radius-sm);
    margin: 1rem 0;
    border-left: 3px solid var(--color-active);
}

.help-example p {
    margin-bottom: 0;
}

#btn-close-help {
    margin-top: 1.5rem;
}

/* Responsive */
@media (min-width: 360px) {
    .super-board {
        max-width: 340px;
        gap: 8px;
    }

    .mini-board {
        gap: 3px;
        padding: 5px;
    }

    .cell {
        min-height: 32px;
        font-size: 1.2rem;
    }

    .mini-overlay {
        font-size: 3.5rem;
    }
}

@media (min-width: 400px) {
    .super-board {
        max-width: 360px;
    }

    .cell {
        min-height: 36px;
        font-size: 1.3rem;
    }

    .mini-overlay {
        font-size: 4rem;
    }
}

@media (min-width: 768px) {
    h1 {
        font-size: 2.5rem;
    }

    .super-board {
        max-width: 400px;
        gap: 10px;
    }

    .mini-board {
        gap: 4px;
        padding: 6px;
    }

    .cell {
        min-height: 40px;
        font-size: 1.5rem;
    }

    .mini-overlay {
        font-size: 4.5rem;
    }
}

/* Winning mini boards highlighting */
.mini-board.global-winning {
    animation: globalWinPulse 0.6s ease infinite alternate;
}

@keyframes globalWinPulse {
    from {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
    }
    to {
        transform: scale(1.02);
        box-shadow: 0 0 20px rgba(46, 204, 113, 0.8);
    }
}
