/* ===========================================
   Stack-it — paleta cozy/warm (mocha + terracota + sage)
   Inspiração: 2025 Mocha Mousse + ethereal warm
   =========================================== */

:root {
    /* Background gradients (height-as-time-of-day) */
    --bg-dawn: linear-gradient(180deg, #fde6c4 0%, #f5d3a0 100%);
    --bg-midday: linear-gradient(180deg, #b9e3f5 0%, #fdf0c8 100%);
    --bg-sunset: linear-gradient(180deg, #f5a872 0%, #c44d6f 100%);
    --bg-dusk: linear-gradient(180deg, #6a4a8c 0%, #2d1f4f 100%);
    --bg-starry: linear-gradient(180deg, #1a1a3e 0%, #0a0a1f 100%);

    /* Block colors (cream skin default) */
    --block-base: #f5e6d3;
    --block-top: #e8d2b5;
    --block-accent: #d4915f;
    --block-outline: #8b6f47;

    /* UI text */
    --text-primary: #2d1f1a;
    --text-secondary: #6b5544;
    --text-on-dark: #f5e6d3;

    /* Feedback */
    --accent-gold: #fbbf24;
    --accent-success: #84cc16;
    --accent-warn: #f59e0b;
    --accent-danger: #c2410c;

    /* Shadows */
    --shadow-soft: 0 8px 24px rgba(139, 111, 71, 0.2);
    --shadow-strong: 0 16px 48px rgba(45, 31, 26, 0.4);

    /* Sizes */
    --hud-height: 64px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Quicksand', system-ui, -apple-system, sans-serif;
    color: var(--text-primary);
    background: var(--bg-dawn);
    transition: background 1.2s ease;
}

body.world-midday { background: var(--bg-midday); }
body.world-sunset { background: var(--bg-sunset); }
body.world-dusk { background: var(--bg-dusk); color: var(--text-on-dark); }
body.world-starry { background: var(--bg-starry); color: var(--text-on-dark); }

/* ===========================================
   Loading screen
   =========================================== */

#loading {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dawn);
    z-index: 100;
}

.loader-box {
    text-align: center;
    padding: 32px;
    max-width: 320px;
}

.loader-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 24px;
    letter-spacing: -0.5px;
}

.loader-bar {
    width: 100%;
    height: 6px;
    background: rgba(139, 111, 71, 0.15);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

.loader-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent-warn), var(--accent-danger));
    border-radius: 3px;
    transition: width 0.3s ease;
    animation: loader-pulse 1.5s ease-in-out infinite;
}

@keyframes loader-pulse {
    0%, 100% { width: 30%; }
    50% { width: 80%; }
}

.loader-tip {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===========================================
   Game wrapper
   =========================================== */

#game-wrap {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
}

#game {
    flex: 1;
    width: 100%;
    overflow: hidden;
    position: relative;
}

#game canvas {
    display: block !important;
    width: auto !important;
    height: auto !important;
    max-height: calc(100dvh - var(--hud-height)) !important;
    margin: 0 auto !important;
    object-fit: contain;
}

/* ===========================================
   HUD
   =========================================== */

#hud {
    height: var(--hud-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: rgba(253, 230, 196, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 2px solid rgba(139, 111, 71, 0.2);
    box-shadow: 0 2px 12px rgba(45, 31, 26, 0.08);
    z-index: 10;
    flex-shrink: 0;
}

/* Em mundos escuros, HUD escuro com texto claro */
body.world-dusk #hud,
body.world-starry #hud {
    background: rgba(26, 26, 62, 0.95);
    border-bottom-color: rgba(245, 230, 211, 0.2);
}

#hud-left, #hud-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#height-box, #streak-box, #best-box, #coins-box {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(245, 230, 211, 0.6);
    border: 1px solid rgba(139, 111, 71, 0.15);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    box-shadow: var(--shadow-soft);
    transition: transform 0.15s ease, background 0.3s ease;
}

body.world-dusk #height-box,
body.world-dusk #streak-box,
body.world-dusk #best-box,
body.world-dusk #coins-box,
body.world-starry #height-box,
body.world-starry #streak-box,
body.world-starry #best-box,
body.world-starry #coins-box {
    background: rgba(245, 230, 211, 0.15);
    color: var(--text-on-dark);
    border-color: rgba(245, 230, 211, 0.2);
}

.hud-label {
    font-size: 11px;
    text-transform: uppercase;
    opacity: 0.7;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.hud-unit {
    font-size: 11px;
    opacity: 0.6;
}

#height-value, #streak-value, #best-value, #coins {
    font-family: 'Quicksand', monospace;
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

#height-box.pulse {
    animation: hud-pulse 0.4s ease-out;
}

