:root {
    --primary: #4ade80;
    --primary-hover: #22c55e;
    --text: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    font-family: 'Outfit', sans-serif;
    color: var(--text);
    background-color: #0d1b2a;
    overflow: hidden;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh; /* fallback */
    height: 100dvh; /* dynamic viewport: excludes iOS browser chrome */
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    transition: opacity 0.5s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 3rem;
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 650px;
    transform: translateY(0);
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

h1 {
    font-size: 4rem;
    font-weight: 900;
    line-height: 1.1;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #fff, #9ca3af);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    color: #e5e7eb;
    line-height: 1.5;
}

.help-section {
    display: flex;
    justify-content: space-around;
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    gap: 2rem;
}

.help-col h3 {
    font-size: 1.2rem;
    margin-bottom: 0.8rem;
    color: var(--primary);
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.help-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-col li {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #e5e7eb;
}

.help-col b {
    color: #fff;
    display: inline-block;
    width: 65px;
}

.item-list li {
    display: flex;
    align-items: center;
}

.item-list canvas {
    width: 1em;
    height: 1em;
    margin-right: 0.5rem;
    vertical-align: middle;
}

.btn {
    background: var(--primary);
    color: #064e3b;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    border-radius: 99px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.4);
    pointer-events: auto;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5);
}

.btn:active {
    transform: translateY(1px);
}

#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#hud.hidden {
    opacity: 0;
}

.left-hud {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.altitude-box, .time-box {
    font-size: 3rem;
    font-weight: 900;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-variant-numeric: tabular-nums; /* Prevents jumping width on varying digits */
}

.time-box {
    font-size: 2rem; /* Make time slightly smaller than altitude */
    color: #e5e7eb;
}

.unit {
    font-size: 1.5rem;
    font-weight: 400;
    color: #f3f4f6;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.score-box {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 1rem 2rem;
    border-radius: 16px;
    font-size: 3rem;
    font-weight: 900;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
    display: flex;
    align-items: baseline;
    gap: 1rem;
    align-self: flex-start;
}

.coin-icon {
    width: 32px;
    height: 32px;
    background: radial-gradient(circle at 30% 30%, #fde047, #f59e0b, #b45309);
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(245, 158, 11, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.8);
    position: relative;
    border: 2px solid #fbbf24;
    display: inline-block;
    vertical-align: middle;
}

.coin-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 18px;
    height: 18px;
    border: 2px solid #d97706;
    border-radius: 50%;
}

/* ===== GAME-OVER PANEL ===== */
.game-over-panel {
    max-width: 640px;
    width: 90vw;
    padding: 2rem 2.5rem;
    animation: none; /* no float animation on wide panel */
}

/* ===== NAME INPUT ===== */
.name-input-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.name-input {
    flex: 1;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 99px;
    padding: 0.6rem 1.2rem;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    user-select: text;
}

.name-input::placeholder { color: rgba(255,255,255,0.45); }
.name-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74,222,128,0.25);
}

.btn-save {
    background: rgba(74,222,128,0.2);
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.6rem 1.4rem;
    font-size: 0.95rem;
    white-space: nowrap;
}
.btn-save:hover {
    background: var(--primary);
    color: #064e3b;
}

.save-status {
    font-size: 0.85rem;
    margin: 0 0 0.75rem;
    min-height: 1.2em;
    color: var(--primary);
}

/* ===== HIGHSCORE TABLE ===== */
.hs-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
    color: #fbbf24;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.hs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.hs-table th {
    padding: 0.35rem 0.6rem;
    color: rgba(255,255,255,0.5);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

.hs-table td {
    padding: 0.4rem 0.6rem;
    color: #e5e7eb;
}

.hs-table tbody tr:nth-child(odd)  { background: rgba(255,255,255,0.05); }
.hs-table tbody tr:nth-child(even) { background: transparent; }

.hs-table tbody tr.hs-highlight td {
    color: #fbbf24;
    font-weight: 700;
}

.hs-loading {
    text-align: center;
    color: rgba(255,255,255,0.4);
    padding: 0.75rem 0;
}

/* ===== SCREEN SCROLLING (mobile) ===== */
.screen {
    overflow-y: auto;
    touch-action: pan-y;
}

/* ===== TOUCH CONTROLS ===== */
#touch-controls {
    position: fixed; /* fixed to actual visible viewport, not container */
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 1rem 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 1.5rem));
    pointer-events: auto;
    z-index: 20;
}

#touch-controls.hidden {
    display: none;
}

.touch-group {
    display: flex;
    gap: 0.6rem;
}

.touch-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1.1;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: background 0.1s ease, border-color 0.1s ease, transform 0.1s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.touch-btn small {
    font-size: 0.6rem;
    font-weight: 600;
    opacity: 0.75;
    letter-spacing: 0.03em;
}

.touch-btn.touch-btn-action {
    background: rgba(74, 222, 128, 0.1);
    border-color: rgba(74, 222, 128, 0.35);
}

.touch-btn:active,
.touch-btn.active {
    background: rgba(74, 222, 128, 0.3);
    border-color: var(--primary);
    transform: scale(0.92);
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 600px) {
    .glass-panel {
        padding: 1.5rem 1.25rem;
        margin: 0.5rem;
        border-radius: 16px;
        animation: none; /* disable float on mobile */
    }

    h1 { font-size: 2.8rem; }
    h2 { font-size: 1.6rem; }
    p  { font-size: 0.95rem; margin-bottom: 1.25rem; }

    .help-section {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .screen {
        justify-content: flex-start;
        padding-top: 1rem;
        padding-bottom: 160px; /* room for touch controls */
    }

    .altitude-box { font-size: 2.2rem; }
    .time-box     { font-size: 1.6rem; }
    .score-box    { font-size: 2rem; padding: 0.6rem 1rem; }
    .unit         { font-size: 1.2rem; }

    #hud { padding: 1rem; }

    .game-over-panel { padding: 1.25rem; }

    .hs-table { font-size: 0.8rem; }
    .hs-table th, .hs-table td { padding: 0.3rem 0.4rem; }
}

/* Hide touch controls on desktop (mouse/trackpad) */
@media (pointer: fine) {
    #touch-controls { display: none !important; }
}
