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

:root {
    --bg: #0a0a0a;
    --surface: #1a1a1a;
    --surface-hover: #222;
    --border: #2a2a2a;
    --text: #e0e0e0;
    --text-dim: #888;
    --accent: #d4a574;
    --accent-hover: #e0b688;
    --danger: #c0544e;
    --danger-hover: #d4605a;
    --black-stone: #222;
    --white-stone: #e8e8e8;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    min-height: 100dvh;
    overflow: hidden;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100dvh;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* ── Lobby ────────────────────────────────── */

.lobby-container {
    text-align: center;
    max-width: 380px;
    width: 100%;
    padding: 20px;
}

.logo {
    font-size: 4rem;
    font-weight: 200;
    letter-spacing: 0.15em;
    color: var(--accent);
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 48px;
}

.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.size-select {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 8px;
}

.size-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

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

.size-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #0a0a0a;
    font-weight: 600;
}

.primary-btn {
    background: var(--accent);
    color: #0a0a0a;
    border: none;
    padding: 14px 32px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

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

.secondary-btn {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.secondary-btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 8px;
    transition: color 0.15s;
}

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

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-dim);
    font-size: 0.8rem;
    margin: 4px 0;
}

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

.join-section {
    display: flex;
    gap: 8px;
}

#room-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 1rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    text-align: center;
    outline: none;
    transition: border-color 0.15s;
}

#room-input::placeholder {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-dim);
}

#room-input:focus {
    border-color: var(--accent);
}

/* Waiting section */
.waiting-section {
    margin-top: 32px;
    animation: fadeIn 0.3s ease;
}

.waiting-text {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 16px;
    animation: pulse 2s ease-in-out infinite;
}

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

.room-code-display {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 20px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 1.8rem;
    letter-spacing: 0.25em;
    color: var(--accent);
    margin-bottom: 8px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    transition: color 0.15s;
    display: flex;
}

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

.share-hint {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-bottom: 12px;
}

.status-message {
    margin-top: 20px;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease;
}

.status-message.error {
    background: rgba(192, 84, 78, 0.15);
    border: 1px solid rgba(192, 84, 78, 0.3);
    color: var(--danger);
}

.status-message.info {
    background: rgba(212, 165, 116, 0.1);
    border: 1px solid rgba(212, 165, 116, 0.2);
    color: var(--accent);
}

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

/* ── Game Screen ──────────────────────────── */

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

.game-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    gap: 12px;
    max-height: 100dvh;
}

.game-info-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 720px;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.bottom-panel {
    flex-wrap: wrap;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.stone-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
}

.stone-icon.black {
    background: radial-gradient(circle at 35% 35%, #555, #111);
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.stone-icon.white {
    background: radial-gradient(circle at 35% 35%, #fff, #ccc);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.player-label {
    font-weight: 500;
    font-size: 0.9rem;
}

.capture-count {
    color: var(--text-dim);
    font-size: 0.8rem;
}

.turn-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
    margin-left: auto;
    transition: all 0.3s;
}

.turn-indicator.active {
    background: var(--accent);
    box-shadow: 0 0 8px rgba(212, 165, 116, 0.5);
}

.board-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 720px;
    aspect-ratio: 1;
}

#board-canvas {
    cursor: pointer;
    border-radius: 8px;
}

.game-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.action-btn {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.action-btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: default;
    border-color: var(--border);
    color: var(--text-dim);
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
}

.connection-status.disconnected .status-dot {
    background: var(--danger);
}

.connection-status.connecting .status-dot {
    background: var(--accent);
    animation: pulse 1s ease-in-out infinite;
}

/* ── Game Over Overlay ────────────────────── */

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
    backdrop-filter: blur(4px);
}

.overlay-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 360px;
    width: calc(100% - 40px);
    animation: slideUp 0.3s ease;
}

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

.overlay-card h2 {
    font-size: 1.6rem;
    font-weight: 300;
    color: var(--accent);
    margin-bottom: 20px;
}

.score-display {
    margin-bottom: 28px;
}

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 0.9rem;
}

.score-row + .score-row {
    border-top: 1px solid var(--border);
}

.score-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.score-value {
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.score-value.winner {
    color: var(--accent);
}

.overlay-card .primary-btn {
    margin-bottom: 8px;
}

/* ── Responsive ───────────────────────────── */

@media (max-width: 480px) {
    .logo {
        font-size: 3rem;
    }

    .game-info-panel {
        padding: 8px 12px;
    }

    .game-actions {
        width: 100%;
        margin-left: 0;
    }

    .action-btn {
        flex: 1;
    }

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

    .capture-count {
        font-size: 0.75rem;
    }
}
