/* ============================================================
   style.css — Atari Combat v2.0
   Full dark retro aesthetic with all new UI elements
============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* ── Design tokens ───────────────────────────────────────── */
:root {
    --bg:           #111318;
    --surface:      #1a1e26;
    --surface2:     #222736;
    --border:       #2e3547;
    --accent:       #4CAF50;
    --accent2:      #F0B429;
    --danger:       #E53E3E;
    --text:         #e8eaf0;
    --text-dim:     #6b7280;
    --font:         'Press Start 2P', monospace;
    --radius:       4px;
    --glow-green:   0 0 12px rgba(76,175,80,0.5);
    --glow-gold:    0 0 12px rgba(240,180,41,0.5);
}

/* ── Base ─────────────────────────────────────────────────── */
html, body {
    width: 100%;
    height: 100%;
    background: var(--bg);
    font-family: var(--font);
    color: var(--text);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Prevent browser pan/zoom gestures at CSS level */
    touch-action: none;
    /* Prevent text selection on tap-hold */
    -webkit-user-select: none;
    user-select: none;
}

/* ── Game container ──────────────────────────────────────── */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 820px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

/* ── Canvas ──────────────────────────────────────────────── */
#game-canvas {
    background: #000;
    /* Fill available height; on mobile, leave room for HUD + controls */
    height: clamp(240px, 60vh, 580px);
    width: auto;
    aspect-ratio: 160 / 192;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    box-shadow: 0 0 0 3px var(--border), 0 0 32px rgba(0,0,0,0.8), var(--glow-green);
    border: none;
    touch-action: none;
    display: block;
    flex-shrink: 0;
}

/* ── Top UI bar ──────────────────────────────────────────── */
#ui-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    gap: 8px;
    font-size: 8px;
    color: var(--text);
    min-height: 32px;
    flex-shrink: 0;
    /* Frosted panel so text always has contrast */
    background: rgba(17, 19, 24, 0.92);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
}

#status-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

#status-text {
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 7px;
}

#mode-display {
    color: var(--accent2);
    font-size: 7px;
    white-space: nowrap;
    font-weight: bold;
    letter-spacing: 0.5px;
}

#scoreboard {
    font-size: 9px;
    color: var(--text);
    text-align: center;
    letter-spacing: 2px;
    flex: 1;
}

#status-bar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    flex: 1;
}

/* ── Ping indicator ──────────────────────────────────────── */
#ping-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
}

#ping-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #48BB78;
    flex-shrink: 0;
    transition: background 0.5s;
}

#ping-label {
    font-size: 5px;
    color: var(--text-dim);
}

/* ── Icon buttons (mute, pause, legend) ──────────────────── */
.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    width: 24px;
    height: 24px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s;
    padding: 0;
    line-height: 1;
}

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

.icon-btn:active {
    transform: scale(0.92);
}

/* ── Power-up HUD ────────────────────────────────────────── */
.powerup-hud {
    font-size: 11px;
    min-height: 16px;
    letter-spacing: 4px;
    color: var(--text);
    text-align: center;
}

/* ── Touch controls ──────────────────────────────────────── */
#touch-controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 16px;
    pointer-events: none;
    flex-shrink: 0;
}

#dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    pointer-events: auto;
}

.dpad-row {
    display: flex;
    gap: 4px;
}

.dpad-btn {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.07);
    border: 1.5px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.7);
    font-size: 18px;
    border-radius: var(--radius);
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}

#right-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.action-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(76,175,80,0.15);
    border: 2px solid rgba(76,175,80,0.5);
    color: rgba(76,175,80,0.9);
    font-family: var(--font);
    font-size: 9px;
    cursor: pointer;
    touch-action: none;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, border-color 0.1s, box-shadow 0.1s;
}

.action-btn:active, .action-btn.btn-active {
    background: rgba(76,175,80,0.35);
    border-color: var(--accent);
    box-shadow: var(--glow-green);
}

.dpad-btn.btn-active {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.6);
}

/* ── Volume slider ───────────────────────────────────────── */
.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 60px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    pointer-events: auto;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* ── Fullscreen overlay base ─────────────────────────────── */
.fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.82);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── Overlay card ────────────────────────────────────────── */
.overlay-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 340px;
    width: 100%;
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
    animation: slideUp 0.25s ease-out;
}

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

/* ── Landing screen ──────────────────────────────────────── */
.landing-card {
    text-align: center;
    gap: 20px;
}

