/* DOM layer over the canvas (js/ui/ui.js). Units are design pixels of the
   540-wide stage, which is scaled to the canvas. */

@font-face {
    font-family: "Super Bouncer";
    src: url("../data/fnt/Super%20Bouncer.ttf") format("truetype");
    font-display: swap;
}

:root {
    --wood: #8a4d22;
    --wood-dark: #5b2f12;
    --cream: #fdf1d6;
    --ink: #4a2a12;
    --ink-soft: #7a5233;
    --acc: #f59a23;       /* primary action (orange) */
    --green: #5fbf2f;     /* rewarded ads only */
    --gold: #ffc63d;      /* coins and score only */
    --danger: #e2483a;
}

#ui {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10;
    pointer-events: none;
    overflow: hidden;
    font-family: "Super Bouncer", "Trebuchet MS", system-ui, sans-serif;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
}

#ui *,
#ui *::before,
#ui *::after { box-sizing: border-box; }

#ui .stage {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
}

#ui .hud,
#ui .modals,
#ui .toasts {
    position: absolute;
    inset: 0;
}

:where(#ui) button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    pointer-events: auto;
    border: 0;
    background: none;
    padding: 0;
}

:where(#ui) button:disabled { cursor: default; }
:where(#ui) button:focus-visible { outline: 4px solid #fff; outline-offset: 3px; border-radius: 16px; }

.ic {
    width: 1em;
    height: 1em;
    vertical-align: -0.14em;
    flex: none;
    --acc: var(--gold);
}

/* ------------------------------------------------------------- modals */

.modal {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal .backdrop {
    position: absolute;
    inset: 0;
    background: rgba(28, 14, 4, 0.62);
    opacity: 0;
    transition: opacity 0.2s;
}

.modal.show .backdrop { opacity: 1; }

.panel {
    position: relative;
    background: center / 100% 100% no-repeat;
    transform: scale(0.82) translateY(24px);
    opacity: 0;
    transition: transform 0.26s cubic-bezier(0.2, 1.4, 0.4, 1), opacity 0.18s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal.show .panel { transform: none; opacity: 1; }

.panel-big {
    width: 470px;
    height: 720px;
    background-image: url("../ui/panel.webp");
    padding: 238px 66px 58px;
}

.panel-small {
    width: 460px;
    height: 544px;
    background-image: url("../ui/panel-small.webp");
    padding: 124px 56px 60px 48px;
}

.panel-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 32px;
    white-space: nowrap;
    text-shadow: 0 3px 0 var(--wood-dark), 0 0 6px rgba(60, 25, 5, 0.6);
    letter-spacing: 0.5px;
}

.panel-big .panel-title { top: 122px; }
.panel-small .panel-title { top: 38px; font-size: 30px; }

.panel-close {
    position: absolute;
    width: 74px;
    height: 72px;
    background: url("../ui/btn-close.webp") center / contain no-repeat;
}

.panel-small .panel-close { right: 30px; top: 50px; background: none; width: 92px; height: 92px; }
.panel-big .panel-close { right: -6px; top: 40px; }

.panel-body {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-height: 0;
}

/* ------------------------------------------------------------- buttons */

.btn {
    position: relative;
    width: 300px;
    height: 125px;
    margin: -14px 0;
    background: center / contain no-repeat;
    color: #fff;
    font-size: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.08s, filter 0.15s;
}

.btn span {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: -4px;
    text-shadow: 0 2px 0 rgba(80, 30, 0, 0.55);
    white-space: nowrap;
}

.btn:active:not(:disabled) { transform: scale(0.95); }
.btn:disabled { filter: grayscale(0.9) brightness(0.9); opacity: 0.75; }

.btn-orange { background-image: url("../ui/btn-orange.webp"); }
.btn-green { background-image: url("../ui/btn-green.webp"); }
.btn-green span { text-shadow: 0 2px 0 rgba(20, 70, 0, 0.6); }
.btn.small { width: 230px; height: 96px; font-size: 26px; margin: -10px 0; }
.btn .ic { width: 32px; height: 32px; --acc: #fff; }
.btn.small .ic { width: 28px; height: 28px; }

.btn-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-top: auto;
}

.link-btn {
    font-size: 22px;
    color: var(--ink-soft);
    padding: 12px 22px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
}

.link-btn:active { background: rgba(122, 82, 51, 0.12); }
.link-btn .ic { width: 24px; height: 24px; }

/* ------------------------------------------------------------- settings */

.settings .panel-body { justify-content: center; gap: 26px; }

.slider-row {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.slider-label { font-size: 24px; display: inline-flex; gap: 10px; align-items: center; }
.slider-label .ic { width: 28px; height: 28px; --acc: var(--acc); }

.slider-row input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 300px;
    height: 34px;
    background: transparent;
    cursor: pointer;
    --v: 100%;
}

.slider-row input[type=range]::-webkit-slider-runnable-track {
    height: 22px;
    border-radius: 11px;
    background: linear-gradient(#8ee04a, #4fae1e) 0 0 / var(--v) 100% no-repeat, #2b2b2b;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.45), 0 0 0 3px #7a4a22;
}

.slider-row input[type=range]::-moz-range-track {
    height: 22px;
    border-radius: 11px;
    background: linear-gradient(#8ee04a, #4fae1e) 0 0 / var(--v) 100% no-repeat, #2b2b2b;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.45), 0 0 0 3px #7a4a22;
}

.slider-row input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 44px;
    height: 44px;
    margin-top: -11px;
    border: 0;
    background: url("../ui/slider-knob.webp") center / contain no-repeat;
}

.slider-row input[type=range]::-moz-range-thumb {
    width: 44px;
    height: 44px;
    border: 0;
    background: url("../ui/slider-knob.webp") center / contain no-repeat;
}

.version { font-size: 15px; color: var(--ink-soft); opacity: 0.7; }

.howto .panel-body { justify-content: center; }
.howto-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; text-align: left; }
.howto-list li { display: flex; gap: 14px; align-items: center; font-size: 20px; line-height: 1.25; }
.howto-list .ic { width: 38px; height: 38px; color: var(--wood); --acc: var(--gold); }

/* ------------------------------------------------------------- achievements */

.achievements .panel-body { padding-top: 0; }
.ach-summary { font-size: 20px; color: var(--ink-soft); margin: -6px 0 10px; }

.ach-list {
    list-style: none;
    margin: 0;
    padding: 2px 6px 10px;
    width: 100%;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    pointer-events: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    mask-image: linear-gradient(transparent, #000 10px, #000 calc(100% - 18px), transparent);
}

.ach {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    background: #fff8e6;
    border: 3px solid #e7c999;
    border-radius: 18px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.ach.done { background: #eef8dc; border-color: #b8dc8a; }
.ach-icon {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    flex: none;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 35% 30%, #c97a3a, var(--wood));
    color: #fff;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

.ach.done .ach-icon { background: radial-gradient(circle at 35% 30%, #8fd65a, #4e9e22); }
.ach-icon .ic { width: 26px; height: 26px; --acc: var(--gold); }
.ach-main { flex: 1; min-width: 0; }
.ach-title { font-size: 19px; line-height: 1.1; }
.ach-desc { font-size: 14px; color: var(--ink-soft); margin: 2px 0 6px; line-height: 1.2; }
.ach-bar { height: 8px; border-radius: 4px; background: #ead6b4; overflow: hidden; }
.ach-bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffb340, #f08a1c); border-radius: 4px; }
.ach.done .ach-bar i { background: linear-gradient(90deg, #8fd65a, #4e9e22); }
.ach-side { text-align: right; flex: none; }
.ach-prog { font-size: 15px; color: var(--ink-soft); }
.ach-reward { font-size: 17px; color: #a86a00; display: inline-flex; gap: 4px; align-items: center; margin-top: 4px; }

/* ------------------------------------------------------------- toasts */

.toasts { display: flex; flex-direction: column; align-items: center; padding-top: 170px; gap: 10px; }

.toast {
    max-width: 440px;
    padding: 14px 24px;
    border-radius: 22px;
    background: var(--cream);
    border: 4px solid var(--wood);
    box-shadow: 0 6px 0 var(--wood-dark), 0 10px 24px rgba(0, 0, 0, 0.3);
    font-size: 21px;
    text-align: center;
    opacity: 0;
    transform: translateY(-16px) scale(0.95);
    transition: opacity 0.2s, transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.toast.show { opacity: 1; transform: none; }

.ach-toast { display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 18px 10px 12px; }
.ach-kicker { font-size: 14px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 1px; }
.ach-toast .ach-title { font-size: 21px; }
.ach-toast .ach-reward { font-size: 20px; margin: 0 0 0 6px; }

/* ------------------------------------------------------------- shop */

.shop .panel-body, .locked .panel-body, .revive .panel-body { justify-content: flex-start; }
.shop-art { width: 120px; height: 120px; object-fit: contain; margin-top: -6px; filter: drop-shadow(0 4px 0 rgba(90, 45, 10, 0.35)); }
.shop-desc { font-size: 20px; line-height: 1.25; margin: 8px 10px 4px; }
.shop-stock { font-size: 17px; color: var(--ink-soft); margin: 4px 0 0; display: flex; align-items: center; gap: 5px; }
.shop-stock .ic { width: 20px; height: 20px; }
.shop-hint { font-size: 15px; color: var(--ink-soft); margin: 2px 0 0; }

/* ------------------------------------------------------------- revive */

.revive .panel-body { justify-content: flex-start; }
.revive-text { font-size: 22px; line-height: 1.3; margin: 6px 8px 18px; }

.revive-ring { position: relative; width: 130px; height: 130px; margin: 0 0 8px; --dur: 6s; }
.revive-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.revive-ring circle {
    fill: #fff8e6;
    stroke: var(--acc);
    stroke-width: 9;
    stroke-linecap: round;
    stroke-dasharray: 277;
    stroke-dashoffset: 0;
    animation: ring var(--dur) linear forwards;
}

.revive.paused .revive-ring circle { animation-play-state: paused; }
.revive-ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; color: var(--wood); }

@keyframes ring { to { stroke-dashoffset: 277; } }

/* ------------------------------------------------------------- result */

.result .panel-body { justify-content: flex-start; }
.score-label { font-size: 17px; color: var(--ink-soft); margin-top: -10px; }
.score-big {
    font-size: 64px;
    line-height: 1;
    color: var(--gold);
    -webkit-text-stroke: 3px #9a5a00;
    paint-order: stroke fill;
    text-shadow: 0 4px 0 #9a5a00;
    margin: 2px 0 6px;
}

.best { font-size: 20px; display: inline-flex; gap: 6px; align-items: center; }
.best .ic { width: 24px; height: 24px; }

.ribbon {
    position: absolute;
    top: 84px;
    left: 50%;
    width: 360px;
    height: 125px;
    transform: translateX(-50%) rotate(-3deg);
    background: url("../ui/ribbon.webp") center / contain no-repeat;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 30px;
    text-shadow: 0 3px 0 #a14a00;
    animation: pop 0.5s 0.15s cubic-bezier(0.2, 1.6, 0.4, 1) both;
    pointer-events: none;
}

.ribbon span { margin-top: 16px; display: inline-flex; gap: 8px; align-items: center; }
.ribbon .ic { width: 30px; height: 30px; }
.result.record .panel-title { visibility: hidden; }

@keyframes pop { from { transform: translateX(-50%) rotate(-3deg) scale(0.3); opacity: 0; } }

.biggest { display: flex; align-items: center; gap: 8px; font-size: 17px; margin-top: 4px; color: var(--ink-soft); }
.biggest img { width: 36px; height: 36px; object-fit: contain; }
.biggest b { color: var(--ink); font-weight: normal; }

.coin-box {
    margin-top: 10px;
    width: 100%;
    min-height: 74px;
    background: #fff8e6;
    border: 3px solid #e7c999;
    border-radius: 18px;
    padding: 0 4px 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.coin-box:has(> :only-child) { justify-content: center; padding: 0; }
.coin-box .btn.small { width: 200px; height: 84px; font-size: 24px; margin: -6px -8px; }

.coin-earned { font-size: 24px; display: inline-flex; gap: 6px; align-items: center; color: #9a5a00; }
.coin-earned .ic { width: 30px; height: 30px; }
.coin-earned b { font-weight: normal; color: var(--ink); }

.goal { font-size: 16px; color: var(--ink-soft); margin-top: 10px; display: inline-flex; gap: 6px; align-items: center; }
.goal.good { color: #3f8a12; font-size: 18px; }
.goal .ic { width: 20px; height: 20px; flex: none; }

.result .btn-col { margin-top: auto; }

/* ------------------------------------------------------------- locked world */

.world-thumb { position: relative; width: 300px; height: 150px; border-radius: 18px; overflow: hidden; border: 4px solid var(--wood); box-shadow: 0 4px 0 var(--wood-dark); }
.world-thumb img { width: 100%; height: 100%; object-fit: cover; filter: saturate(0.5) brightness(0.75); }
.lock-badge { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.lock-badge .ic { width: 60px; height: 60px; --acc: var(--gold); filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.4)); }
.locked-text { font-size: 19px; line-height: 1.25; margin: 12px 6px 8px; }
.progress { position: relative; width: 300px; height: 28px; border-radius: 14px; background: #ead6b4; overflow: hidden; box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.2); }
.progress i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #ffb340, #f08a1c); }
.progress span { position: relative; font-size: 16px; line-height: 28px; color: var(--ink); }

/* ------------------------------------------------------------- HUD */

.hud > * { position: absolute; display: none; }
.hud[data-scene="Gameplay"] .next,
.hud[data-scene="Gameplay"] .skill-badge,
.hud[data-scene="Gameplay"] .skill-banner,
.hud[data-scene="Gameplay"] .danger,
.hud[data-scene="Gameplay"] .tutorial,
.hud[data-scene="Maps"] .map-home { display: block; }

.next { left: 12px; top: 166px; width: 82px; text-align: center; }
.next-label {
    font-size: 15px;
    color: #fff;
    text-shadow: 0 2px 0 var(--wood-dark), 0 0 4px rgba(60, 25, 5, 0.7);
    margin-bottom: 3px;
}

.next-frame {
    width: 76px;
    height: 76px;
    margin: 0 auto;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 40%, #fff8e6 55%, #f0d9ad);
    border: 5px solid var(--wood);
    box-shadow: 0 4px 0 var(--wood-dark), inset 0 3px 6px rgba(90, 45, 10, 0.25);
    display: grid;
    place-items: center;
    transition: transform 0.2s;
}

.next.bump .next-frame { transform: scale(1.12); }
.next-frame img { width: 54px; height: 54px; object-fit: contain; }
.next-frame img:not([src]), .next-frame img[src=""] { visibility: hidden; }

.skill-badge {
    left: 462px;
    min-width: 28px;
    height: 28px;
    padding: 0 7px;
    border-radius: 14px;
    background: var(--cream);
    border: 3px solid var(--wood);
    font-size: 17px;
    line-height: 22px;
    text-align: center;
    color: var(--ink);
    box-shadow: 0 2px 0 var(--wood-dark);
    pointer-events: none;
}

.skill-badge.empty { background: var(--acc); color: #fff; border-color: #b4600a; }

.skill-banner {
    left: 50%;
    top: 240px;
    transform: translate(-50%, -8px);
    opacity: 0;
    transition: opacity 0.18s, transform 0.18s;
    background: var(--cream);
    border: 4px solid var(--wood);
    border-radius: 999px;
    box-shadow: 0 5px 0 var(--wood-dark);
    padding: 8px 8px 8px 22px;
    white-space: nowrap;
    font-size: 19px;
    display: flex;
    align-items: center;
    gap: 12px;
    visibility: hidden;
}

.hud:not([data-scene="Gameplay"]) .skill-banner { display: none; }
.skill-banner.show { opacity: 1; transform: translate(-50%, 0); visibility: visible; }
.skill-banner.no-cancel { padding-right: 22px; }
.skill-banner.no-cancel .skill-cancel { display: none; }
.skill-cancel {
    background: var(--wood);
    color: #fff;
    border-radius: 999px;
    padding: 6px 16px;
    font-size: 17px;
    pointer-events: auto;
}

.danger {
    left: 50%;
    top: 300px;
    transform: translateX(-50%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s;
    color: #fff;
    background: var(--danger);
    border: 4px solid #8c1d12;
    border-radius: 999px;
    padding: 4px 18px;
    font-size: 22px;
    white-space: nowrap;
    box-shadow: 0 4px 0 #8c1d12;
}

.danger.show { opacity: 1; visibility: visible; animation: pulse 0.6s infinite alternate; }
.danger b { font-weight: normal; margin-left: 8px; }

@keyframes pulse { to { transform: translateX(-50%) scale(1.08); } }

.tutorial { left: 0; right: 0; top: 330px; opacity: 0; visibility: hidden; transition: opacity 0.3s; pointer-events: none; }
.tutorial.show { opacity: 1; visibility: visible; }
.tut-hand {
    position: absolute;
    left: 250px;
    top: 120px;
    color: #fff;
    animation: swipe 2.2s ease-in-out infinite;
}

.tut-hand .ic { width: 64px; height: 64px; --acc: var(--acc); filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4)); }
.tut-card {
    position: absolute;
    left: 50%;
    top: 220px;
    transform: translateX(-50%);
    width: 380px;
    background: rgba(255, 248, 230, 0.95);
    border: 4px solid var(--wood);
    border-radius: 20px;
    box-shadow: 0 5px 0 var(--wood-dark);
    padding: 12px 16px;
    font-size: 19px;
    line-height: 1.3;
    text-align: center;
}

@keyframes swipe {
    0%, 100% { transform: translateX(-110px); }
    45%, 55% { transform: translateX(110px); }
}

.map-home {
    right: 16px;
    top: 18px;
    width: 76px;
    height: 72px;
    background: url("../ui/btn-home.webp") center / contain no-repeat;
    pointer-events: auto;
    filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.3));
}

.map-home:active { transform: scale(0.94); }

/* ------------------------------------------------------------- ad mock */

.ad-mock {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(10, 10, 10, 0.92);
    display: grid;
    place-items: center;
    opacity: 0;
    transition: opacity 0.2s;
    font-family: "Super Bouncer", system-ui, sans-serif;
    color: #fff;
    --acc: #fff;
}

.ad-mock.show { opacity: 1; }
.ad-box { text-align: center; padding: 24px; }
.ad-tag { display: inline-block; font-size: 13px; letter-spacing: 2px; padding: 4px 10px; border: 2px solid #fff; border-radius: 6px; opacity: 0.8; }
.ad-title { font-size: 26px; margin: 16px 0; display: flex; gap: 10px; align-items: center; justify-content: center; }
.ad-title .ic { width: 30px; height: 30px; }
.ad-ring { width: 90px; height: 90px; border-radius: 50%; border: 6px solid var(--green); margin: 0 auto; display: grid; place-items: center; font-size: 36px; }
.ad-note { font-family: system-ui, sans-serif; font-size: 14px; opacity: 0.7; margin: 16px 0; }
.ad-close { font: inherit; font-size: 20px; color: #fff; background: var(--green); border: 0; border-radius: 999px; padding: 12px 28px; cursor: pointer; }
.ad-close:disabled { background: #555; cursor: default; }

@media (prefers-reduced-motion: reduce) {
    #ui *, .ad-mock { animation: none; transition: none; }
}
