@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-tertiary: #1a1a1a;
    --accent-gold: #d4af37;
    --accent-silver: #c0c0c0;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    padding: 16px 0;
}

.particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(circle at 20% 50%, rgba(212, 175, 55, 0.03) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(192, 192, 192, 0.03) 0%, transparent 50%);
}

.particle {
    position: absolute;
    background: rgba(212, 175, 55, 0.2);
    border-radius: 50%;
    animation: particleFloat 8s infinite ease-in-out;
    z-index: -1;
    pointer-events: none;
}

@keyframes particleFloat {
    0%, 100% {
        transform: translateY(0) translateX(0);
        opacity: 0;
    }
    10% { opacity: 0.3; }
    90% { opacity: 0.3; }
    100% {
        transform: translateY(-100vh) translateX(50px);
        opacity: 0;
    }
}

.container {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 580px;
    padding: 24px;
}

/* Keep mode selection at standard width - no expansion needed since vertical layout */
.mode-selection {
    max-width: 100%;
}

/* Header */
.game-header {
    text-align: center;
    margin-bottom: 24px;
    animation: fadeSlideDown 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeSlideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-title {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #ffffff 0%, #a0a0a0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-title .letter {
    display: inline-block;
    animation: letterFade 0.5s ease-out both;
}

.game-title .letter:nth-child(1) { animation-delay: 0.05s; }
.game-title .letter:nth-child(2) { animation-delay: 0.1s; }
.game-title .letter:nth-child(3) { animation-delay: 0.15s; }
.game-title .letter:nth-child(5) { animation-delay: 0.2s; }
.game-title .letter:nth-child(6) { animation-delay: 0.25s; }
.game-title .letter:nth-child(7) { animation-delay: 0.3s; }
.game-title .letter:nth-child(9) { animation-delay: 0.35s; }
.game-title .letter:nth-child(10) { animation-delay: 0.4s; }
.game-title .letter:nth-child(11) { animation-delay: 0.45s; }

@keyframes letterFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.subtitle {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    animation: fadeIn 0.6s ease-out 0.3s both;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mode Selection */
.mode-selection {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 32px 28px;
    border: 1px solid var(--border-subtle);
    animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.mode-title {
    font-size: 1.375rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 24px;
    letter-spacing: -0.02em;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

@media (min-width: 768px) {
    .mode-buttons {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 767px) {
    .mode-buttons {
        grid-template-columns: 1fr;
    }
}

.mode-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 18px 20px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
    text-align: left;
    position: relative;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.mode-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.1), rgba(192, 192, 192, 0.05));
    opacity: 0;
    transition: opacity 0.25s ease;
}

.mode-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(212, 175, 55, 0.3);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.mode-btn:hover::before {
    opacity: 1;
}

.mode-btn:active {
    transform: translateY(0);
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: 10px;
    display: block;
    filter: grayscale(0.3);
}

.mode-name {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}

.mode-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Board Size Selection */
.board-size-selection {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
}

.board-size-title {
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 12px;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
}

.board-size-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.board-size-btn {
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.size-label {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.size-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.board-size-btn:hover {
    background: var(--bg-secondary);
    border-color: rgba(212, 175, 55, 0.3);
    transform: translateY(-2px);
}

.board-size-btn.active {
    background: linear-gradient(135deg, var(--accent-gold), #b8941f);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.board-size-btn.active .size-label {
    color: var(--bg-primary);
}

.board-size-btn.active .size-desc {
    color: rgba(10, 10, 10, 0.8);
}

.board-size-btn:active {
    transform: translateY(0);
}

/* Instructions */
.instructions-container {
    margin-top: 16px;
}

.instructions-toggle {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.instructions-toggle:hover {
    background: var(--bg-secondary);
    border-color: rgba(212, 175, 55, 0.2);
}

.instructions-content {
    margin-top: 12px;
    padding: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.instruction-text {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.instruction-text strong {
    color: var(--accent-gold);
    display: block;
    margin-bottom: 4px;
}

/* Player Setup */
.player-setup {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 40px 32px;
    border: 1px solid var(--border-subtle);
    animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.setup-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 32px;
    letter-spacing: -0.02em;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
    outline: none;
}

.input-group input:focus {
    border-color: rgba(212, 175, 55, 0.4);
    background: rgba(212, 175, 55, 0.05);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.start-btn {
    width: 100%;
    padding: 16px;
    margin-top: 24px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--accent-gold), #b8941f);
    color: var(--bg-primary);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.02em;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(212, 175, 55, 0.3);
}

.start-btn:active {
    transform: translateY(0);
}

/* Online Setup */
.online-setup,
.room-screen {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 40px 32px;
    border: 1px solid var(--border-subtle);
    animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.online-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

@media (min-width: 640px) {
    .online-options {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 639px) {
    .online-options {
        grid-template-columns: 1fr;
    }
}

.online-option-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
    text-align: left;
    position: relative;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.online-option-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.1), rgba(192, 192, 192, 0.05));
    opacity: 0;
    transition: opacity 0.25s ease;
}

.online-option-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(212, 175, 55, 0.3);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.online-option-btn:hover::before {
    opacity: 1;
}

.option-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    display: block;
}

.option-name {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}

.option-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.back-btn {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.back-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.room-code-display {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    margin: 24px 0;
}

.room-code-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 500;
}

.room-code {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    color: var(--accent-gold);
    margin-bottom: 16px;
    font-family: 'Courier New', monospace;
}

.copy-btn {
    padding: 10px 24px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: var(--bg-primary);
    border-color: rgba(212, 175, 55, 0.3);
    color: var(--accent-gold);
}

.copy-btn:active {
    transform: scale(0.95);
}

.waiting-status {
    text-align: center;
    padding: 24px;
    margin-bottom: 24px;
}

.waiting-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.waiting-text {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    margin: 16px 0;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-gold);
    animation: pulse-indicator 2s infinite;
}

@keyframes pulse-indicator {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

.status-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Game Container */
.game-container {
    animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Scoreboard */
.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--border-subtle);
    gap: 24px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.player2-info {
    flex-direction: row-reverse;
    text-align: right;
}

.player-avatar {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.player1-info .player-avatar {
    color: var(--accent-gold);
}

.player2-info .player-avatar {
    color: var(--accent-silver);
}

.player1-info.active .player-avatar {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1),
                0 4px 16px rgba(212, 175, 55, 0.2);
    transform: scale(1.05);
}

.player2-info.active .player-avatar {
    border-color: var(--accent-silver);
    box-shadow: 0 0 0 3px rgba(192, 192, 192, 0.1),
                0 4px 16px rgba(192, 192, 192, 0.2);
    transform: scale(1.05);
}

.player-details {
    flex: 1;
    min-width: 0;
}

.player-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-score {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.host-crown {
    font-size: 0.875rem;
    margin-left: 4px;
    filter: drop-shadow(0 0 4px rgba(212, 175, 55, 0.6));
    animation: crownGlow 2s ease-in-out infinite;
}

@keyframes crownGlow {
    0%, 100% {
        filter: drop-shadow(0 0 4px rgba(212, 175, 55, 0.6));
    }
    50% {
        filter: drop-shadow(0 0 8px rgba(212, 175, 55, 0.9));
    }
}

.vs-divider {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.1em;
}

/* Turn Indicator */
.turn-indicator {
    text-align: center;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border-subtle);
}

.turn-text {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 4px;
}

.turn-player {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* Game Board */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.cell {
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    user-select: none;
}

/* Dynamic font size based on board size */
.board[style*="repeat(4"] .cell {
    font-size: 2.75rem;
}

.board[style*="repeat(5"] .cell {
    font-size: 2.25rem;
}

.cell:hover:not(.x):not(.o) {
    background: var(--bg-tertiary);
    border-color: rgba(255, 255, 255, 0.15);
    transform: scale(1.02);
}

.cell:active:not(.x):not(.o) {
    transform: scale(0.98);
}

.cell.x,
.cell.o {
    cursor: not-allowed;
    animation: cellAppear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cellAppear {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.cell.x {
    color: var(--accent-gold);
    border-color: rgba(212, 175, 55, 0.2);
    background: rgba(212, 175, 55, 0.05);
}

.cell.o {
    color: var(--accent-silver);
    border-color: rgba(192, 192, 192, 0.2);
    background: rgba(192, 192, 192, 0.05);
}

.cell.winner {
    animation: winnerPulse 1.2s ease-in-out infinite;
    border-color: rgba(212, 175, 55, 0.6);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2),
                0 4px 32px rgba(212, 175, 55, 0.4);
    background: rgba(212, 175, 55, 0.08);
}

@keyframes winnerPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2),
                    0 4px 32px rgba(212, 175, 55, 0.4);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 6px rgba(212, 175, 55, 0.3),
                    0 8px 40px rgba(212, 175, 55, 0.6);
    }
}

/* Game Controls */
.game-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.control-btn {
    padding: 14px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.01em;
}

.reset-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.reset-btn:hover {
    background: var(--bg-secondary);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.menu-btn {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.menu-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.control-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.125rem;
}

/* Waiting Overlay */
.waiting-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.waiting-overlay-content {
    text-align: center;
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.waiting-spinner-large {
    width: 60px;
    height: 60px;
    margin: 0 auto 24px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.waiting-overlay-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.waiting-overlay-subtext {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 48px 40px;
    text-align: center;
    animation: modalScale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    max-width: 400px;
    margin: 24px;
}

@keyframes modalScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.confetti {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    top: -10px;
    animation: confettiFall 2.5s ease-in;
}

@keyframes confettiFall {
    to {
        transform: translateY(500px) rotate(720deg);
        opacity: 0;
    }
}

.winner-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: iconPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes iconPop {
    0% {
        transform: scale(0);
    }
    100% {
        transform: scale(1);
    }
}

.winner-text {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.winner-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-weight: 500;
}

.modal-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.modal-btn {
    padding: 14px 24px;
    border-radius: 10px;
    border: none;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.01em;
}

.play-again-btn {
    background: linear-gradient(135deg, var(--accent-gold), #b8941f);
    color: var(--bg-primary);
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(212, 175, 55, 0.3);
}

.menu-modal-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.menu-modal-btn:hover {
    background: var(--bg-primary);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.modal-btn:active {
    transform: translateY(0);
}

/* Chat Container */
.chat-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    margin-top: 24px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.chat-container.minimized .chat-messages,
.chat-container.minimized .chat-input-container {
    display: none;
}

.chat-header {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.chat-toggle:hover {
    color: var(--text-primary);
}

.chat-messages {
    height: 200px;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

.chat-message {
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 0.875rem;
    line-height: 1.4;
}

.chat-message.own {
    background: var(--accent-gold);
    color: var(--bg-primary);
    align-self: flex-end;
    margin-left: auto;
}

.chat-message.opponent {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    align-self: flex-start;
}

.chat-message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.8;
}

.chat-input-container {
    padding: 12px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--accent-gold);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send {
    padding: 10px 20px;
    background: var(--accent-gold);
    color: var(--bg-primary);
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.chat-send:active {
    transform: translateY(0);
}

/* Tablet optimizations */
@media (min-width: 641px) and (max-width: 1023px) {
    .container:has(.mode-selection) {
        max-width: 750px;
    }

    .mode-buttons {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }

    .online-options {
        grid-template-columns: repeat(2, 1fr);
    }

    .mode-btn,
    .online-option-btn {
        padding: 22px;
    }
}

/* Responsive */
@media (max-width: 640px) {
    body {
        padding: 12px 0;
    }

    .container {
        max-width: 100%;
        padding: 12px;
    }

    /* Override max-width expansion on mobile */
    .container:has(.mode-selection) {
        max-width: 100%;
    }

    .game-header {
        margin-bottom: 20px;
    }

    .game-title {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.7rem;
    }

    .mode-selection,
    .player-setup,
    .online-setup,
    .room-screen {
        padding: 20px 16px;
    }

    .mode-title,
    .setup-title {
        font-size: 1.125rem;
        margin-bottom: 20px;
    }

    .board-size-selection {
        margin-top: 20px;
        padding-top: 20px;
    }

    .board-size-title {
        margin-bottom: 10px;
        font-size: 0.9375rem;
    }

    .board-size-buttons {
        gap: 8px;
    }

    .board-size-btn {
        padding: 10px 14px;
    }

    .size-label {
        font-size: 0.9375rem;
    }

    .size-desc {
        font-size: 0.6875rem;
    }

    .instructions-container {
        margin-top: 12px;
    }

    .instructions-toggle {
        padding: 10px 14px;
        font-size: 0.8125rem;
    }

    .instructions-content {
        padding: 12px;
    }

    .instruction-text {
        font-size: 0.8125rem;
    }

    .mode-btn,
    .online-option-btn {
        padding: 16px;
    }

    .mode-icon,
    .option-icon {
        font-size: 1.75rem;
        margin-bottom: 8px;
    }

    .mode-name,
    .option-name {
        font-size: 1rem;
    }

    .mode-desc,
    .option-desc {
        font-size: 0.8125rem;
    }

    /* Ensure single column on mobile */
    .mode-buttons,
    .online-options {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .cell {
        font-size: 2.5rem;
    }

    .board[style*="repeat(4"] .cell {
        font-size: 2rem;
    }

    .board[style*="repeat(5"] .cell {
        font-size: 1.75rem;
    }

    .board {
        gap: 8px;
    }

    .board[style*="repeat(4"],
    .board[style*="repeat(5"] {
        gap: 6px;
    }

    .scoreboard {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 16px;
    }

    .player-avatar {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
    }

    .player-name {
        font-size: 0.9375rem;
    }

    .player-score {
        font-size: 0.8125rem;
    }

    .player2-info {
        flex-direction: row;
        text-align: left;
    }

    .vs-divider {
        display: none;
    }

    .turn-indicator {
        padding: 12px;
    }

    .turn-player {
        font-size: 1rem;
    }

    .game-controls {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .control-btn {
        padding: 12px;
        font-size: 0.875rem;
    }

    .chat-container {
        margin-top: 16px;
    }

    .chat-messages {
        height: 150px;
    }

    .chat-input-container {
        padding: 10px;
        gap: 6px;
    }

    .chat-input {
        font-size: 0.8125rem;
        padding: 8px 10px;
    }

    .chat-send {
        padding: 8px 16px;
        font-size: 0.8125rem;
    }

    .modal-content {
        padding: 32px 24px;
        margin: 16px;
    }

    .winner-icon {
        font-size: 3rem;
    }

    .winner-text {
        font-size: 1.5rem;
    }

    .winner-subtitle {
        font-size: 0.875rem;
    }

    .modal-buttons {
        grid-template-columns: 1fr;
    }

    .waiting-overlay-text {
        font-size: 1.25rem;
    }

    .waiting-overlay-subtext {
        font-size: 0.875rem;
    }

    .room-code {
        font-size: 2rem;
        letter-spacing: 0.15em;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .game-title {
        font-size: 1.5rem;
    }

    .game-header {
        margin-bottom: 16px;
    }

    .mode-selection,
    .player-setup,
    .online-setup,
    .room-screen {
        padding: 16px 12px;
    }

    .cell {
        font-size: 2rem;
    }

    .board {
        gap: 6px;
    }

    .chat-messages {
        height: 120px;
    }

    .board-size-btn {
        padding: 8px 12px;
    }

    .size-label {
        font-size: 0.875rem;
    }

    .size-desc {
        font-size: 0.625rem;
    }
}

/* Very short screens (landscape phones, etc) */
@media (max-height: 700px) {
    body {
        padding: 8px 0;
    }

    .game-header {
        margin-bottom: 16px;
    }

    .game-title {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.7rem;
    }

    .mode-selection,
    .player-setup,
    .online-setup,
    .room-screen {
        padding: 16px;
    }

    .mode-title,
    .setup-title {
        font-size: 1rem;
        margin-bottom: 16px;
    }

    .board-size-selection {
        margin-top: 16px;
        padding-top: 16px;
    }

    .board-size-btn {
        padding: 10px 14px;
    }

    .mode-btn,
    .online-option-btn {
        padding: 14px;
    }

    .mode-icon,
    .option-icon {
        font-size: 1.75rem;
        margin-bottom: 8px;
    }
}
