:root {
    --ink: #2c2623;
    --sky-top: #b3e5f4;
    --sky-bottom: #dcf4fb;
    --grass-main: #5ec49e;
    --grass-dark: #3da37e;
    --cliff-main: #e59852;
    --cliff-dark: #c97732;
    --sign-green: #58b895;
    --sign-green-dark: #3e9676;
    --card-bg: rgba(255, 252, 245, 0.95);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Fredoka', 'Nunito', sans-serif;
    background: linear-gradient(135deg, #3c6382 0%, #1e3799 100%);
}

#app-shell {
    width: 100vw;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

#game-Stage {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 540px;
    max-height: 960px;
    aspect-ratio: 9 / 16;
    background: var(--sky-top);
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 0 4px var(--ink);
    border-radius: 22px;
}

@media (max-width: 600px), (max-height: 750px) {
    #game-Stage {
        max-width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
    }
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    touch-action: none;
}

.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.95);
}

/* ---- Top HUD ---- */
#hud-bar {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 20;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.hud-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    width: 100%;
}

.hud-left, .hud-right {
    display: flex;
    gap: 6px;
    pointer-events: auto;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 3px solid var(--ink);
    background: #fff9f0;
    box-shadow: 0 4px 0 var(--ink);
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    padding: 0;
}

.icon-btn:hover {
    background: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 5px 0 var(--ink);
}

.icon-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--ink);
}

.hud-center {
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    border-radius: 14px;
    padding: 4px 12px;
    min-width: 140px;
}

.level-badge {
    font-size: 14px;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: 0.4px;
}

.level-subtitle {
    font-size: 11px;
    font-weight: 700;
    color: #c86d25;
}

.stat-pill {
    border: 3px solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    border-radius: 12px;
    padding: 4px 9px;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #fff;
    min-width: 48px;
}

.fail-pill {
    background: #ff6b6b;
}

.coin-pill {
    background: #feca57;
    color: var(--ink);
}

.stat-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.6px;
}

#fail-count, #coin-count {
    font-size: 15px;
    font-weight: 900;
    line-height: 1.05;
}

#fail-count {
    text-shadow: 1.5px 1.5px 0 var(--ink);
}

/* ---- Journey Progress Bar ---- */
.progress-container {
    width: 100%;
    background: rgba(255, 255, 255, 0.88);
    border: 3px solid var(--ink);
    box-shadow: 0 3px 0 var(--ink);
    border-radius: 999px;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.prog-icon {
    font-size: 14px;
    line-height: 1;
}

.progress-track {
    position: relative;
    flex: 1;
    height: 10px;
    background: #dfe6e9;
    border-radius: 999px;
    border: 2px solid var(--ink);
    overflow: visible;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #5ec49e, #feca57);
    border-radius: 999px;
    transition: width 0.08s linear;
}

.checkpoint-marker {
    position: absolute;
    top: -10px;
    transform: translateX(-50%);
    font-size: 13px;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}

/* ---- Action Prompt ---- */
.action-prompt {
    position: absolute;
    top: 104px;
    left: 50%;
    transform: translateX(-50%);
    background: #ffeaa7;
    color: var(--ink);
    border: 3px solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    border-radius: 999px;
    padding: 6px 16px;
    font-size: 12.5px;
    font-weight: 800;
    white-space: nowrap;
    z-index: 22;
    animation: pulseBounce 0.6s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes pulseBounce {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.05); }
}

