* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    background: #10151f;
    color: #f8fafc;
    font-family: "Segoe UI", Arial, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
    touch-action: none;
}

#game-wrapper {
    position: relative;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    padding:
        max(8px, env(safe-area-inset-top))
        max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(8px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 18% 12%, rgba(249, 199, 79, 0.12), transparent 28%),
        linear-gradient(135deg, #10151f, #17212f 48%, #10151f);
}

#game-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border: 1px solid rgba(248, 250, 252, 0.2);
    border-radius: 12px;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.42), inset 0 0 0 1px rgba(255,255,255,0.08);
    touch-action: none;
}

#ui-overlay {
    position: absolute;
    inset:
        env(safe-area-inset-top)
        env(safe-area-inset-right)
        env(safe-area-inset-bottom)
        env(safe-area-inset-left);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding:
        max(14px, env(safe-area-inset-top))
        max(14px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom))
        max(14px, env(safe-area-inset-left));
    background: rgba(11, 18, 32, 0.82);
    backdrop-filter: blur(6px);
    pointer-events: auto;
    overflow: hidden;
    overscroll-behavior: contain;
}

.screen.active {
    display: flex;
}

#screen-menu {
    padding: 0;
    overflow: hidden;
    background: #83d9ff;
    backdrop-filter: none;
}

.home-scene {
    position: relative;
    width: min(100%, 980px);
    height: min(100%, 720px);
    min-height: min(560px, 100%);
    overflow: hidden;
    border-radius: clamp(0px, 2vw, 18px);
    background: #89dcff;
    box-shadow: 0 24px 60px rgba(10, 20, 35, 0.28);
    isolation: isolate;
}

.home-bg-art {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transform: scale(1.04);
    animation: homeDrift 9s ease-in-out infinite alternate;
    z-index: 0;
}

