/* ===================================================================
   FIRELINE: Emergency Rescue — global UI + responsive + mobile controls
   =================================================================== */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    color: rgba(255, 255, 255, 0.92);
    background-color: #0a0c10;
    font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

#app {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

#game-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
#game-container canvas { display: block; touch-action: none; }

/* ---------------------------------------------------------------
   Overlay screens (menu / pause / results)
   --------------------------------------------------------------- */
.overlay-full {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: radial-gradient(circle at 50% 40%, rgba(20,24,32,0.82), rgba(4,6,10,0.94));
    backdrop-filter: blur(3px);
    animation: fadeIn 0.25s ease;
}
.overlay-center {
    position: absolute;
    inset: 0;
    z-index: 35;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.menu-panel {
    width: min(92vw, 420px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 26px 24px;
    text-align: center;
    border-radius: 18px;
    background: linear-gradient(160deg, rgba(28,32,42,0.96), rgba(14,16,22,0.98));
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 18px 50px rgba(0,0,0,0.6);
}
.menu-panel.panel-wide { width: min(96vw, 640px); }
.menu-panel h2 { margin: 0 0 16px; font-size: 1.5rem; letter-spacing: 0.5px; }

.game-title {
    margin: 0;
    font-size: clamp(2.2rem, 9vw, 3.4rem);
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(90deg, #ff6b35, #ffd23f);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.game-subtitle {
    margin: 2px 0 22px;
    font-size: 1rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #9fb0c0;
}

/* ---------------------------------------------------------------
   Buttons
   --------------------------------------------------------------- */
.btn {
    display: block;
    width: 100%;
    margin: 10px 0;
    padding: 13px 16px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #eaf0f6;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.2s ease, border-color 0.2s ease;
    touch-action: manipulation;
}
.btn:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.3); }
.btn:active { transform: scale(0.97); }
.btn-primary {
    color: #1a1206;
    background: linear-gradient(90deg, #ff6b35, #ffb03a);
    border-color: rgba(255,176,58,0.6);
    box-shadow: 0 6px 18px rgba(255,107,53,0.35);
}
.btn-primary:hover { background: linear-gradient(90deg, #ff7d4d, #ffbd55); }

.toggle {
    min-width: 64px;
    padding: 6px 14px;
    font-weight: 800;
    font-size: 0.85rem;
    color: #0a0c10;
    background: #6b7684;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s ease;
}
.toggle.on { background: linear-gradient(90deg, #2ecc71, #27ae60); }
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 12px 0;
    padding: 8px 4px;
    font-size: 1rem;
}

/* ---------------------------------------------------------------
   Level select
   --------------------------------------------------------------- */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 8px 0 18px;
}
.level-card {
    position: relative;
    padding: 14px 10px;
    text-align: center;
    color: #eaf0f6;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.2s ease;
}
.level-card:hover { background: rgba(255,255,255,0.1); }
.level-card:active { transform: scale(0.97); }
.level-card.level-locked { opacity: 0.45; cursor: not-allowed; }
.level-num { font-size: 0.75rem; letter-spacing: 1px; color: #9fb0c0; text-transform: uppercase; }
.level-name { font-size: 1rem; font-weight: 700; margin: 4px 0 6px; }
.level-stars { font-size: 0.95rem; letter-spacing: 2px; }
.level-best { font-size: 0.8rem; color: #ffd23f; margin-top: 4px; }
.level-lock { position: absolute; top: 8px; right: 10px; font-size: 1.1rem; }

/* ---------------------------------------------------------------
   Rules / results text
   --------------------------------------------------------------- */
.rules-list { text-align: left; margin: 0 0 14px; padding-left: 18px; line-height: 1.9; font-size: 0.95rem; }
.rules-list li { margin: 4px 0; }
kbd {
    display: inline-block;
    min-width: 22px;
    padding: 2px 7px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    color: #0a0c10;
    background: #dfe6ee;
    border-radius: 6px;
    border-bottom: 2px solid #a9b4c0;
    text-align: center;
}
.menu-panel p { font-size: 0.92rem; line-height: 1.6; color: #c3ccd6; margin: 10px 0; }
.mobile-note { color: #ffd23f !important; font-size: 0.9rem !important; }
.win-panel h2 { color: #2ecc71; }
.lose-panel h2 { color: #e74c3c; }
.win-stars { font-size: 2rem; letter-spacing: 6px; margin: 6px 0 14px; }
.win-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; font-size: 0.95rem; }
.win-stats div { padding: 8px; background: rgba(255,255,255,0.05); border-radius: 10px; }
.lose-reason { font-size: 1.05rem; color: #ff8a7a; }

.countdown-num {
    font-size: clamp(5rem, 26vw, 12rem);
    font-weight: 900;
    color: #ffd23f;
    text-shadow: 0 6px 30px rgba(0,0,0,0.7);
    animation: popIn 0.4s ease;
}
@keyframes popIn { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------------------------------------------------------------
   HUD (top bar)
   --------------------------------------------------------------- */
#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    pointer-events: none;
    font-size: 0.85rem;
}
#hud > div { display: flex; flex-direction: column; gap: 6px; }
.hud-left { align-items: flex-start; min-width: 120px; }
.hud-center { align-items: center; }
.hud-right { align-items: flex-end; min-width: 120px; }

.hud-bar { display: flex; align-items: center; gap: 6px; }
.hud-icon { font-size: 0.9rem; }
.bar-track {
    width: 110px;
    height: 12px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 8px;
    overflow: hidden;
}
.bar-fill { height: 100%; transition: width 0.15s linear; }
.bar-hp { background: linear-gradient(90deg, #e74c3c, #ff7b6b); }
.bar-water { background: linear-gradient(90deg, #3498db, #5dade2); }
.bar-stab-track { width: 150px; }
.bar-stab { background: linear-gradient(90deg, #2ecc71, #a3e4b8); }
.bar-stab-warn { background: linear-gradient(90deg, #e67e22, #f1c40f); }

.hud-timer { font-size: 1.5rem; font-weight: 800; letter-spacing: 1px; text-shadow: 0 2px 6px rgba(0,0,0,0.6); }
.hud-stability { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 0.72rem; color: #c3ccd6; }
.hud-obj { font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,0.7); }
.hud-keycard { color: #ffd23f; font-weight: 800; text-shadow: 0 1px 4px rgba(0,0,0,0.7); }
.hud-alert { color: #ff5252; font-weight: 800; font-size: 0.72rem; animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.hud-pause-btn {
    pointer-events: auto;
    width: 40px; height: 40px;
    font-size: 1.1rem;
    color: #fff;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 10px;
    cursor: pointer;
    touch-action: manipulation;
}
.hud-pause-btn:active { transform: scale(0.92); }

/* ---------------------------------------------------------------
   Mobile on-screen controls
   --------------------------------------------------------------- */
#mobile-controls {
    position: absolute;
    inset: 0;
    z-index: 25;
    pointer-events: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* transparent drag-aim layer (only this captures field touches) */
.aim-layer {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    touch-action: none;
}

/* Virtual joystick */
.joystick-base {
    position: absolute;
    left: calc(20px + env(safe-area-inset-left));
    bottom: calc(24px + env(safe-area-inset-bottom));
    width: 132px;
    height: 132px;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.10), rgba(255,255,255,0.03));
    border: 2px solid rgba(255,255,255,0.22);
    box-shadow: inset 0 0 18px rgba(0,0,0,0.4);
    pointer-events: auto;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.joystick-knob {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffb03a, #ff6b35);
    border: 2px solid rgba(255,255,255,0.5);
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    will-change: transform;
    pointer-events: none;
}

/* Action buttons */
.action-cluster {
    position: absolute;
    right: calc(20px + env(safe-area-inset-right));
    bottom: calc(24px + env(safe-area-inset-bottom));
    display: flex;
    align-items: flex-end;
    gap: 16px;
    pointer-events: none;
}
.action-btn {
    pointer-events: auto;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border-radius: 50%;
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    border: 2px solid rgba(255,255,255,0.35);
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.06s ease, box-shadow 0.12s ease;
}
.action-btn .action-label {
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 1px;
    opacity: 0.9;
}
.btn-spray {
    width: 96px; height: 96px;
    background: radial-gradient(circle at 40% 35%, #5dade2, #2471a3);
    box-shadow: 0 6px 18px rgba(36,113,163,0.5);
}
.btn-spray.active {
    transform: scale(0.94);
    box-shadow: 0 0 0 4px rgba(93,173,226,0.55), 0 6px 18px rgba(36,113,163,0.7);
}
.btn-interact {
    width: 76px; height: 76px;
    background: radial-gradient(circle at 40% 35%, #58d68d, #1e8449);
    box-shadow: 0 6px 18px rgba(30,132,73,0.5);
}
.btn-interact:active { transform: scale(0.92); }

/* ---------------------------------------------------------------
   Responsive tweaks
   --------------------------------------------------------------- */
@media (max-width: 600px) {
    #hud { font-size: 0.72rem; gap: 6px; padding-left: 8px; padding-right: 8px; }
    .bar-track { width: 78px; height: 10px; }
    .bar-stab-track { width: 96px; }
    .hud-timer { font-size: 1.15rem; }
    .hud-left, .hud-right { min-width: 88px; }
    .hud-obj { font-size: 0.72rem; }
    .menu-panel { padding: 20px 16px; }
    .level-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}

@media (max-width: 420px) {
    .joystick-base { width: 112px; height: 112px; }
    .joystick-knob { width: 50px; height: 50px; }
    .btn-spray { width: 82px; height: 82px; font-size: 1.5rem; }
    .btn-interact { width: 64px; height: 64px; font-size: 1.3rem; }
    .action-cluster { gap: 10px; }
}

/* Landscape phones: pull controls into the corners, shrink HUD */
@media (max-height: 460px) {
    .joystick-base { width: 104px; height: 104px; bottom: calc(10px + env(safe-area-inset-bottom)); }
    .joystick-knob { width: 46px; height: 46px; }
    .btn-spray { width: 74px; height: 74px; }
    .btn-interact { width: 58px; height: 58px; }
    .hud-center { display: none; }
}