/* ---- Iconic Green Sign ("Fail = Try again ✅") ---- */
.green-sign-banner {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    z-index: 25;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.green-sign-banner.hidden {
    transform: translate(-50%, -50%) scale(0.7);
}

.green-sign-inner, .sign-logo {
    position: relative;
    background: var(--sign-green);
    border: 3.5px solid var(--ink);
    border-radius: 12px;
    padding: 12px 24px;
    color: #ffffff;
    font-size: clamp(18px, 4.5vw, 23px);
    font-weight: 800;
    letter-spacing: 0.5px;
    text-shadow: 1.5px 1.5px 0 rgba(0, 0, 0, 0.28);
    box-shadow: 0 6px 0 var(--ink), inset 0 0 0 3px rgba(255, 255, 255, 0.85);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.rivet {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #ffffff;
    border-radius: 50%;
    opacity: 0.9;
}
.rivet.tl { top: 7px; left: 7px; }
.rivet.tr { top: 7px; right: 7px; }
.rivet.bl { bottom: 7px; left: 7px; }
.rivet.br { bottom: 7px; right: 7px; }

/* ---- Touch Controls ---- */
.touch-controls {
    position: absolute;
    bottom: 18px;
    left: 16px;
    right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 20;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.dpad-group, .action-group {
    display: flex;
    gap: 12px;
    pointer-events: auto;
}

.ctrl-btn {
    width: 68px;
    height: 64px;
    border-radius: 18px;
    border: 3.5px solid var(--ink);
    background: rgba(255, 252, 245, 0.92);
    color: var(--ink);
    font-family: 'Fredoka', sans-serif;
    font-size: 24px;
    font-weight: 900;
    box-shadow: 0 6px 0 var(--ink);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.1s ease;
    touch-action: manipulation;
}

.ctrl-btn.jump-btn {
    width: 122px;
    background: #ffeaa7;
    font-size: 18px;
    letter-spacing: 0.5px;
}

.ctrl-btn:active, .ctrl-btn.pressed {
    transform: translateY(5px);
    box-shadow: 0 1px 0 var(--ink);
    background: #5ec49e;
    color: #fff;
}

/* ---- Overlay Screens ---- */
.overlay-screen {
    position: absolute;
    inset: 0;
    background: rgba(24, 38, 48, 0.38);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 30;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.menu-card {
    width: 100%;
    max-width: 400px;
    background: var(--card-bg);
    border: 4px solid var(--ink);
    border-radius: 26px;
    box-shadow: 0 12px 0 var(--ink), 0 24px 48px rgba(0, 0, 0, 0.3);
    padding: 24px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-title {
    margin: 14px 0 4px;
    font-size: clamp(34px, 8vw, 44px);
    font-weight: 900;
    color: #e59852;
    -webkit-text-stroke: 2px var(--ink);
    text-shadow: 0 4px 0 var(--ink);
    letter-spacing: 1.5px;
}

.win-heading {
    color: #5ec49e;
}

.game-tagline {
    margin: 0 0 18px;
    font-size: 14px;
    font-weight: 700;
    color: #4d443f;
    line-height: 1.35;
}

.menu-buttons {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.Cartoon-btn {
    width: 100%;
    padding: 13px 18px;
    border-radius: 16px;
    border: 3.5px solid var(--ink);
    box-shadow: 0 5px 0 var(--ink);
    font-family: 'Fredoka', sans-serif;
    font-size: 17px;
    font-weight: 800;
    color: #fff;
    text-shadow: 1.5px 1.5px 0 var(--ink);
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.12s ease;
    letter-spacing: 0.6px;
}

.Cartoon-btn:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
    box-shadow: 0 6px 0 var(--ink);
}

.Cartoon-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--ink);
}

.btn-green { background: #5ec49e; }
.btn-orange { background: #e59852; }
.btn-blue { background: #54a0ff; }
.btn-purple { background: #9b72f2; }

.btn-small {
    padding: 10px 14px;
    font-size: 14px;
}

.controls-hint {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 2px dashed rgba(44, 38, 35, 0.2);
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: #5c514b;
}

/* ---- Level Select Grid ---- */
.level-card {
    max-height: 86vh;
}

.section-title {
    margin: 0 0 4px;
    font-size: 28px;
    color: var(--ink);
    font-weight: 900;
}

.section-sub {
    margin: 0 0 12px;
    font-size: 13px;
    color: #6b5e57;
    font-weight: 700;
}

.level-grid {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    max-height: 48vh;
    overflow-y: auto;
    padding: 6px 4px 12px;
}

.lvl-btn {
    aspect-ratio: 1 / 1;
    border-radius: 14px;
    border: 3px solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    background: #5ec49e;
    color: #fff;
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 800;
    text-shadow: 1.5px 1.5px 0 var(--ink);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.lvl-btn.current {
    background: #e59852;
}

.lvl-btn.locked {
    background: #d5cfc7;
    color: #7d746d;
    text-shadow: none;
    cursor: not-allowed;
    opacity: 0.85;
}

.lvl-btn:not(.locked):active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--ink);
}

.level-card-footer {
    width: 100%;
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