.game-title {
    font-size: clamp(24px, 6vw, 40px);
    color: var(--accent);
    text-shadow: var(--glow-green);
    letter-spacing: 6px;
    animation: flicker 4s infinite;
}

@keyframes flicker {
    0%, 95%, 100% { opacity: 1; }
    96%           { opacity: 0.7; }
    97%           { opacity: 1; }
    98%           { opacity: 0.8; }
}

.game-subtitle {
    font-size: 8px;
    color: var(--text-dim);
    letter-spacing: 3px;
}

.landing-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

/* ── Lobby screen ────────────────────────────────────────── */
.lobby-card {
    gap: 14px;
}

.lobby-title {
    font-size: 12px;
    color: var(--accent);
    letter-spacing: 3px;
    text-align: center;
}

.lobby-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.lobby-field label {
    font-size: 7px;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.lobby-field input,
.lobby-field select {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 8px;
    padding: 8px 10px;
    border-radius: var(--radius);
    outline: none;
    width: 100%;
    transition: border-color 0.15s;
    /* Re-enable touch interaction for form fields */
    touch-action: auto;
    -webkit-user-select: text;
    user-select: text;
}

.lobby-field input::placeholder {
    color: var(--text-dim);
}

.lobby-field input:focus,
.lobby-field select:focus {
    border-color: var(--accent);
}

.lobby-field select option {
    background: var(--surface2);
}

.lobby-status-text {
    font-size: 7px;
    color: var(--text-dim);
    text-align: center;
    min-height: 12px;
}

.lobby-client-name {
    font-size: 8px;
    color: var(--accent);
    text-align: center;
    min-height: 12px;
}

/* ── Invite / QR panel ───────────────────────────────────── */
.invite-card {
    text-align: center;
}

#qr-code {
    background: #fff;
    padding: 10px;
    border-radius: var(--radius);
}

#qr-code img { display: block; }

.invite-hint {
    font-size: 6px;
    color: var(--text-dim);
}

.invite-link {
    font-size: 5px;
    color: var(--text-dim);
    word-break: break-all;
    max-width: 280px;
    text-align: center;
    line-height: 1.8;
}

.invite-expire {
    font-size: 5px;
    color: var(--accent2);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
    font-family: var(--font);
    font-size: 9px;
    padding: 12px 20px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    letter-spacing: 1px;
    width: 100%;
    transition: filter 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 4px 0 #2d7a31;
}

.btn-primary:hover  { filter: brightness(1.1); box-shadow: var(--glow-green); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #2d7a31; }

.btn-secondary {
    font-family: var(--font);
    font-size: 9px;
    padding: 12px 20px;
    background: transparent;
    color: var(--accent2);
    border: 1px solid var(--accent2);
    border-radius: var(--radius);
    cursor: pointer;
    letter-spacing: 1px;
    width: 100%;
    transition: background 0.15s, box-shadow 0.15s;
}

.btn-secondary:hover  { background: rgba(240,180,41,0.1); box-shadow: var(--glow-gold); }
.btn-secondary:active { transform: scale(0.97); }

/* ── Overlay text ────────────────────────────────────────── */
.overlay-big-text {
    font-size: 11px;
    color: var(--text);
    text-align: center;
    line-height: 1.5;
}

.overlay-sub-text {
    font-size: 7px;
    color: var(--text-dim);
    text-align: center;
    line-height: 2;
}

/* ── Keyboard legend modal ───────────────────────────────── */
.legend-card {
    position: relative;
    max-width: 380px;
    gap: 12px;
}

.legend-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    width: 24px;
    height: 24px;
    border-radius: var(--radius);
    cursor: pointer;
    line-height: 1;
}

.legend-section {
    font-size: 8px;
    color: var(--accent2);
    letter-spacing: 2px;
    margin-top: 4px;
}

.legend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 6px;
    color: var(--text-dim);
}

.legend-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
}

.legend-table td:first-child {
    color: var(--text);
    white-space: nowrap;
}

/* ── Disconnect overlay ──────────────────────────────────── */
#disconnect-counter {
    color: var(--accent2);
}

/* ── Media: hide touch controls on desktop ───────────────────── */
@media (hover: hover) and (pointer: fine) {
    #touch-controls  { display: none; }
    #keyboard-hints  { display: flex; }
    #game-canvas {
        height: clamp(420px, 82vh, 640px);
    }
}

