/* ===== Design Tokens ===== */
:root {
    --bg1: #ffe9f3;
    --bg2: #e7f0ff;
    --accent: #ff9ac2;
    --accent-dark: #e07aa8;
    --success: #50ff96;
    --success-dark: #2ecc71;
    --warning: #ffdc50;
    --danger: #ff5050;
    --text: #3a3a4a;
    --text-light: #8888a0;
    --card: rgba(255,255,255,0.85);
    --card-border: rgba(255,155,195,0.3);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 12px rgba(180,140,180,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(100,80,120,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(255,233,243,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(231,240,255,0.9));
}

/* ===== Typography ===== */
.title {
    font-size: clamp(24px, 6vw, 36px);
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 2px 8px rgba(255,154,194,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), #ffb8d9);
    color: #fff;
    box-shadow: 0 3px 12px rgba(255,154,194,0.35);
}

.btn-primary:active {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    box-shadow: 0 1px 6px rgba(255,154,194,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,240,248,0.95);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-dark), var(--success));
    color: #fff;
    box-shadow: 0 3px 12px rgba(50,255,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,200,220,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(50,255,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;
}

/* ===== 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(50,255,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,220,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;
}

/* ===== 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;
}

.status-sleeping { color: var(--danger); }
.status-awake { color: var(--success-dark); }

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

/* ===== Da Wire specific ===== */
.sweet-spot-label {
    text-align: center;
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 700;
    color: var(--success-dark);
    margin-bottom: 4px;
}

.grip-section {
    text-align: center;
}

.grip-label {
    font-size: clamp(14px, 3.5vw, 18px);
    font-weight: 700;
    color: var(--success-dark);
    margin-bottom: 8px;
}

/* ===== In and Out specific ===== */
.location-label {
    font-size: clamp(14px, 3.5vw, 18px);
    font-weight: 700;
    color: var(--text-light);
    text-align: center;
    padding: 6px 0;
}

/* ===== 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(50,255,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; }
