/**
 * Air Hockey - Styles
 * 2-6 player multiplayer air hockey game.
 *
 * Chrome is built on the shared design system (design-tokens.css + ui.css,
 * loaded before this file). Everything inside the canvas — the table, the
 * puck, the paddles and the team colours — is drawn by the game and is
 * deliberately not touched here.
 */

/* ============================================
   BASE STYLES
   ============================================ */

/* Reset and typography come from ui.css. */

body {
    color: var(--text-body);
    background: var(--bg);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

.hidden {
    display: none !important;
}

/* ============================================
   GAME CONTAINER
   ============================================ */

#gameContainer {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr 280px;
    height: 100vh;
    height: 100dvh;
    gap: 0;
}

#gameContainer.hidden {
    display: none;
}

/* ============================================
   TOP BAR
   ============================================ */

.top-bar {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-3) var(--sp-5);
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    min-height: 60px;
    overflow: visible;
    flex-wrap: wrap;
    gap: var(--sp-4);
}

.game-info {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.game-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--accent-ink);
}

.game-info h1 {
    font-size: var(--fs-lg);
    color: var(--text);
}

/* Same treatment as .sdk-room in the shell. */
.room-badge {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    max-width: 24ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.room-badge:empty { display: none; }

.score-display {
    display: flex;
    gap: var(--sp-8);
}

.score-board {
    display: flex;
    gap: var(--sp-4);
    align-items: center;
}

.score-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

/* The dot carries the player's in-game team colour (set inline by the game);
   it is game state, not palette. */
.score-color {
    width: 14px;
    height: 14px;
    border-radius: var(--r-pill);
    flex: none;
}

.score-name {
    font-weight: 600;
    font-size: var(--fs-sm);
    color: var(--text);
}

.score-value {
    font-size: var(--fs-xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent-ink);
    min-width: 28px;
    text-align: center;
}

/* Indicator styles */
.indicator {
    font-size: var(--fs-lg);
}

.indicator.connected {
    color: var(--success);
}

.indicator.disconnected {
    color: var(--danger);
}

/* ============================================
   GAME ARENA
   ============================================ */

.game-arena {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--code-bg);
    overflow: hidden;
    min-height: 300px;
    padding: 10px;
}

#gameCanvas {
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
    /* Don't use max-width/max-height as they interfere with transform scaling */
    display: block;
    max-width: none;
}

/* Portrait mode container adjustments */
.game-arena.portrait-mode {
    min-height: 50vh;
}

#gameCanvas.rotated {
    /* Canvas is rotated via JS transform */
}

/* ============================================
   CONTROL PANEL (lobby card)
   ============================================ */

.control-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface-1);
    padding: var(--sp-8);
    border-radius: var(--r-xl);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-3);
    text-align: center;
    min-width: 350px;
    z-index: 100;
}

.control-panel.hidden {
    display: none;
}

.control-panel h2 {
    font-size: var(--fs-2xl);
    margin-bottom: var(--sp-2);
}

.control-panel p {
    color: var(--text-muted);
    margin-bottom: var(--sp-6);
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
    max-height: 150px;
    overflow-y: auto;
}

.player-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-4);
    background: var(--surface-2);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.player-item.ready {
    border-color: rgba(52, 211, 153, 0.35);
    background: var(--success-bg);
}

.player-color {
    width: 18px;
    height: 18px;
    border-radius: var(--r-pill);
    border: 2px solid var(--border-strong);
    flex: none;
}

.player-name {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    text-align: left;
    font-weight: 500;
    color: var(--text);
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Peer link state in the lobby list. */
.p2p-state { flex: none; }
.p2p-state--on { color: var(--success); }
.p2p-state--wait { color: var(--warning); }

.player-status {
    font-size: var(--fs-lg);
}

.game-message {
    color: var(--accent-ink);
    font-size: var(--fs-base);
    margin: var(--sp-4) 0;
    font-weight: 500;
}

.game-settings {
    margin: var(--sp-4) 0;
    padding: var(--sp-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.game-settings label {
    color: var(--text-body);
    font-size: var(--fs-md);
    font-weight: 600;
}

.game-settings select {
    margin-left: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    min-height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-strong);
    background: var(--code-bg);
    color: var(--text);
    font-family: inherit;
    font-size: var(--fs-md);
    cursor: pointer;
}

.game-buttons {
    display: flex;
    gap: var(--sp-3);
    justify-content: center;
    align-items: center;
    margin: var(--sp-4) 0;
    flex-wrap: wrap;
}

.game-buttons .btn {
    flex: 1;
    min-width: 160px;
    max-width: 250px;
}

/* ============================================
   GOAL OVERLAY
   ============================================ */

.goal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    animation: goalFadeIn 0.3s var(--ease);
}

.goal-overlay.hidden {
    display: none;
}

@keyframes goalFadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Game moment, not chrome: the gold stays. */
.goal-text {
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--warning) 0%, #f59e0b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: goalPulse 0.5s ease infinite alternate;
}

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