.home-sky,
.home-hills {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.home-sky {
    background:
        radial-gradient(circle at 18% 16%, rgba(255,255,255,0.9) 0 3%, transparent 3.5%),
        radial-gradient(circle at 22% 14%, rgba(255,255,255,0.9) 0 4%, transparent 4.5%),
        radial-gradient(circle at 26% 17%, rgba(255,255,255,0.9) 0 3%, transparent 3.5%),
        linear-gradient(to bottom, rgba(255,255,255,0.06), transparent 34%);
    opacity: 0.65;
    animation: homeClouds 12s ease-in-out infinite alternate;
}

.home-logo {
    position: absolute;
    left: 50%;
    top: 26px;
    transform: translateX(-50%) rotate(-2deg);
    display: grid;
    justify-items: center;
    color: #ffffff;
    font-weight: 1000;
    line-height: 0.88;
    text-align: center;
    text-shadow:
        4px 4px 0 #5b3522,
        -3px 3px 0 #5b3522,
        0 8px 0 rgba(91, 53, 34, 0.2);
    z-index: 5;
    filter: drop-shadow(0 10px 0 rgba(75, 45, 28, 0.18));
}

.home-logo span {
    color: #ffe15a;
    font-size: clamp(38px, 7vw, 76px);
    -webkit-text-stroke: 2px #5b3522;
}

.home-logo strong {
    color: #ff7a32;
    font-size: clamp(46px, 8vw, 92px);
    -webkit-text-stroke: 2px #5b3522;
}

.home-progress {
    position: absolute;
    top: 24px;
    right: 22px;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 9px 11px;
    border: 3px solid #5b3522;
    border-radius: 18px;
    background: #fff6d8;
    color: #5b3522;
    font-size: 13px;
    font-weight: 900;
    box-shadow: 0 5px 0 rgba(91, 53, 34, 0.2);
    z-index: 7;
}

.home-progress span {
    white-space: nowrap;
}

.home-thief {
    position: absolute;
    left: max(12px, 6%);
    bottom: 54px;
    width: min(38vw, 330px);
    max-height: 58%;
    object-fit: contain;
    transform-origin: 50% 100%;
    filter: drop-shadow(0 12px 0 rgba(74, 54, 35, 0.22));
    animation: thiefIdle 2.7s ease-in-out infinite;
    z-index: 4;
}

.home-victim {
    position: absolute;
    right: max(-34px, 3%);
    bottom: 88px;
    width: min(26vw, 210px);
    max-height: 47%;
    object-fit: contain;
    filter: drop-shadow(0 10px 0 rgba(74, 54, 35, 0.18));
    animation: victimFloat 3.2s ease-in-out infinite;
    z-index: 3;
}

.home-sparkles {
    position: absolute;
    right: clamp(114px, 21vw, 260px);
    bottom: clamp(250px, 42vh, 358px);
    width: 86px;
    height: 86px;
    background:
        radial-gradient(circle, #fff 0 8%, transparent 9%) 10px 18px / 30px 30px no-repeat,
        radial-gradient(circle, #ffe15a 0 10%, transparent 11%) 48px 36px / 28px 28px no-repeat,
        radial-gradient(circle, #fff 0 7%, transparent 8%) 34px 4px / 24px 24px no-repeat;
    animation: sparklePop 1.4s ease-in-out infinite;
    z-index: 5;
}

.home-actions {
    position: absolute;
    left: 50%;
    bottom: 34px;
    transform: translateX(-50%);
    display: grid;
    justify-items: center;
    gap: 14px;
    z-index: 8;
}

.home-play-btn {
    min-width: clamp(190px, 24vw, 260px);
    height: 74px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 5px solid #63361f;
    border-radius: 24px;
    color: #63361f;
    background: linear-gradient(#ffe86a, #ffb22e);
    box-shadow:
        inset 0 4px 0 rgba(255,255,255,0.62),
        0 9px 0 #b75b20,
        0 16px 18px rgba(74, 54, 35, 0.22);
    font: inherit;
    font-size: 34px;
    font-weight: 1000;
    cursor: pointer;
    animation: playPulse 1.5s ease-in-out infinite;
}

.home-play-btn span {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    padding-left: 3px;
    border-radius: 50%;
    color: #ffffff;
    background: #30b559;
    -webkit-text-stroke: 0;
    box-shadow: inset 0 3px 0 rgba(255,255,255,0.45), 0 3px 0 rgba(75, 45, 28, 0.22);
    font-size: 24px;
}

.home-play-btn:hover,
.home-icon-btn:hover {
    filter: brightness(1.04);
}

.home-play-btn:active,
.home-icon-btn:active {
    transform: translateY(3px);
}

.home-icon-btn.muted {
    color: #8c4f3c;
    background: #ffd9d0;
}

.home-icon-btn.bump {
    animation: iconBump 0.22s ease;
}

.home-icon-row {
    display: flex;
    gap: 10px;
}

.home-icon-btn {
    width: 58px;
    height: 54px;
    display: grid;
    place-items: center;
    border: 4px solid #63361f;
    border-radius: 18px;
    color: #63361f;
    background: #fff6d8;
    box-shadow: inset 0 3px 0 rgba(255,255,255,0.72), 0 5px 0 #c28a55;
    font: inherit;
    font-size: 25px;
    font-weight: 1000;
    cursor: pointer;
}

@keyframes homeDrift {
    from { transform: scale(1.04) translateX(-7px); }
    to { transform: scale(1.055) translateX(7px); }
}

@keyframes homeClouds {
    from { transform: translateX(-8px); }
    to { transform: translateX(18px); }
}

@keyframes thiefIdle {
    0%, 100% { transform: translateY(0) rotate(-1deg) scale(1); }
    50% { transform: translateY(-8px) rotate(1deg) scale(1.015, 0.99); }
}

@keyframes victimFloat {
    0%, 100% { transform: translateY(0) rotate(1deg); }
    50% { transform: translateY(-5px) rotate(-1deg); }
}

@keyframes targetSparkle {
    0%, 100% { transform: translateY(0) rotate(-10deg) scale(1); }
    50% { transform: translateY(-8px) rotate(-4deg) scale(1.06); }
}

@keyframes gloveFloat {
    0%, 100% { transform: translateY(0) rotate(62deg); }
    50% { transform: translateY(-7px) rotate(70deg); }
}

@keyframes sparklePop {
    0%, 100% { opacity: 0.45; transform: scale(0.88); }
    50% { opacity: 1; transform: scale(1.08); }
}

@keyframes playPulse {
    0%, 100% {
        filter: brightness(1);
        box-shadow:
            inset 0 4px 0 rgba(255,255,255,0.62),
            0 9px 0 #b75b20,
            0 16px 18px rgba(74, 54, 35, 0.22);
    }
    50% {
        filter: brightness(1.08);
        box-shadow:
            inset 0 4px 0 rgba(255,255,255,0.76),
            0 9px 0 #b75b20,
            0 18px 24px rgba(255, 178, 46, 0.36);
    }
}

@keyframes iconBump {
    0%, 100% { transform: rotate(0deg); }
    35% { transform: rotate(-8deg) scale(1.08); }
    70% { transform: rotate(8deg) scale(1.08); }
}

.screen.hud {
    align-items: flex-start;
    justify-content: flex-start;
    padding: 0;
    background: transparent;
    backdrop-filter: none;
    pointer-events: none;
    overflow: visible;
}

.screen.hud * {
    pointer-events: auto;
}

.popup {
    background: rgba(11, 18, 32, 0.88);
}

.menu-box,
.popup-box {
    width: min(92vw, 460px);
    max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
    padding: 32px;
    text-align: center;
    background: rgba(22, 33, 49, 0.96);
    border: 1px solid rgba(248, 250, 252, 0.14);
    border-radius: 8px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
    animation: rise 0.25s ease-out;
}

.menu-box.wide {
    width: min(94vw, 760px);
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.logo {
    width: 66px;
    height: 66px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    color: #111827;
    background: #ffd166;
    border: 4px solid #f8fafc;
    border-radius: 50%;
    font-weight: 900;
    letter-spacing: 0;
    box-shadow: 0 10px 24px rgba(255, 209, 102, 0.25);
}

h1 {
    margin-bottom: 8px;
    color: #ffd166;
    font-size: 36px;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 20px;
    color: #ffd166;
    font-size: 26px;
    letter-spacing: 0;
}

.subtitle,
.popup-box p {
    color: #cbd5e1;
    line-height: 1.5;
}

.subtitle {
    margin-bottom: 26px;
}

.menu-buttons,
.popup-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.btn {
    min-width: 210px;
    min-height: 48px;
    padding: 12px 24px;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.16s ease, filter 0.16s ease, background 0.16s ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    color: #111827;
    background: #ffd166;
}

.btn-secondary {
    color: #e2e8f0;
    background: #253449;
    border: 1px solid rgba(226, 232, 240, 0.14);
}

.btn-icon {
    position: relative;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 50%;
    color: #f8fafc;
    background: rgba(15, 23, 42, 0.52);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18), inset 0 1px 0 rgba(255,255,255,0.16);
    backdrop-filter: blur(8px);
    font-weight: 900;
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease;
    overflow: hidden;
    font-size: 0;
    text-indent: 0;
}

.btn-icon::before,
.result-icon-btn::before,
.home-icon-btn::before {
    position: absolute;
    inset: 0;
    text-indent: 0;
}

.btn-icon > *,
.result-icon-btn > *,
.home-icon-btn > * {
    display: none;
}

.btn-icon::before {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: currentColor;
    font-size: 20px;
    line-height: 1;
}

#btn-music-hud::before { content: "\266A"; }
#btn-sfx-hud::before { content: "\2726"; }
#btn-retry::before { content: "\21BB"; }
#btn-pause::before { content: "\23F8"; }

.btn-icon:hover {
    transform: translateY(-1px);
    background: rgba(15, 23, 42, 0.7);
}

.btn-icon.muted {
    color: #8c4f3c;
    background: rgba(255, 217, 208, 0.92);
}

.stats {
    display: flex;
    justify-content: center;
    gap: 22px;
    margin-top: 24px;
    color: #cbd5e1;
    font-size: 14px;
}

.stats b,
.popup-stats b {
    color: #ffd166;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin: 20px 0 24px;
    max-height: min(520px, calc(100dvh - 210px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    overflow: auto;
    padding: 2px 4px 6px;
    overscroll-behavior: contain;
}

.level-card {
    min-height: 108px;
    padding: 10px 8px;
    display: grid;
    grid-template-rows: 26px 22px 1fr 18px;
    align-items: center;
    justify-items: center;
    color: #f8fafc;
    background: #1f2a3a;
    border: 1px solid rgba(248, 250, 252, 0.16);
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
}

.level-card:hover:not(.locked) {
    border-color: #ffd166;
    background: #29384d;
}

.level-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
}

.level-card.completed {
    border-color: #8ce99a;
}

.lvl-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #111827;
    background: #ffd166;
    font-size: 13px;
    font-weight: 900;
}

.lvl-num {
    font-weight: 900;
}

.lvl-name {
    max-width: 100%;
    color: #cbd5e1;
    font-size: 11px;
    line-height: 1.15;
    text-align: center;
}

.lvl-stars {
    color: #ffd166;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 1px;
}

.how-list {
    max-width: 420px;
    margin: 20px auto 24px;
    text-align: left;
}

.how-item {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 12px;
    align-items: start;
    margin-bottom: 12px;
    padding: 12px;
    background: rgba(248, 250, 252, 0.06);
    border-radius: 8px;
}

.how-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #111827;
    background: #73d2de;
    font-weight: 900;
}

.how-item p {
    color: #cbd5e1;
    line-height: 1.45;
}

.how-item b {
    color: #ffd166;
}

.settings-actions {
    display: grid;
    gap: 12px;
    margin: 12px auto 22px;
}

.settings-toggle {
    min-height: 54px;
    border: 3px solid #63361f;
    border-radius: 16px;
    color: #63361f;
    background: #fff6d8;
    box-shadow: inset 0 3px 0 rgba(255,255,255,0.72), 0 5px 0 #c28a55;
    font: inherit;
    font-size: 20px;
    font-weight: 1000;
    cursor: pointer;
}

.settings-toggle.muted {
    color: #8c4f3c;
    background: #ffd9d0;
}

/* Shared button icon system. Icons live inside buttons only. */
.btn-primary,
.btn-secondary,
.settings-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-primary::before,
.btn-secondary::before,
.settings-toggle::before {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    color: currentColor;
    font-size: 18px;
    line-height: 1;
}

.btn-primary::before {
    background: rgba(17, 24, 39, 0.11);
}

.btn-secondary::before {
    background: rgba(255, 255, 255, 0.08);
}

.settings-toggle::before {
    width: 30px;
    height: 30px;
    background: rgba(99, 54, 31, 0.11);
    font-size: 20px;
}

#btn-back-from-levels::before { content: "\2039"; }
#btn-back-from-how::before,
#btn-back-from-settings::before { content: "\2713"; }
#btn-next-level::before { content: "\25B6"; }
#btn-retry-complete::before,
#btn-retry-fail::before,
#btn-retry-pause::before { content: "\21BB"; }
#btn-menu-complete::before,
#btn-menu-fail::before,
#btn-menu-pause::before { content: "\2302"; }
#btn-resume::before { content: "\25B6"; }
#btn-settings-music::before { content: "\266A"; }
#btn-settings-sfx::before { content: "\2726"; }

.hud-top,
.hud-bottom {
    position: absolute;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding:
        max(8px, env(safe-area-inset-top))
        max(10px, env(safe-area-inset-right))
        12px
        max(10px, env(safe-area-inset-left));
    color: #e2e8f0;
    background: linear-gradient(to bottom, rgba(15, 23, 42, 0.42), transparent);
}

.hud-top {
    top: 0;
    align-items: flex-start;
}

.hud-bottom {
    bottom: 0;
    align-items: flex-end;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.38), transparent);
    padding:
        12px
        max(10px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(10px, env(safe-area-inset-left));
}

.hud-left {
    display: inline-grid;
    gap: 2px;
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.48);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16), inset 0 1px 0 rgba(255,255,255,0.12);
    backdrop-filter: blur(8px);
}

#hud-level {
    color: #fff7c2;
    font-weight: 900;
    font-size: 16px;
    text-shadow: 0 2px 0 rgba(15, 23, 42, 0.22);
}