/* ── Keyboard hints (desktop only) ──────────────────────────── */
#keyboard-hints {
    display: none; /* shown only on desktop via media query above */
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 20px;
    padding: 6px 0 2px;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#keyboard-hints:hover { opacity: 1; }

.kb-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.kb-row {
    display: flex;
    gap: 3px;
    justify-content: center;
}

.kb-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-bottom: 3px solid rgba(0,0,0,0.5);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 6px;
    color: var(--text);
    white-space: nowrap;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
    cursor: default;
    user-select: none;
}

.kb-key.kb-arrow {
    min-width: 26px;
    font-size: 10px;
    font-family: system-ui, sans-serif; /* arrows render better in system font */
}

.kb-key.kb-space {
    min-width: 70px;
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.kb-label {
    font-family: var(--font);
    font-size: 5px;
    color: var(--text-dim);
    text-align: center;
    letter-spacing: 0.5px;
}


/* ── Media: narrow mobile — hide status label, keep scoreboard ── */
@media (max-width: 420px) {
    #status-text { display: none; }
    #mode-display { display: none; }
}

/* ── Media: very small screens ──────────────────────────────── */
@media (max-height: 580px) {
    #game-canvas { height: 60vh; }
    .dpad-btn    { width: 40px; height: 40px; font-size: 15px; }
    .action-btn  { width: 64px; height: 64px; font-size: 8px; }
}

/* ── 404 page ────────────────────────────────────────────── */
.page-404 {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 20px;
    text-align: center;
    padding: 20px;
}

.page-404 h1 { font-size: 32px; color: var(--accent); }
.page-404 p  { font-size: 9px;  color: var(--text-dim); }
.page-404 a  { color: var(--accent2); font-size: 8px; }

/* ── Leaderboard overlay ─────────────────────────────────────── */
.leaderboard-card {
    width: min(620px, 98vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 20px 20px 16px;
    overflow: hidden;
}

.lb-header {
    text-align: center;
}

.lb-title {
    font-size: 14px;
    margin-bottom: 2px;
}

.lb-subtitle {
    font-size: 6px;
    color: var(--text-dim);
    letter-spacing: 1px;
}

/* Win / lose result banner */
.lb-result-banner {
    text-align: center;
    font-size: 9px;
    padding: 6px 10px;
    border-radius: var(--radius);
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.lb-result-banner.win  { background: rgba(76,175,80,0.18); color: var(--accent); border: 1px solid rgba(76,175,80,0.4); }
.lb-result-banner.lose { background: rgba(229,62,62,0.15);  color: #ff6b6b;        border: 1px solid rgba(229,62,62,0.3); }

/* Scrollable table wrapper */
.lb-table-wrap {
    overflow-y: auto;
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 7px;
    font-family: var(--font);
}

.lb-table thead {
    position: sticky;
    top: 0;
    background: var(--surface2);
    z-index: 1;
}

.lb-table th {
    padding: 6px 6px;
    text-align: left;
    color: var(--text-dim);
    font-size: 6px;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.lb-table td {
    padding: 5px 6px;
    border-bottom: 1px solid rgba(46,53,71,0.5);
    color: var(--text);
    white-space: nowrap;
}

.lb-table td:last-child {
    white-space: normal;
    min-width: 120px;
}

.lb-table tbody tr:last-child td { border-bottom: none; }

.lb-table tbody tr:hover { background: rgba(255,255,255,0.03); }

/* Current player's entry — gold highlight */
.lb-table tbody tr.lb-me td {
    background: rgba(240,180,41,0.12);
    color: var(--accent2);
    font-weight: bold;
}
.lb-table tbody tr.lb-me td:first-child { border-left: 2px solid var(--accent2); }

/* Rank column */
.lb-rank { text-align: center; min-width: 28px; }

/* Mode + badge column */
.lb-badge {
    font-size: 10px;
    margin-right: 3px;
}

.lb-loading {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
    font-size: 7px;
}

.lb-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
    font-size: 7px;
}

/* Score formula note */
.lb-score-note {
    font-size: 5px;
    color: var(--text-dim);
    text-align: center;
    letter-spacing: 0.3px;
    padding: 0 4px;
}

/* Action buttons */
.lb-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-shrink: 0;
}

.lb-actions .btn-primary,
.lb-actions .btn-secondary {
    flex: 1;
    max-width: 160px;
}