.goal-scorer {
    font-size: var(--fs-xl);
    color: var(--text);
    margin-top: var(--sp-4);
}

/* ============================================
   SIDE PANEL
   ============================================ */

.side-panel {
    background: var(--surface-1);
    padding: var(--sp-5);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
    overflow-y: auto;
}

/* Same voice as .sdk-side__title in the shell. */
.side-panel h3 {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: var(--sp-2);
}

.side-panel h3 .icon {
    color: var(--text-faint);
}

.side-panel h4 {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: var(--sp-2);
}

.controls-info {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    line-height: var(--lh-body);
}

.controls-info p {
    margin-bottom: var(--sp-2);
}

.controls-info strong { color: var(--text-body); }

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.leaderboard-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.leaderboard-rank .icon { width: 18px; height: 18px; }
.leaderboard-rank--1 { color: var(--warning); }
.leaderboard-rank--2 { color: #cbd5e1; }
.leaderboard-rank--3 { color: #d3976b; }

.leaderboard-color {
    width: 14px;
    height: 14px;
    border-radius: var(--r-pill);
    flex: none;
}

.leaderboard-name {
    flex: 1;
    font-weight: 500;
    font-size: var(--fs-sm);
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent-ink);
}

.game-stats {
    padding: var(--sp-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: var(--sp-1) 0;
    font-size: var(--fs-sm);
}

.stat-row span:first-child {
    color: var(--text-muted);
}

.stat-row span:last-child {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.host-controls {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}

.side-panel .btn,
.host-controls .btn {
    width: 100%;
}

.connection-info {
    background: var(--accent-subtle);
    border: 1px solid rgba(34, 211, 238, 0.3);
    border-radius: var(--r-md);
    padding: var(--sp-3);
    margin-bottom: var(--sp-2);
}

.connection-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-1) 0;
    font-size: var(--fs-sm);
}

.connection-row:first-child {
    margin-bottom: var(--sp-2);
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--border);
}


/* ============================================
   RESPONSIVE
   ============================================ */

/* Tablet and smaller screens */
@media (max-width: 900px) {
    #gameContainer {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .top-bar {
        padding: var(--sp-2) var(--sp-3);
        gap: var(--sp-2);
        min-height: auto;
    }

    .game-info { gap: var(--sp-2); }

    .game-mark { width: 28px; height: 28px; }

    .game-info h1 {
        font-size: var(--fs-base);
    }

    .room-badge {
        font-size: var(--fs-xs);
        padding: 2px 8px;
        max-width: 14ch;
    }

    .score-display {
        gap: var(--sp-2);
    }

    .score-board {
        gap: var(--sp-2);
        flex-wrap: wrap;
    }

    .score-item {
        padding: var(--sp-1) var(--sp-2);
        font-size: var(--fs-sm);
    }

    .side-panel {
        border-left: none;
        border-top: 1px solid var(--border);
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-around;
        padding: var(--sp-3);
        gap: var(--sp-3);
        max-height: 30vh;
        overflow-y: auto;
        /* The last row of controls must clear the phone's home indicator. */
        padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
    }

    .side-panel > * {
        flex: 1;
        min-width: 120px;
    }

    .side-panel h3 {
        font-size: var(--fs-xs);
        width: 100%;
        margin-bottom: 0;
    }

    .side-panel h4 {
        font-size: var(--fs-xs);
        width: 100%;
    }

    .side-panel .btn {
        width: 100%;
        min-width: 100%;
        flex: 1 1 100%;
    }

    .control-panel {
        min-width: 280px;
        padding: var(--sp-6);
        max-width: 90vw;
    }

    .control-panel h2 {
        font-size: var(--fs-xl);
    }
}

/* Mobile landscape (width > height, small screen) */
@media (max-width: 900px) and (orientation: landscape) {
    #gameContainer {
        grid-template-columns: 1fr 200px;
        grid-template-rows: auto 1fr;
    }

    .top-bar {
        padding: var(--sp-1) var(--sp-2);
        min-height: 40px;
    }

    .game-info h1 {
        font-size: var(--fs-md);
    }

    .game-mark { display: none; }

    .room-badge {
        display: none;
    }

    .score-item {
        padding: 2px 6px;
    }

    .side-panel {
        flex-direction: column;
        border-left: 1px solid var(--border);
        border-top: none;
        max-height: none;
        overflow-y: auto;
        padding: var(--sp-2);
        gap: var(--sp-2);
    }

    .side-panel > * {
        min-width: auto;
        width: 100%;
    }

    .side-panel h3,
    .side-panel h4 {
        font-size: var(--fs-xs);
        margin-bottom: var(--sp-1);
    }

    .controls-info p {
        font-size: var(--fs-xs);
    }

    .game-arena {
        min-height: 200px;
        padding: 5px;
    }
}

