/* ===== Design Tokens (Warm Cozy Palette) ===== */
:root {
    --bg1: #fdf5ec;
    --bg2: #f5e6d3;
    --accent: #ff9966;
    --accent-dark: #e07744;
    --success: #7ecb7e;
    --success-dark: #4aa64a;
    --warning: #ffdc50;
    --danger: #ff5050;
    --text: #5c4033;
    --text-light: #8a7060;
    --card: rgba(255,255,255,0.85);
    --card-border: rgba(255,170,120,0.3);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 12px rgba(160,120,80,0.18);
    --font: 'Nunito', 'Baloo 2', system-ui, sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ===== Game Container ===== */
#game {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: 500px;
    overflow: hidden;
    background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 100%);
}

/* Desktop: phone-sized container */
@media (min-width: 900px) {
    #game {
        height: min(100dvh, 900px);
        border-radius: 24px;
        box-shadow: 0 8px 40px rgba(120,80,40,0.25);
        border: 1px solid var(--card-border);
    }
}

/* ===== Canvas Overlay ===== */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* ===== Screens ===== */
.screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    flex-direction: column;
    padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)) 16px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 2;
}

.screen.active {
    display: flex;
    opacity: 1;
}

.screen.fade-out {
    opacity: 0;
}

/* ===== Layout Zones ===== */
.screen-header {
    text-align: center;
    padding: 8px 0;
    flex-shrink: 0;
    background: linear-gradient(to bottom, var(--bg1), rgba(253,245,236,0.85));
}

.screen-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0;
}

.screen-actions {
    flex-shrink: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0 0 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: linear-gradient(to top, var(--bg2), rgba(245,230,211,0.9));
}

/* ===== Typography ===== */
.title {
    font-size: clamp(24px, 6vw, 36px);
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 2px 8px rgba(255,153,102,0.3);
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: clamp(14px, 3.5vw, 18px);
    color: var(--text-light);
    font-weight: 600;
}

.label {
    font-size: clamp(13px, 3vw, 16px);
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ===== Buttons ===== */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 52px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: clamp(15px, 3.8vw, 18px);
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.1s, box-shadow 0.1s, background-color 0.15s;
    -webkit-appearance: none;
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #ffb88a);
    color: #fff;
    box-shadow: 0 3px 12px rgba(255,153,102,0.35);
}

.btn-primary:active {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    box-shadow: 0 1px 6px rgba(255,153,102,0.25);
}

.btn-secondary {
    background: var(--card);
    color: var(--text);
    border: 2px solid var(--card-border);
    box-shadow: var(--shadow);
}

.btn-secondary:active {
    background: rgba(255,248,240,0.95);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-dark), var(--success));
    color: #fff;
    box-shadow: 0 3px 12px rgba(100,200,100,0.25);
}

.btn-danger {
    background: linear-gradient(135deg, #e04848, #ff7070);
    color: #fff;
    box-shadow: 0 3px 12px rgba(255,80,80,0.25);
}

.btn-ghost {
    background: transparent;
    color: var(--text-light);
    min-height: 44px;
    font-size: clamp(13px, 3.2vw, 15px);
}

.btn-ghost:active {
    background: rgba(255,180,140,0.15);
}

.btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Quest button states */
.btn-quest {
    justify-content: space-between;
}

.btn-quest.completed {
    background: rgba(255,255,255,0.7);
    border: 2px solid rgba(100,200,100,0.4);
    color: var(--success-dark);
}

.btn-quest.locked {
    background: rgba(200,200,210,0.4);
    color: #aaa;
    border: 2px solid rgba(200,200,210,0.3);
}

.quest-status {
    font-size: 0.85em;
    opacity: 0.8;
}

/* Two-column button row */
.btn-row {
    display: flex;
    gap: 10px;
}

.btn-row .btn {
    flex: 1;
}

/* Three-column button row (Laundry Leap) */
.btn-row-3 {
    display: flex;
    gap: 8px;
}

.btn-row-3 .btn {
    flex: 1;
    min-height: 56px;
    font-size: clamp(16px, 4vw, 20px);
}

/* ===== Energy Hearts ===== */
.energy-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    padding: 6px 0;
}

.energy-bar .heart {
    font-size: clamp(16px, 4vw, 22px);
    transition: opacity 0.3s, transform 0.3s;
}