#hud-target,
#path-length {
    color: #eef2ff;
    font-size: 12px;
    font-weight: 700;
}

.hud-right {
    display: flex;
    gap: 8px;
}

#status-msg {
    max-width: 54vw;
    padding: 9px 12px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.5);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16), inset 0 1px 0 rgba(255,255,255,0.12);
    backdrop-filter: blur(8px);
    text-align: right;
    font-weight: 800;
    font-size: 13px;
}

#path-length {
    padding: 9px 12px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.48);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16), inset 0 1px 0 rgba(255,255,255,0.12);
    backdrop-filter: blur(8px);
}

.popup-icon {
    display: inline-grid;
    place-items: center;
    min-width: 72px;
    min-height: 38px;
    margin-bottom: 12px;
    padding: 0 12px;
    color: #111827;
    background: #ffd166;
    border-radius: 8px;
    font-weight: 900;
}

.stars {
    margin: 8px 0 12px;
    color: #ffd166;
    font-size: 34px;
    font-weight: 900;
    letter-spacing: 4px;
}

.popup-stats {
    display: flex;
    justify-content: center;
    gap: 22px;
    margin: 20px 0;
    color: #cbd5e1;
    font-size: 14px;
}

.mission-result {
    background: #fffdf7;
    color: #5f4634;
    backdrop-filter: none;
}