@keyframes hud-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); background: rgba(251, 191, 36, 0.4); }
    100% { transform: scale(1); }
}

.streak-icon, .coin-icon {
    font-size: 16px;
}

.coin-icon {
    width: 16px;
    height: 16px;
    background: radial-gradient(circle, #fbbf24 0%, #d97706 100%);
    border-radius: 50%;
    box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(217, 119, 6, 0.4);
    display: inline-block;
}

#hud-right button {
    width: 38px;
    height: 38px;
    border: none;
    background: rgba(245, 230, 211, 0.6);
    border: 1px solid rgba(139, 111, 71, 0.15);
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    color: var(--text-primary);
}

#hud-right button:hover {
    background: rgba(245, 230, 211, 0.9);
    transform: translateY(-1px);
}

#hud-right button:active {
    transform: scale(0.95);
}

body.world-dusk #hud-right button,
body.world-starry #hud-right button {
    background: rgba(245, 230, 211, 0.15);
    color: var(--text-on-dark);
    border-color: rgba(245, 230, 211, 0.2);
}

/* ===========================================
   Tap hint (visível em mobile, fade-out)
   =========================================== */

#tap-hint {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(45, 31, 26, 0.7);
    color: var(--text-on-dark);
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 500;
    display: none; /* hidden por padrão; só Play scene mostra */
    align-items: center;
    gap: 6px;
    z-index: 20;
    pointer-events: none;
    animation: tap-hint-pulse 1.5s ease-in-out infinite;
}

#tap-hint.visible {
    display: flex;
}

#tap-hint.hidden {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.tap-hint-icon {
    font-size: 14px;
}

.tap-hint-icon {
    font-size: 18px;
}

@keyframes tap-hint-pulse {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-4px); }
}

/* ===========================================
   Milestone toast (aparece ao atingir novo mundo)
   =========================================== */

.milestone-toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: linear-gradient(135deg, rgba(212, 145, 95, 0.95) 0%, rgba(196, 77, 111, 0.95) 100%);
    color: #ffffff;
    padding: 14px 22px;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(45, 31, 26, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 30;
    pointer-events: none;
    animation: milestone-slide-in 0.5s ease-out forwards, milestone-glow 2s ease-in-out infinite;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.milestone-toast.fade-out {
    animation: milestone-fade-out 0.5s ease-in forwards;
}

.milestone-emoji {
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.milestone-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.milestone-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1;
}

.milestone-sub {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
}

@keyframes milestone-slide-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-40px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

@keyframes milestone-fade-out {
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px) scale(0.95);
    }
}

@keyframes milestone-glow {
    0%, 100% {
        box-shadow: 0 12px 32px rgba(45, 31, 26, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }
    50% {
        box-shadow: 0 12px 40px rgba(251, 191, 36, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
}

/* ===========================================
   Skin unlock toast (aparece quando desbloqueia nova skin)
   =========================================== */

.skin-unlock-toast {
    position: fixed;
    top: 160px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.96) 0%, rgba(251, 191, 36, 0.96) 100%);
    color: #ffffff;
    padding: 16px 26px;
    border-radius: 18px;
    box-shadow: 0 16px 40px rgba(45, 31, 26, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    text-align: center;
    z-index: 31;
    pointer-events: none;
    animation: skin-unlock-slide-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards, skin-unlock-glow 1.8s ease-in-out infinite;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    min-width: 240px;
}

.skin-unlock-toast.fade-out {
    animation: skin-unlock-fade-out 0.5s ease-in forwards;
}

.skin-unlock-header {
    font-family: 'Quicksand', sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
    opacity: 0.9;
}

.skin-unlock-name {
    font-family: 'Fredoka', sans-serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.skin-unlock-hint {
    font-family: 'Quicksand', sans-serif;
    font-size: 13px;
    opacity: 0.85;
    font-style: italic;
}

@keyframes skin-unlock-slide-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-60px) scale(0.7);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

@keyframes skin-unlock-fade-out {
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-30px) scale(0.95);
    }
}