.energy-bar .heart.empty {
    opacity: 0.25;
    filter: grayscale(1);
}

.energy-label {
    font-size: clamp(12px, 3vw, 15px);
    font-weight: 700;
    color: var(--accent);
    margin-left: 6px;
}

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow);
}

/* ===== Result Message ===== */
.result-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    border: 2px solid var(--card-border);
    box-shadow: var(--shadow);
    animation: popIn 0.25s ease;
}

.result-box.success {
    border-color: rgba(100,200,100,0.5);
}

.result-box.failure {
    border-color: rgba(255,80,80,0.3);
}

.result-text {
    font-size: clamp(15px, 3.8vw, 18px);
    font-weight: 700;
    margin-bottom: 12px;
}

/* ===== Progress Bar ===== */
.progress-bar {
    width: 100%;
    height: 14px;
    background: rgba(200,200,210,0.4);
    border-radius: 7px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-dark), var(--success));
    border-radius: 7px;
    transition: width 0.15s ease;
}

/* Temperature bar color variants */
.temp-hot .progress-fill { background: linear-gradient(90deg, #e07744, #ff9966); }
.temp-warm .progress-fill { background: linear-gradient(90deg, #e0c040, #ffdc50); }
.temp-cold .progress-fill { background: linear-gradient(90deg, #aaa, #ccc); }

/* Noise bar color variants */
.noise-safe .progress-fill { background: linear-gradient(90deg, #4aa64a, #7ecb7e); }
.noise-warn .progress-fill { background: linear-gradient(90deg, #e0c040, #ffdc50); }
.noise-danger .progress-fill { background: linear-gradient(90deg, #cc3030, #ff5050); }

/* ===== Status Indicators ===== */
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: clamp(13px, 3.2vw, 16px);
    font-weight: 600;
}

/* ===== Objective Banner ===== */
.objective {
    background: rgba(255,200,120,0.15);
    border: 1px solid rgba(255,180,80,0.3);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    text-align: center;
    font-size: clamp(13px, 3.2vw, 16px);
    font-weight: 700;
    color: #8a6020;
}

/* ===== D-pad grid for Ice Cream Headache ===== */
.dpad-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    max-width: 240px;
    margin: 0 auto;
}

.dpad-grid .btn {
    min-height: 52px;
    font-size: clamp(16px, 4vw, 20px);
    padding: 8px;
}

.dpad-grid .dpad-center {
    background: rgba(200,180,160,0.2);
    border: 2px dashed rgba(200,180,160,0.4);
    color: var(--text-light);
    font-size: clamp(11px, 2.8vw, 13px);
}

/* Hold-button visual feedback */
.btn.active-hold {
    transform: scale(0.93);
    background: rgba(255,153,102,0.2);
    border-color: var(--accent);
}

/* ===== Clue Display ===== */
.clue-box {
    background: rgba(255,250,230,0.95);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 14px 18px;
    text-align: center;
    font-size: clamp(14px, 3.5vw, 17px);
    font-weight: 600;
    color: var(--text);
    animation: popIn 0.25s ease;
}

.clue-attribution {
    font-size: clamp(12px, 3vw, 14px);
    color: var(--text-light);
    margin-top: 4px;
}

/* ===== Animations ===== */
@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes gentleBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes sparkle {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.1); }
}

.bob {
    animation: gentleBob 2s ease-in-out infinite;
}

/* ===== Completion Screen ===== */
.completion-title {
    font-size: clamp(28px, 7vw, 40px);
    font-weight: 800;
    color: var(--success-dark);
    text-shadow: 0 2px 12px rgba(100,200,100,0.3);
}

.completion-quest-name {
    font-size: clamp(18px, 4.5vw, 24px);
    color: var(--accent);
    font-weight: 700;
}

/* ===== Loading Screen ===== */
#loading-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
    background: linear-gradient(135deg, var(--bg1), var(--bg2));
}

#loading-screen .title {
    font-size: clamp(28px, 7vw, 42px);
}

#loading-screen.hidden {
    display: none;
}

.loading-dots {
    font-size: 24px;
    color: var(--accent);
    letter-spacing: 4px;
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.text-success { color: var(--success-dark); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-light); }
.mt-auto { margin-top: auto; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.gap-6 { gap: 6px; }
.hidden { display: none !important; }