.mission-result-stage {
    position: relative;
    width: min(92vw, 560px);
    max-width: calc(100dvw - 28px - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: min(460px, calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    display: grid;
    grid-template-rows: auto 1fr auto;
    justify-items: center;
    padding: 18px 20px 22px;
    background: #fffaf0;
    border: 5px solid #6b4d3a;
    border-radius: 22px;
    box-shadow: 0 18px 0 rgba(107, 77, 58, 0.12);
}

.mission-result-copy {
    text-align: center;
}

#m1-result-kicker {
    color: #6b4d3a;
    font-size: 22px;
    font-weight: 900;
    line-height: 1.1;
}

#m1-result-title {
    margin: 8px 0 2px;
    color: #ff3b1f;
    font-size: 48px;
    transform: rotate(-9deg);
}

#m1-result-message {
    color: #6b4d3a;
    font-weight: 800;
}

.mission-result-art {
    position: relative;
    width: 100%;
    min-height: 210px;
    height: clamp(190px, 45dvh, 270px);
    background-image:
        linear-gradient(rgba(255, 253, 247, 0.08), rgba(255, 253, 247, 0.08)),
        url("assets/mission-1/background.webp");
    background-size: cover;
    background-position: center;
    border: 3px solid #6b4d3a;
    border-radius: 16px;
    overflow: hidden;
}