@keyframes skin-unlock-glow {
    0%, 100% {
        box-shadow: 0 16px 40px rgba(45, 31, 26, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 0 20px 50px rgba(251, 191, 36, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }
}

/* ===========================================
   Skin Editor overlay (HTML form sobre canvas)
   =========================================== */

#skin-editor-overlay {
    position: fixed;
    top: 320px;
    left: 50%;
    transform: translateX(-50%);
    width: min(420px, 92%);
    background: rgba(245, 230, 211, 0.96);
    border: 2px solid rgba(139, 111, 71, 0.3);
    border-radius: 16px;
    padding: 18px 20px;
    box-shadow: 0 8px 24px rgba(45, 31, 26, 0.15);
    z-index: 25;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.se-row {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

.se-row:last-child {
    margin-bottom: 0;
}

.se-label {
    font-family: 'Quicksand', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 0 0 110px;
    text-align: right;
}

.se-input {
    flex: 1;
    padding: 8px 12px;
    border: 1.5px solid rgba(139, 111, 71, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
    font-family: 'Quicksand', sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    outline: none;
    transition: border-color 0.15s;
}

.se-input:focus {
    border-color: var(--accent-warn);
    background: rgba(255, 255, 255, 0.95);
}

.se-color {
    flex: 1;
    height: 36px;
    border: 1.5px solid rgba(139, 111, 71, 0.3);
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    padding: 2px;
}

.se-color::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 8px;
}

.se-color::-webkit-color-swatch {
    border: none;
    border-radius: 8px;
}

.se-import-row {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px dashed rgba(139, 111, 71, 0.25);
}

.se-import-wrap {
    flex: 1;
    display: flex;
    gap: 6px;
}

.se-code-input {
    flex: 1;
    text-transform: uppercase;
    font-family: 'Quicksand', monospace;
    letter-spacing: 1px;
}

.se-import-btn {
    width: 40px;
    height: 36px;
    border: 1.5px solid rgba(139, 111, 71, 0.3);
    border-radius: 10px;
    background: rgba(212, 145, 95, 0.9);
    color: white;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s;
}

.se-import-btn:hover {
    background: rgba(212, 145, 95, 1);
    transform: translateY(-1px);
}

.se-import-btn:active {
    transform: scale(0.95);
}

/* Skin Editor toasts */

.se-toast {
    position: fixed;
    top: 200px;
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 22px;
    border-radius: 14px;
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    z-index: 32;
    pointer-events: none;
    animation: se-toast-in 0.4s ease-out forwards;
    box-shadow: 0 8px 24px rgba(45, 31, 26, 0.3);
    color: #ffffff;
    max-width: 320px;
}

.se-toast-success {
    background: linear-gradient(135deg, #84cc16 0%, #65a30d 100%);
}

.se-toast-error {
    background: linear-gradient(135deg, #ef4444 0%, #c2410c 100%);
}

.se-toast.fade-out {
    animation: se-toast-out 0.4s ease-in forwards;
}

@keyframes se-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes se-toast-out {
    to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ===========================================
   Pause overlay (ESC ou botão home pausa)
   =========================================== */

#si-pause {
    position: fixed;
    inset: 0;
    background: rgba(45, 31, 26, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    animation: si-pause-fade-in 0.2s ease-out;
}

.si-pause-card {
    background: var(--block-base);
    border: 3px solid var(--accent-warn);
    border-radius: 20px;
    padding: 36px 44px;
    text-align: center;
    box-shadow: var(--shadow-strong);
    max-width: 320px;
    width: 90%;
}

.si-pause-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.si-pause-hint {
    font-family: 'Quicksand', sans-serif;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.si-pause-resume,
.si-pause-menu {
    display: block;
    width: 100%;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: 10px;
}

.si-pause-resume {
    background: var(--accent-warn);
    color: white;
    box-shadow: 0 4px 0 var(--accent-danger);
}

.si-pause-resume:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--accent-danger);
}

.si-pause-resume:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--accent-danger);
}

.si-pause-menu {
    background: rgba(139, 111, 71, 0.2);
    color: var(--text-primary);
}

.si-pause-menu:hover {
    background: rgba(139, 111, 71, 0.35);
}

@keyframes si-pause-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===========================================
   Privacy link (canto inferior, opacidade baixa)
   =========================================== */

#privacy-link {
    position: fixed;
    bottom: 6px;
    right: 8px;
    font-family: 'Quicksand', sans-serif;
    font-size: 9px;
    color: rgba(139, 111, 71, 0.4);
    text-decoration: none;
    z-index: 5;
    transition: color 0.2s;
}

#privacy-link:hover {
    color: rgba(139, 111, 71, 0.8);
}

/* ===========================================
   Mobile responsive
   =========================================== */

@media (max-width: 768px) {
    :root {
        --hud-height: 56px;
    }

    .loader-title {
        font-size: 28px;
    }

    #height-box, #streak-box, #best-box, #coins-box {
        padding: 4px 8px;
        font-size: 12px;
        gap: 4px;
    }

    .hud-label {
        display: none;
    }

    #height-value, #streak-value, #best-value, #coins {
        font-size: 16px;
    }

    #hud {
        padding: 0 12px;
    }

    #hud-right button {
        width: 34px;
        height: 34px;
    }
}
