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

/* Theme */
:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --success-hover: #16a34a;
    --warning: #eab308;
    --warning-hover: #ca8a04;
    --danger: #ef4444;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: #475569;
    --border-active: #3b82f6;

    --red-token: #dc2626;
    --yellow-token: #fbbf24;
}

/* Layout */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--bg-card);
    padding: 5px 2rem;
    border-bottom: 2px solid var(--border);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

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

header .logo img {
    height: 68px;
    width: auto;
}

header .logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
    min-height: 0;
    width: 100%;
}

footer {
    background: var(--bg-card);
    padding: 8px 2rem;
    border-top: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 1.5rem;
}

footer .footer-left {
    display: flex;
    align-items: center;
}

footer .footer-logo {
    height: 22px;
}

footer .footer-right {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    max-width: 900px;
}

.screen.active {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.card h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.card h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

/* Lobby header */
.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.lobby-header h2 {
    margin-bottom: 0;
}

.subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.125rem;
}

/* Inputs */
input[type="text"] {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-dark);
    color: var(--text-primary);
    margin-bottom: 1rem;
    transition: all 0.2s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--border-active);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

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

/* Buttons */
.btn {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

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

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

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

.btn-success:hover {
    background: var(--success-hover);
}

.btn-warning {
    background: var(--warning);
    color: var(--bg-dark);
}

.btn-warning:hover {
    background: var(--warning-hover);
}

.btn-large {
    width: 100%;
    padding: 1.25rem;
    font-size: 1.125rem;
}

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

/* Messages */
.message {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 6px;
    text-align: center;
    font-size: 0.875rem;
}

.message.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.message.success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid var(--success);
}

/* Lobby */
.lobby-section {
    margin: 1.5rem 0;
}

.lobby-section label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.separator {
    text-align: center;
    margin: 2rem 0;
    color: var(--text-muted);
    font-weight: 600;
    position: relative;
}

.separator::before,
.separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.separator::before {
    left: 0;
}

.separator::after {
    right: 0;
}

.input-group {
    display: flex;
    gap: 0.75rem;
}

.input-group input {
    flex: 1;
    margin-bottom: 0;
}

/* Waiting area */
.waiting-area {
    margin-top: 2rem;
    padding: 2rem;
    background: var(--bg-dark);
    border-radius: 8px;
    border: 2px solid var(--border-active);
    text-align: center;
}

.waiting-area h3 {
    color: var(--warning);
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.code-display {
    margin: 1.5rem 0;
}

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

.code-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--success);
    letter-spacing: 0.25rem;
    font-family: 'Courier New', monospace;
}

.share-text {
    color: var(--text-secondary);
    margin-top: 1rem;
    font-size: 0.875rem;
}

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

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

/* Game screen layout */
#game-screen {
    position: relative;
    width: 100%;
    max-width: 1200px;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
}

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

/* Game header */
.game-header {
    width: 100%;
    max-width: 1000px;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: 2rem;
    margin: 0 auto 1rem;
}

.player-card {
    width: 180px;
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    border: 3px solid transparent;
    transition: all 0.3s;
    text-align: center;
}

.player-card.player-0 {
    border-color: var(--red-token);
}

.player-card.player-1 {
    border-color: var(--yellow-token);
}

.player-card.player-0.active {
    border-color: var(--red-token);
    box-shadow: 0 0 20px rgba(220, 38, 38, 0.85);
}

.player-card.player-1.active {
    border-color: var(--yellow-token);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.85);
}

.player-token {
    width: 50px;
    height: 50px;
}

.player-info {
    width: 100%;
}

.player-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.player-badge {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-dark);
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    display: inline-block;
}

.player-timer {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: var(--bg-dark);
    border-radius: 6px;
    color: var(--text-primary);
    transition: all 0.3s;
}

.player-timer.warning {
    color: var(--warning);
    animation: pulse 1s infinite;
}

.player-timer.danger {
    color: var(--danger);
    animation: pulse 0.5s infinite;
}

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

/* Game status and actions */
.game-info-center {
    flex: 1;
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.code-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.code-area span {
    font-family: 'Courier New', monospace;
    font-size: 1.125rem;
    font-weight: bold;
    color: var(--success);
}

.game-actions {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: end;
    gap: 0.5rem;
}

.replay-area {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.status-message {
    font-size: 1.125rem;
    font-weight: 600;
    padding: 0.75rem;
    background: var(--bg-dark);
    border-radius: 8px;
}

/* Board */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    overflow-x: auto;
}

#game-board {
    display: block;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    margin: 0 auto;
    width: 100%;
    max-width: min(560px, 100vw - 2rem);
    height: auto;
    aspect-ratio: 7 / 6 !important;
}

/* Tablet */
@media (max-width: 1024px) {
    .card {
        padding: 2rem;
    }

    .card h1 {
        font-size: 2.1rem;
    }

    .card h2 {
        font-size: 1.5rem;
    }

    .game-header {
        max-width: 900px;
        gap: 1.5rem;
    }

    .player-card {
        width: 160px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    body {
        font-size: 0.95rem;
    }

    header .logo img {
        height: 48px;
    }

    header .logo h1 {
        font-size: 1.4rem;
    }

    .card {
        padding: 1.5rem;
    }

    .card h1 {
        font-size: 2rem;
    }

    .card h2 {
        font-size: 1.4rem;
    }

    main {
        padding: .5rem 1rem;
    }

    #game-screen {
        padding: .5rem 1rem 0 1rem;
        max-width: 100%;
    }

    .game-header {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
        max-width: 100%;
    }

    .player-card {
        flex: 1 1 45%;
        width: auto;
        padding: 0.6rem;
        gap: 0.5rem;
    }

    .player-token {
        width: 30px;
        height: 30px;
    }

    .player-name {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }

    .player-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }

    #player-0 {
        order: 1;
    }

    #player-1 {
        order: 2;
    }

    .game-info-center {
        order: 3;
        flex: 1 1 100%;
        padding: 0.75rem;
    }

    .status-message {
        font-size: 1rem;
        padding: 0.6rem;
    }
}

/* Small mobile width */
@media (max-width: 825px) {
    main {
        align-items: start;
    }

    .game-actions {
        flex-direction: row;
        margin-bottom: -5rem;
    }

    .game-actions button {
        margin-bottom: 1rem;
    }
}

/* Very small mobile */
@media (max-width: 492px) {
    body {
        font-size: 0.9rem;
    }

    header {
        padding: 5px 1.5rem;
    }

    footer {
        padding: 8px 1.5rem;
    }

    .card {
        padding: 1.25rem;
    }

    .card h1 {
        font-size: 1.8rem;
    }

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

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

    .player-badge {
        font-size: 0.65rem;
    }

    .code-area span {
        font-size: 1rem;
    }

    .code-value {
        font-size: 2.1rem;
    }

    #game-board {
        width: 100% !important;
    }
}

/* Short height */
@media (max-height: 850px) {
    main {
        align-items: start;
    }

    #game-board {
        max-height: 45vh;
        width: auto;
    }
}

@media (max-height: 600px) {
    #game-board {
        max-height: 40vh;
    }
}