.m1-result-piece {
    position: absolute;
    display: block;
    width: auto;
    pointer-events: none;
    user-select: none;
    filter: drop-shadow(0 8px 0 rgba(107, 77, 58, 0.16));
}

.m1-result-thief {
    left: 58px;
    bottom: 18px;
    height: 178px;
    transform-origin: 50% 100%;
}

.m1-result-npc {
    right: 76px;
    bottom: 58px;
    height: 172px;
}

.m1-result-purse {
    right: 144px;
    bottom: 128px;
    height: 74px;
}

.m1-result-glove {
    left: 214px;
    bottom: 116px;
    height: 58px;
    transform: rotate(-18deg);
}

#m1-result-emoji {
    position: absolute;
    left: 50%;
    top: 50%;
    display: grid;
    place-items: center;
    width: 118px;
    height: 118px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 6px solid #1b2430;
    background: #ffd166;
    color: #1b2430;
    font-size: 64px;
    font-weight: 900;
    box-shadow: 0 8px 0 rgba(107, 77, 58, 0.18);
}

.mission-result-actions {
    display: flex;
    gap: 18px;
    margin-top: 16px;
}

.mission-result-actions[hidden] {
    display: none;
}

.result-icon-btn {
    position: relative;
    width: 74px;
    height: 58px;
    min-width: 56px;
    min-height: 48px;
    display: grid;
    place-items: center;
    border: 4px solid #c59b86;
    border-radius: 16px;
    color: #8f6a59;
    background: #fff7ed;
    box-shadow: inset 0 0 0 3px #ffffff, 0 5px 0 rgba(107, 77, 58, 0.15);
    font-size: 30px;
    font-weight: 900;
    cursor: pointer;
    overflow: hidden;
    font-size: 0;
    text-indent: 0;
}

.result-icon-btn::before {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: currentColor;
    font-size: 30px;
    line-height: 1;
}

#btn-m1-next::before,
#btn-m1-skip::before { content: "\25B6"; }
#btn-m1-replay::before,
#btn-m1-retry::before { content: "\21BB"; }
#btn-m1-levels-success::before,
#btn-m1-levels-fail::before { content: "\2630"; }

.result-icon-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.04);
}

.result-success #m1-result-title {
    color: #2f9e44;
    transform: rotate(0deg);
}

.result-success #m1-result-emoji {
    background: #8ce99a;
    left: 52%;
    top: 48%;
    width: 104px;
    height: 104px;
    font-size: 54px;
}

.result-success .m1-result-thief {
    transform: translateY(-8px) rotate(-4deg);
}

.result-success .m1-result-glove {
    left: 328px;
    bottom: 140px;
    transform: rotate(10deg);
}

.result-success .m1-result-purse {
    right: 180px;
    bottom: 150px;
    transform: rotate(-8deg);
}

.result-success .m1-result-npc {
    transform: translateX(12px);
}

.result-fail .m1-result-thief {
    transform: translateY(30px) rotate(-68deg);
}

.result-fail .m1-result-glove {
    left: 236px;
    bottom: 106px;
    transform: rotate(26deg);
}

.result-fail .m1-result-purse {
    transform: translateY(14px);
}

.result-fail #m1-result-emoji {
    left: 34%;
    top: 39%;
    width: 96px;
    height: 96px;
    font-size: 64px;
}