/* Mobile portrait (height > width) - Rotate canvas */
@media (max-width: 768px) and (orientation: portrait) {
    body {
        overflow: hidden;
    }

    #gameContainer {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
    }

    .top-bar {
        padding: var(--sp-1) var(--sp-2);
        min-height: 45px;
        gap: var(--sp-1);
    }

    .game-info {
        gap: var(--sp-2);
    }

    .game-info h1 {
        font-size: var(--fs-md);
    }

    .game-mark { display: none; }

    .room-badge {
        display: none;
    }

    .score-display {
        gap: var(--sp-1);
    }

    .score-board {
        gap: var(--sp-1);
    }

    .score-item {
        padding: 2px 6px;
        font-size: var(--fs-xs);
    }

    .score-value {
        font-size: var(--fs-base);
    }

    .game-arena {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 10px;
        min-height: 50vh;
        flex: 1;
    }

    /* Portrait mode - canvas is rotated by JS */
    .game-arena.portrait-mode {
        min-height: 45vh;
    }

    #gameCanvas {
        /* Canvas dimensions and transform set by JS */
        display: block;
    }

    .side-panel {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        padding: var(--sp-2);
        gap: var(--sp-2);
        max-height: 25vh;
        overflow-y: auto;
        border-top: 1px solid var(--border);
        border-left: none;
        padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom, 0px));
    }

    .side-panel > * {
        flex: 1 1 45%;
        min-width: 100px;
    }

    .side-panel h3,
    .side-panel h4 {
        font-size: var(--fs-xs);
        width: 100%;
        justify-content: center;
        text-align: center;
        margin-bottom: var(--sp-1);
    }

    .controls-info {
        display: none; /* Hide controls info on small portrait to save space */
    }

    .leaderboard {
        font-size: var(--fs-xs);
    }

    .game-stats {
        font-size: var(--fs-xs);
        padding: var(--sp-2);
    }

    .stat-row {
        padding: 2px 0;
    }

    .side-panel .btn {
        flex: 1 1 45%;
        min-width: 80px;
        width: auto;
    }

    .control-panel {
        min-width: 260px;
        max-width: 95vw;
        padding: var(--sp-4);
        max-height: 80vh;
        overflow-y: auto;
    }

    .control-panel h2 {
        font-size: var(--fs-xl);
    }

    .control-panel p {
        font-size: var(--fs-sm);
        margin-bottom: var(--sp-4);
    }

    .game-settings label {
        font-size: var(--fs-sm);
    }

    .game-settings select {
        padding: var(--sp-2);
        font-size: var(--fs-sm);
    }

    .game-buttons .btn {
        min-width: 140px;
    }

    /* Goal overlay adjustments */
    .goal-overlay .goal-text {
        font-size: 2.5rem;
    }

    .goal-overlay .goal-scorer {
        font-size: var(--fs-base);
    }
}

/* Very small phones */
@media (max-width: 400px) {
    .top-bar {
        padding: var(--sp-1);
    }

    .game-info h1 {
        font-size: var(--fs-sm);
    }

    .score-item {
        padding: 1px 4px;
        font-size: 0.65rem;
    }

    .score-value {
        font-size: var(--fs-sm);
    }

    .side-panel {
        max-height: 20vh;
        padding: var(--sp-1);
        padding-bottom: calc(var(--sp-1) + env(safe-area-inset-bottom, 0px));
    }

    .side-panel h3,
    .side-panel h4 {
        font-size: 0.7rem;
    }
}

/* ============================================
   FULLSCREEN TOGGLE BUTTON (Mobile Only)
   ============================================ */

.fullscreen-toggle-btn {
    position: fixed;
    top: 120px; /* Below share button */
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: var(--r-pill);
    background: var(--overlay);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-strong);
    color: var(--accent-ink);
    cursor: pointer;
    z-index: 50000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
    box-shadow: var(--shadow-2);
}

.fullscreen-toggle-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
}

.fullscreen-toggle-btn:active {
    transform: scale(0.95);
}

.fullscreen-toggle-btn svg {
    width: 24px;
    height: 24px;
}

/* Fullscreen mode - hide side panel and expand game arena */
body.fullscreen-mode #gameContainer {
    grid-template-columns: 1fr;
}

body.fullscreen-mode .side-panel {
    display: none;
}

body.fullscreen-mode .top-bar {
    padding: var(--sp-2) var(--sp-3);
    min-height: 50px;
}

body.fullscreen-mode .game-info h1 {
    font-size: var(--fs-lg);
}

body.fullscreen-mode .game-arena {
    padding: var(--sp-2);
}

/* Only show fullscreen button on mobile/tablet */
@media (min-width: 769px) {
    .fullscreen-toggle-btn {
        display: none !important;
    }
}

/* Adjust position on smaller screens */
@media (max-width: 768px) and (orientation: portrait) {
    .fullscreen-toggle-btn {
        top: 80px;
        right: 12px;
        width: 44px;
        height: 44px;
    }

    .fullscreen-toggle-btn svg {
        width: 22px;
        height: 22px;
    }
}