@media (max-width: 640px) {
    #game-wrapper {
        align-items: center;
    }

    #game-canvas {
        border-radius: 8px;
    }

    .home-scene {
        width: 100%;
        height: 100%;
        min-height: 0;
        border-radius: 0;
    }

    .home-logo {
        top: 18px;
    }

    .home-progress {
        top: 96px;
        right: 50%;
        bottom: auto;
        transform: translateX(50%);
        gap: 7px;
        font-size: 12px;
        max-width: calc(100% - 24px);
        flex-wrap: wrap;
        justify-content: center;
    }

    .home-progress span:nth-child(2) {
        display: none;
    }

    .home-thief {
        left: 8px;
        bottom: 136px;
        width: min(47vw, 190px);
    }

    .home-victim {
        right: 6px;
        bottom: 232px;
        width: min(34vw, 138px);
    }

    .home-actions {
        bottom: 22px;
    }

    .home-play-btn {
        min-width: 188px;
        height: 66px;
        font-size: 30px;
    }

    .home-icon-btn {
        width: 52px;
        height: 50px;
        font-size: 22px;
    }

    .menu-box,
    .popup-box {
        width: min(94vw, 460px);
        padding: 20px 16px;
    }

    h1 {
        font-size: 30px;
    }

    .level-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        margin: 14px 0 16px;
    }

    .level-card {
        min-height: 88px;
        padding: 8px 6px;
    }

    .lvl-name {
        font-size: 10px;
    }

    .stats {
        flex-direction: column;
        gap: 8px;
    }

    #status-msg {
        max-width: min(58vw, 230px);
        font-size: 12px;
        line-height: 1.15;
    }

    .mission-result-stage {
        width: min(94vw, 420px);
        min-height: 0;
        padding: 12px 12px 14px;
        border-width: 4px;
        border-radius: 18px;
    }

    #m1-result-kicker {
        font-size: 18px;
    }

    #m1-result-title {
        font-size: 40px;
    }

    .mission-result-art {
        min-height: 180px;
        height: clamp(180px, 42dvh, 245px);
    }

    .m1-result-thief {
        left: 26px;
        bottom: 10px;
        height: 138px;
    }

    .m1-result-npc {
        right: 34px;
        bottom: 38px;
        height: 134px;
    }

    .m1-result-purse {
        right: 94px;
        bottom: 104px;
        height: 56px;
    }

    .m1-result-glove {
        left: 150px;
        bottom: 92px;
        height: 46px;
    }

    #m1-result-emoji {
        width: 82px;
        height: 82px;
        border-width: 5px;
        font-size: 48px;
    }

    .mission-result-actions {
        gap: 10px;
        margin-top: 12px;
    }

    .result-icon-btn {
        width: 64px;
        height: 52px;
        font-size: 25px;
    }

    .hud-top {
        align-items: flex-start;
    }

    .hud-left {
        max-width: calc(100vw - 214px);
        padding: 6px 8px;
    }

    #hud-level {
        font-size: 13px;
        line-height: 1.12;
    }

    #hud-target,
    #path-length {
        font-size: 11px;
    }

    .hud-right {
        gap: 6px;
    }

    .btn-icon {
        width: 44px;
        height: 44px;
        font-size: 17px;
    }
}

@media (max-height: 560px) {
    .home-logo {
        top: 12px;
    }

    .home-logo span {
        font-size: clamp(30px, 8vh, 48px);
    }

    .home-logo strong {
        font-size: clamp(36px, 9vh, 58px);
    }

    .home-progress {
        top: 12px;
        right: 12px;
        transform: none;
        font-size: 11px;
    }

    .home-thief {
        bottom: 54px;
        width: min(25vw, 180px);
    }

    .home-victim {
        bottom: 68px;
        width: min(18vw, 132px);
    }

    .home-actions {
        bottom: 12px;
        gap: 8px;
    }

    .home-play-btn {
        height: 54px;
        min-width: 170px;
        border-width: 4px;
        border-radius: 18px;
        font-size: 26px;
    }

    .home-icon-btn {
        width: 46px;
        height: 44px;
        border-width: 3px;
        font-size: 20px;
    }

    .menu-box,
    .popup-box {
        padding: 16px;
    }

    h2 {
        margin-bottom: 12px;
        font-size: 22px;
    }

    .how-list {
        margin: 10px auto 14px;
    }

    .how-item {
        margin-bottom: 8px;
        padding: 9px;
    }

    .level-grid {
        grid-template-columns: repeat(5, minmax(78px, 1fr));
        max-height: calc(100dvh - 150px);
    }

    .level-card {
        min-height: 76px;
    }

    .mission-result-stage {
        width: min(94vw, 640px);
        grid-template-columns: 180px 1fr;
        grid-template-rows: 1fr auto;
        column-gap: 12px;
        min-height: 0;
        padding: 10px 12px;
    }

    .mission-result-copy {
        align-self: center;
    }

    .mission-result-art {
        height: min(58dvh, 260px);
        min-height: 180px;
    }

    .mission-result-actions {
        grid-column: 1 / -1;
        margin-top: 8px;
    }
}

/* Premium home title screen composition. Home-only overrides. */
#screen-menu {
    background: #74d2f4;
}

#screen-menu .home-scene {
    width: min(100%, 980px);
    height: min(100%, 720px);
    min-height: 0;
    border-radius: clamp(0px, 1.6vw, 18px);
    box-shadow: 0 28px 80px rgba(20, 62, 92, 0.28);
}

#screen-menu .home-bg-art {
    object-position: 50% 48%;
    transform: scale(1.02);
    filter: saturate(1.06) contrast(1.02);
}

#screen-menu .home-sky {
    opacity: 0.45;
    z-index: 2;
}

#screen-menu .home-hills {
    z-index: 2;
    background:
        linear-gradient(to bottom, rgba(255,255,255,0.14), transparent 26%),
        radial-gradient(ellipse at 50% 94%, rgba(56, 112, 41, 0.20), transparent 42%);
}

.home-foreground {
    position: absolute;
    inset: auto 0 0 0;
    width: 100%;
    height: 38%;
    object-fit: cover;
    object-position: bottom center;
    pointer-events: none;
    z-index: 5;
}

#screen-menu .home-logo {
    top: clamp(18px, 3.3%, 30px);
    z-index: 9;
    transform: translateX(-50%) rotate(-1.5deg);
    text-shadow:
        2px 3px 0 #6b3d25,
        -1px 2px 0 #6b3d25,
        0 8px 16px rgba(77, 47, 29, 0.22);
    filter: drop-shadow(0 5px 0 rgba(255, 255, 255, 0.30));
    animation: logoFloat 3.4s ease-in-out infinite;
}

#screen-menu .home-logo span {
    font-size: clamp(30px, 4.8vw, 56px);
    -webkit-text-stroke: 1.5px #6b3d25;
}

#screen-menu .home-logo strong {
    font-size: clamp(38px, 5.8vw, 70px);
    -webkit-text-stroke: 1.5px #6b3d25;
}

#screen-menu .home-progress {
    top: clamp(14px, 3%, 22px);
    right: clamp(14px, 3%, 24px);
    max-width: 250px;
    gap: 7px;
    padding: 8px 10px;
    border-width: 3px;
    border-radius: 16px;
    font-size: 12px;
    z-index: 10;
}

#screen-menu .home-thief {
    left: clamp(18px, 7%, 72px);
    bottom: clamp(84px, 11%, 104px);
    width: clamp(230px, 34%, 340px);
    max-height: 60%;
    z-index: 7;
    filter: drop-shadow(0 12px 0 rgba(51, 73, 39, 0.24));
    animation: thiefPremiumIdle 2.6s ease-in-out infinite;
}

#screen-menu .home-victim {
    right: clamp(28px, 8%, 90px);
    bottom: clamp(130px, 18%, 158px);
    width: clamp(132px, 19%, 195px);
    max-height: 44%;
    z-index: 6;
    filter: drop-shadow(0 9px 0 rgba(51, 73, 39, 0.18));
    animation: victimPremiumIdle 3.2s ease-in-out infinite;
}

.home-depth-shadow {
    position: absolute;
    height: 28px;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(54, 57, 32, 0.28), rgba(54, 57, 32, 0.02) 68%, transparent 70%);
    z-index: 4;
    pointer-events: none;
}

.home-depth-shadow-thief {
    left: clamp(44px, 10%, 108px);
    bottom: clamp(86px, 12%, 110px);
    width: clamp(190px, 28%, 290px);
}

.home-depth-shadow-victim {
    right: clamp(42px, 9%, 104px);
    bottom: clamp(132px, 19%, 160px);
    width: clamp(120px, 17%, 178px);
}

#screen-menu .home-sparkles {
    right: clamp(86px, 15%, 162px);
    bottom: clamp(288px, 43%, 350px);
    width: 62px;
    height: 62px;
    z-index: 8;
    animation: sparklePop 1.8s ease-in-out infinite;
}

#screen-menu .home-actions {
    bottom: clamp(24px, 5%, 42px);
    gap: 13px;
    z-index: 12;
}

#screen-menu .home-play-btn {
    min-width: clamp(210px, 24vw, 270px);
    height: clamp(66px, 8.2vh, 78px);
    border-width: 5px;
    border-radius: 25px;
    font-size: clamp(30px, 3vw, 38px);
}

#screen-menu .home-play-btn span {
    width: 44px;
    height: 44px;
    font-size: 0;
}

#screen-menu .home-play-btn span::before {
    content: "";
    width: 0;
    height: 0;
    margin-left: 4px;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    border-left: 18px solid #ffffff;
}

#screen-menu .home-icon-row {
    gap: clamp(8px, 1.4vw, 12px);
    padding: 7px 9px;
    border: 3px solid rgba(99, 54, 31, 0.28);
    border-radius: 22px;
    background: rgba(255, 246, 216, 0.44);
    backdrop-filter: blur(2px);
    box-shadow: 0 8px 18px rgba(74, 54, 35, 0.12);
}

#screen-menu .home-icon-btn {
    position: relative;
    width: clamp(50px, 5.6vw, 60px);
    height: clamp(50px, 5.4vw, 58px);
    border-width: 4px;
    border-radius: 17px;
    font-size: 0;
    color: transparent;
    overflow: hidden;
}

#screen-menu .home-icon-btn::before {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: #63361f;
    font-size: clamp(24px, 2.6vw, 29px);
    line-height: 1;
    filter: drop-shadow(0 2px 0 rgba(255,255,255,0.55));
}

#btn-levels::before { content: "\2630"; }
#btn-how::before { content: "?"; }
#btn-music::before { content: "\266A"; }
#btn-sfx::before { content: "\1F50A"; }
#btn-settings::before { content: "\2699"; }

#screen-menu #btn-sfx::before {
    font-size: clamp(22px, 2.35vw, 26px);
}

#screen-menu .home-icon-btn.muted::after {
    content: "";
    position: absolute;
    width: 30px;
    height: 4px;
    left: 50%;
    top: 50%;
    border-radius: 999px;
    background: #c44232;
    transform: translate(-50%, -50%) rotate(-38deg);
    box-shadow: 0 1px 0 #ffffff;
}

@keyframes logoFloat {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(-1.5deg); }
    50% { transform: translateX(-50%) translateY(-4px) rotate(-0.5deg); }
}

@keyframes thiefPremiumIdle {
    0%, 100% { transform: translateY(0) rotate(-1deg) scale(1); }
    50% { transform: translateY(-5px) rotate(0.5deg) scale(1.012, 0.992); }
}

@keyframes victimPremiumIdle {
    0%, 100% { transform: translateY(0) rotate(0.5deg); }
    50% { transform: translateY(-3px) rotate(-0.3deg); }
}

@media (max-width: 640px) {
    #screen-menu .home-logo {
        top: 18px;
    }

    #screen-menu .home-logo span {
        font-size: clamp(28px, 10vw, 38px);
    }

    #screen-menu .home-logo strong {
        font-size: clamp(35px, 12vw, 48px);
    }

    #screen-menu .home-progress {
        top: 98px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-width: calc(100% - 34px);
    }

    #screen-menu .home-progress span:nth-child(2) {
        display: none;
    }

    #screen-menu .home-thief {
        left: 8px;
        bottom: 126px;
        width: min(58vw, 230px);
        max-height: 48%;
    }

    #screen-menu .home-victim {
        right: 10px;
        bottom: 238px;
        width: min(38vw, 145px);
        max-height: 33%;
    }

    .home-depth-shadow-thief {
        left: 12px;
        bottom: 128px;
        width: min(50vw, 200px);
    }

    .home-depth-shadow-victim {
        right: 16px;
        bottom: 240px;
        width: min(34vw, 134px);
    }

    #screen-menu .home-sparkles {
        right: 74px;
        bottom: 378px;
        width: 48px;
        height: 48px;
    }

    #screen-menu .home-actions {
        bottom: max(18px, env(safe-area-inset-bottom));
        gap: 10px;
    }

    #screen-menu .home-play-btn {
        min-width: 190px;
        height: 66px;
        font-size: 30px;
    }

    #screen-menu .home-icon-row {
        gap: 7px;
        padding: 6px 7px;
    }

    #screen-menu .home-icon-btn {
        width: 48px;
        height: 48px;
        border-width: 3px;
        border-radius: 15px;
    }
}

@media (max-height: 560px) {
    #screen-menu .home-logo {
        top: 10px;
    }

    #screen-menu .home-progress {
        top: 12px;
        right: 12px;
        left: auto;
        transform: none;
    }

    #screen-menu .home-thief {
        left: 42px;
        bottom: 56px;
        width: min(24vw, 190px);
    }

    #screen-menu .home-victim {
        right: 58px;
        bottom: 72px;
        width: min(15vw, 125px);
    }

    #screen-menu .home-actions {
        bottom: 12px;
    }
}
