:root {
    color-scheme: dark;
    --bg: #0f1718;
    --panel: rgba(16, 24, 27, 0.9);
    --panel-solid: #142024;
    --glass: rgba(12, 18, 22, 0.76);
    --glass-strong: rgba(14, 21, 25, 0.9);
    --line: rgba(255, 255, 255, 0.16);
    --line-strong: rgba(255, 255, 255, 0.24);
    --text: #f3fbf4;
    --muted: #b6c6bd;
    --green: #63bb69;
    --gold: #f0bd4e;
    --red: #e6675f;
    --sky: #72d1ee;
    --cyan: #35d9e6;
    --pink: #ec6fbd;
    --lime: #8eea72;
    --stone: #777d82;
    --shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
    --soft-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    margin: 0;
    overflow: hidden;
    background:
        linear-gradient(135deg, rgba(99, 187, 105, 0.12), transparent 34%),
        linear-gradient(225deg, rgba(53, 217, 230, 0.11), transparent 32%),
        var(--bg);
    color: var(--text);
    overscroll-behavior: none;
}

button,
input,
select,
a.button {
    font: inherit;
}

button {
    cursor: pointer;
}

a.button {
    text-decoration: none;
}

button:disabled,
input:disabled,
select:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.shell {
    display: grid;
    grid-template-rows: auto 1fr;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 520px;
    background:
        linear-gradient(180deg, rgba(114, 209, 238, 0.12), transparent 32%),
        linear-gradient(120deg, rgba(240, 189, 78, 0.12), transparent 42%),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(180deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        var(--bg);
    background-size: auto, auto, 32px 32px, 32px 32px, auto;
}

.shell.app-fullscreen {
    grid-template-rows: 1fr;
    background: #071018;
}

.shell.app-fullscreen .topbar {
    position: absolute;
    inset: 0 0 auto 0;
    min-height: 58px;
    background: rgba(9, 13, 18, 0.78);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
}

.shell.app-fullscreen .game-layout {
    height: 100%;
}

.shell.app-fullscreen .status-pill {
    top: 78px;
}

.shell.app-fullscreen .stats {
    top: 76px;
}

.lock-shell {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
    background:
        linear-gradient(135deg, rgba(53, 217, 230, 0.14), transparent 34%),
        linear-gradient(225deg, rgba(236, 111, 189, 0.14), transparent 36%),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(180deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        #080d16;
    background-size: auto, auto, 34px 34px, 34px 34px, auto;
}

.lock-stage {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    align-items: center;
    justify-items: center;
    gap: clamp(18px, 4vw, 46px);
    width: 100%;
    min-height: 100%;
    padding: max(24px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
    isolation: isolate;
}

.lock-stage::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(90deg, rgba(4, 8, 15, 0.08) 0%, rgba(4, 8, 15, 0.36) 58%, rgba(4, 8, 15, 0.78) 100%),
        linear-gradient(180deg, rgba(6, 10, 18, 0.04) 0%, rgba(6, 10, 18, 0.18) 45%, rgba(6, 10, 18, 0.72) 100%);
}

.lock-art {
    position: relative;
    display: grid;
    place-items: center;
    width: min(62vw, 650px);
    height: min(calc(100dvh - 48px), 780px);
    min-height: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025)),
        rgba(5, 9, 16, 0.58);
    box-shadow: 0 24px 68px rgba(0, 0, 0, 0.46);
}

.lock-art::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    pointer-events: none;
    z-index: 2;
}

.lock-art::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 28%;
    background: linear-gradient(180deg, transparent, rgba(2, 5, 10, 0.36));
    pointer-events: none;
    z-index: 1;
}

.lock-hero-image {
    position: absolute;
    inset: 0;
    z-index: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

.lock-panel {
    position: relative;
    width: min(420px, 100%);
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.035)),
        rgba(10, 15, 22, 0.84);
    box-shadow: 0 22px 64px rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(16px);
    overflow: hidden;
}

.lock-panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: linear-gradient(90deg, var(--cyan), var(--gold), var(--pink));
}

.lock-brand {
    justify-content: flex-start;
    margin-bottom: 18px;
}

.password-form {
    display: grid;
    gap: 10px;
}

.password-form label {
    color: #ffe39a;
    font-size: 0.84rem;
    font-weight: 900;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.password-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.password-error {
    margin: 2px 0 0;
    color: #ffb8b2;
    font-size: 0.9rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 68px;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    background:
        linear-gradient(180deg, rgba(25, 36, 40, 0.95), rgba(12, 18, 22, 0.88)),
        linear-gradient(90deg, rgba(53, 217, 230, 0.08), rgba(240, 189, 78, 0.08));
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(16px) saturate(1.08);
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 172px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.34);
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.18) 0 2px, transparent 2px 100%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0 2px, transparent 2px 100%),
        linear-gradient(180deg, #68b75b 0 45%, #7b5838 45% 70%, #5b4532 70% 100%);
    background-size: 12px 12px, 12px 12px, auto;
    box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.24), 0 10px 22px rgba(0, 0, 0, 0.32);
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.42);
}

.account {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

.account-name {
    color: var(--muted);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-toggle {
    flex: 0 0 auto;
}

.fullscreen-toggle[aria-pressed="true"] {
    border-color: rgba(112, 183, 215, 0.7);
    background: rgba(112, 183, 215, 0.18);
}

.fullscreen-exit-icon,
.fullscreen-toggle[aria-pressed="true"] .fullscreen-enter-icon {
    display: none;
}

.fullscreen-toggle[aria-pressed="true"] .fullscreen-exit-icon {
    display: block;
}

input,
select {
    min-width: 0;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    outline: none;
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    padding: 0 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

input:focus,
select:focus,
button:focus-visible {
    border-color: var(--sky);
    box-shadow: 0 0 0 3px rgba(112, 183, 215, 0.22);
}

select option {
    background: #1b2124;
    color: var(--text);
}

.button,
.icon-button,
.mobile-controls button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05)),
        rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 20px rgba(0, 0, 0, 0.22);
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.button {
    padding: 0 12px;
    white-space: nowrap;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.mobile-controls button:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.13);
    border-color: var(--line-strong);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 12px 26px rgba(0, 0, 0, 0.28);
}

.button.primary {
    border-color: rgba(90, 168, 90, 0.7);
    background: rgba(90, 168, 90, 0.22);
}

.button.secondary {
    border-color: rgba(217, 164, 65, 0.7);
    background: rgba(217, 164, 65, 0.2);
}

.button.ghost {
    background: transparent;
}

.button svg,
.icon-button svg,
.mobile-controls svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.game-layout {
    position: relative;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
}

.world-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border-right: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 30%),
        linear-gradient(90deg, rgba(53, 217, 230, 0.045) 1px, transparent 1px),
        linear-gradient(180deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        var(--panel);
    background-size: auto, 24px 24px, 24px 24px, auto;
    box-shadow: var(--shadow);
    z-index: 3;
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 38px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.panel-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: #ffe39a;
    font-size: 0.92rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.panel-title svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.panel-close {
    flex: 0 0 auto;
}

.menu-scrim {
    display: none;
}

.shell.menu-collapsed .game-layout {
    grid-template-columns: minmax(0, 1fr);
}

.shell.menu-collapsed .world-panel {
    display: none;
}

.world-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px 38px;
    gap: 8px;
}

.world-row + .world-row {
    grid-template-columns: minmax(0, 1fr) 38px 38px;
}

.kid-panel {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(240, 189, 78, 0.46);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(99, 187, 105, 0.22), rgba(53, 217, 230, 0.14)),
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 62%),
        var(--panel-solid);
    box-shadow: var(--soft-shadow);
}

.kid-panel-head,
.kid-score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.kid-panel-title,
.kid-score {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.kid-panel-title {
    color: #ffe39a;
    font-size: 1rem;
    font-weight: 800;
}

.kid-panel-title svg,
.kid-score svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.kid-reset {
    height: 34px;
    min-height: 34px;
}

.kid-score {
    flex: 1 1 0;
    justify-content: center;
    min-height: 38px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04)),
        rgba(255, 255, 255, 0.08);
}

.kid-score:first-child {
    color: #ffe27a;
}

.kid-score:last-child {
    color: #8fe5ff;
}

.kid-score strong {
    color: var(--text);
    font-size: 1.05rem;
}

.kid-quest-text {
    margin: 0;
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.3;
}

.character-list {
    display: grid;
    gap: 10px;
}

.character-card {
    position: relative;
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: end;
    gap: 12px;
    min-height: 102px;
    padding: 10px;
    border: 1px solid rgba(114, 209, 238, 0.36);
    border-radius: 8px;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(17, 28, 31, 0.82), rgba(13, 18, 22, 0.94)),
        linear-gradient(135deg, rgba(53, 217, 230, 0.18), transparent 42%),
        linear-gradient(45deg, transparent 0 47%, rgba(236, 111, 189, 0.12) 47% 53%, transparent 53% 100%),
        var(--panel-solid);
    box-shadow: var(--soft-shadow);
}

.character-card::after {
    content: "";
    position: absolute;
    inset: auto 10px 9px 10px;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(90deg, #27d7e8, transparent, #e85fbb);
    opacity: 0.72;
}

.character-image {
    position: relative;
    z-index: 1;
    width: 76px;
    height: 82px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 6px;
    object-fit: contain;
    object-position: 50% 24%;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
        rgba(255, 255, 255, 0.06);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.character-copy {
    position: relative;
    z-index: 1;
    min-width: 0;
    padding-bottom: 12px;
}

.character-copy span {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.character-copy strong {
    display: block;
    margin-top: 3px;
    overflow: hidden;
    color: var(--text);
    font-size: 1.55rem;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    width: 38px;
    padding: 0;
}

.icon-button.danger {
    border-color: rgba(216, 91, 82, 0.55);
    color: #ffb8b2;
}

.palette {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.block-button {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 6px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025)),
        var(--panel-solid);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 16px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.block-button::before {
    content: "";
    position: absolute;
    inset: 8px;
    border-radius: 4px;
    background: var(--swatch);
    box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.2), inset 0 7px 0 rgba(255, 255, 255, 0.16);
}

.block-button.active {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(240, 189, 78, 0.28), 0 10px 22px rgba(0, 0, 0, 0.3);
}

.stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #73bfdc;
}

.stage::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 18%),
        linear-gradient(0deg, rgba(5, 10, 12, 0.14), transparent 28%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
    touch-action: none;
    user-select: none;
}

.reticle {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 18px;
    height: 18px;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 5;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.48));
}

.reticle::before,
.reticle::after {
    content: "";
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.55);
}

.reticle::before {
    left: 8px;
    top: 2px;
    width: 2px;
    height: 14px;
}

.reticle::after {
    left: 2px;
    top: 8px;
    width: 14px;
    height: 2px;
}

.status-pill {
    position: absolute;
    left: 50%;
    top: 18px;
    max-width: min(560px, calc(100% - 32px));
    min-height: 34px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: var(--glass-strong);
    color: var(--text);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -8px);
    transition: opacity 160ms ease, transform 160ms ease;
    text-align: center;
    font-size: 0.92rem;
    z-index: 6;
}

.status-pill.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.status-pill.error {
    border-color: rgba(216, 91, 82, 0.55);
    color: #ffd1cc;
}

.celebration {
    position: absolute;
    left: 50%;
    top: 50%;
    display: grid;
    place-items: center;
    width: min(380px, calc(100% - 32px));
    min-height: 116px;
    padding: 18px;
    border: 2px solid rgba(255, 226, 122, 0.85);
    border-radius: 8px;
    background:
        radial-gradient(circle at 20% 20%, rgba(255, 226, 122, 0.35), transparent 32%),
        radial-gradient(circle at 82% 28%, rgba(39, 215, 232, 0.28), transparent 34%),
        rgba(16, 20, 23, 0.9);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
    color: var(--text);
    font-size: 1.75rem;
    font-weight: 900;
    line-height: 1.1;
    opacity: 0;
    pointer-events: none;
    text-align: center;
    transform: translate(-50%, -48%) scale(0.9);
    transition: opacity 180ms ease, transform 180ms ease;
    z-index: 4;
    backdrop-filter: blur(10px);
}

.celebration.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.stats {
    position: absolute;
    right: 16px;
    bottom: 16px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100% - 32px);
    pointer-events: none;
    z-index: 6;
}

.stats span {
    min-height: 32px;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    background: var(--glass);
    box-shadow: var(--soft-shadow);
    color: var(--text);
    font-size: 0.88rem;
    backdrop-filter: blur(12px);
}

.mobile-controls {
    position: absolute;
    right: 14px;
    bottom: 14px;
    left: 14px;
    display: none;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    --control-size: 58px;
    --control-gap: 8px;
    pointer-events: none;
    touch-action: none;
    z-index: 6;
}

.move-pad,
.action-pad {
    display: grid;
    gap: var(--control-gap);
    pointer-events: auto;
    touch-action: none;
}

.move-pad {
    grid-template-columns: repeat(3, var(--control-size));
    grid-auto-rows: var(--control-size);
}

.action-pad {
    grid-template-columns: repeat(2, var(--control-size));
    grid-auto-rows: var(--control-size);
}

.mobile-controls button {
    flex-direction: column;
    width: var(--control-size);
    height: var(--control-size);
    padding: 0;
    gap: 2px;
    border-color: rgba(255, 255, 255, 0.28);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06)),
        rgba(12, 18, 22, 0.84);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.38);
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mobile-controls span {
    display: block;
    font-size: 0.62rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
}

.mobile-controls button:active,
.mobile-controls button.is-active {
    border-color: rgba(255, 226, 122, 0.86);
    background:
        linear-gradient(180deg, rgba(255, 226, 122, 0.26), rgba(240, 189, 78, 0.16)),
        rgba(12, 18, 22, 0.9);
    transform: scale(0.96);
}

.move-pad button[data-move="forward"] {
    grid-column: 2;
    grid-row: 1;
}

.move-pad button[data-move="left"] {
    grid-column: 1;
    grid-row: 2;
}

.move-pad button[data-move="back"] {
    grid-column: 2;
    grid-row: 2;
}

.move-pad button[data-move="right"] {
    grid-column: 3;
    grid-row: 2;
}

@media (max-width: 1366px), (pointer: coarse) {
    .mobile-controls {
        display: flex;
    }

    .status-pill {
        top: 66px;
    }

    .stats {
        top: 14px;
        right: 14px;
        bottom: auto;
    }
}

@media (max-width: 1050px) {
    body {
        overflow: hidden;
    }

    .shell {
        height: 100dvh;
        min-height: 0;
    }

    .topbar {
        align-items: center;
        flex-direction: row;
        min-height: 58px;
        padding-bottom: 10px;
    }

    .account {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .game-layout {
        display: block;
        height: 100%;
        min-height: 0;
    }

    .world-panel {
        position: absolute;
        inset: 0 auto 0 0;
        display: flex;
        flex-direction: column;
        width: min(382px, calc(100vw - 18px));
        height: 100%;
        gap: 10px;
        max-height: none;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 12px;
        border-top: 0;
        border-right: 1px solid var(--line);
        box-shadow: 18px 0 34px rgba(0, 0, 0, 0.36);
        opacity: 1;
        transform: translateX(0);
        transition: transform 180ms ease, opacity 180ms ease;
        z-index: 8;
    }

    .stage {
        width: 100%;
        height: 100%;
        min-height: 0;
    }

    .shell.menu-collapsed .world-panel {
        display: flex;
        pointer-events: none;
        opacity: 0;
        transform: translateX(calc(-100% - 10px));
    }

    .menu-scrim {
        position: absolute;
        inset: 0;
        z-index: 7;
        display: block;
        border: 0;
        border-radius: 0;
        background: rgba(2, 5, 9, 0.44);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    .shell:not(.menu-collapsed) .menu-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .world-panel > .world-row:first-child,
    .world-panel > .world-row:nth-child(2) {
        grid-column: auto;
    }

    .world-panel > .character-list {
        grid-column: auto;
        grid-row: auto;
    }

    .world-panel > .kid-panel {
        grid-column: auto;
    }

    .world-panel > .palette {
        grid-column: auto;
    }

    input,
    select,
    .button,
    .icon-button {
        min-height: 44px;
        font-size: 16px;
    }

    .icon-button {
        width: 44px;
    }

    .world-row,
    .world-row + .world-row {
        grid-template-columns: minmax(0, 1fr) 44px 44px;
    }

    .character-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .kid-panel {
        grid-template-columns: 1fr;
        align-items: center;
    }

    .kid-panel-head {
        grid-column: 1 / -1;
    }

    .kid-score-row {
        min-width: 0;
    }

    .kid-quest-text {
        align-self: center;
    }

    .palette {
        grid-template-columns: repeat(5, minmax(44px, 1fr));
    }

    .character-card {
        grid-template-columns: 62px minmax(0, 1fr);
        min-height: 78px;
        padding: 8px;
        gap: 8px;
    }

    .character-image {
        width: 62px;
        height: 62px;
    }

    .character-copy {
        padding-bottom: 8px;
    }

    .character-copy span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .character-copy strong {
        font-size: 1.25rem;
    }

    .mobile-controls {
        display: flex;
        right: max(12px, env(safe-area-inset-right));
        left: max(12px, env(safe-area-inset-left));
        bottom: max(12px, env(safe-area-inset-bottom));
        --control-size: clamp(52px, 7.5vw, 64px);
        --control-gap: clamp(7px, 1.2vw, 10px);
    }

    .status-pill {
        top: 64px;
    }

    .stats {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        bottom: auto;
    }
}

@media (pointer: coarse) {
    .mobile-controls {
        display: flex;
    }
}

@media (min-width: 701px) and (max-width: 1050px),
    (pointer: coarse) and (min-width: 701px),
    (min-width: 701px) and (max-width: 1280px) and (max-height: 900px) {
    .shell {
        height: 100dvh;
        min-height: 0;
    }

    .topbar {
        flex-wrap: nowrap;
        min-height: 64px;
        padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
    }

    .brand {
        min-width: 0;
    }

    .brand-name {
        font-size: clamp(1.02rem, 1.6vw, 1.2rem);
    }

    .account {
        flex-wrap: nowrap;
        gap: 10px;
    }

    .account-name {
        display: none;
    }

    .game-layout {
        display: block;
        height: 100%;
        min-height: 0;
    }

    .stage {
        width: 100%;
        height: 100%;
        min-height: 0;
    }

    .world-panel {
        position: absolute;
        inset: 0 auto 0 0;
        display: flex;
        flex-direction: column;
        width: min(430px, calc(100vw - 24px));
        height: 100%;
        max-height: none;
        min-height: 0;
        padding: 14px;
        border-top: 0;
        border-right: 1px solid var(--line);
        box-shadow: 18px 0 38px rgba(0, 0, 0, 0.38);
        opacity: 1;
        transform: translateX(0);
        transition: transform 180ms ease, opacity 180ms ease;
        z-index: 8;
    }

    .shell.menu-collapsed .world-panel {
        display: flex;
        pointer-events: none;
        opacity: 0;
        transform: translateX(calc(-100% - 12px));
    }

    .menu-scrim {
        position: absolute;
        inset: 0;
        z-index: 7;
        display: block;
        border: 0;
        border-radius: 0;
        background: rgba(2, 5, 9, 0.44);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    .shell:not(.menu-collapsed) .menu-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .character-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .palette {
        grid-template-columns: repeat(5, minmax(48px, 1fr));
    }

    .mobile-controls {
        display: flex;
        right: max(22px, env(safe-area-inset-right));
        left: max(22px, env(safe-area-inset-left));
        bottom: max(20px, env(safe-area-inset-bottom));
        gap: clamp(20px, 6vw, 72px);
        --control-size: clamp(64px, 7.2vw, 78px);
        --control-gap: clamp(10px, 1.3vw, 14px);
    }

    .mobile-controls button {
        border-color: rgba(255, 255, 255, 0.28);
        background: rgba(13, 18, 23, 0.86);
        box-shadow: 0 16px 34px rgba(0, 0, 0, 0.38);
    }

    .mobile-controls svg {
        width: 20px;
        height: 20px;
    }

    .mobile-controls span {
        font-size: 0.68rem;
    }

    .stats {
        top: max(14px, env(safe-area-inset-top));
        right: max(18px, env(safe-area-inset-right));
        max-width: min(420px, calc(100% - 36px));
    }

    .stats span:first-child {
        display: none;
    }

    .status-pill {
        top: 76px;
        max-width: min(520px, calc(100% - 36px));
    }
}

@media (min-width: 900px) and (max-width: 1280px) and (max-height: 900px),
    (pointer: coarse) and (orientation: landscape) and (min-width: 900px) {
    .world-panel {
        width: min(390px, calc(100vw - 28px));
    }

    .mobile-controls {
        right: max(28px, env(safe-area-inset-right));
        left: max(28px, env(safe-area-inset-left));
        bottom: max(18px, env(safe-area-inset-bottom));
        --control-size: clamp(62px, 5.8vw, 76px);
        --control-gap: clamp(9px, 1vw, 13px);
    }

    .status-pill {
        top: 74px;
    }
}

@media (max-width: 1100px) and (min-height: 521px) {
    .lock-stage {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
        align-items: center;
        justify-items: center;
        gap: 14px;
    }

    .lock-art {
        width: min(100%, 560px);
        height: min(56dvh, 640px);
    }

    .lock-panel {
        width: min(520px, 100%);
    }
}

@media (max-width: 900px) {
    .lock-stage {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
        align-items: center;
        justify-items: center;
        gap: 14px;
        padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    }

    .lock-stage::before {
        background:
            linear-gradient(180deg, rgba(5, 8, 15, 0.04) 0%, rgba(5, 8, 15, 0.18) 42%, rgba(5, 8, 15, 0.9) 100%),
            linear-gradient(90deg, rgba(5, 8, 15, 0.08), rgba(5, 8, 15, 0.28));
    }

    .lock-art {
        width: min(100%, 540px);
        height: min(58dvh, 650px);
    }

    .lock-panel {
        width: min(520px, 100%);
        background: rgba(10, 15, 22, 0.84);
    }
}

@media (max-width: 700px) {
    .world-panel {
        display: flex;
        flex-direction: column;
        grid-template-columns: 1fr;
        gap: 8px;
        height: 100%;
        max-height: none;
        padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .world-panel > .world-row:first-child,
    .world-panel > .world-row:nth-child(2),
    .world-panel > .character-list,
    .world-panel > .kid-panel,
    .world-panel > .palette {
        flex: 0 0 auto;
        grid-column: 1;
        grid-row: auto;
    }

    .character-list {
        display: flex;
        gap: 8px;
        min-width: 0;
        overflow-x: auto;
        padding-bottom: 4px;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
    }

    .kid-panel {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 9px;
    }

    .kid-panel-head {
        grid-column: auto;
    }

    .kid-score {
        min-height: 34px;
        padding: 6px;
    }

    .world-row,
    .world-row + .world-row {
        grid-template-columns: minmax(0, 1fr) 42px 42px;
        gap: 6px;
    }

    input,
    select,
    .button,
    .icon-button {
        min-height: 42px;
        height: 42px;
    }

    .icon-button {
        width: 42px;
    }

    .palette {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 46px;
        grid-template-columns: none;
        grid-template-rows: 46px;
        min-width: 0;
        overflow-x: auto;
        padding-bottom: 5px;
        scrollbar-width: thin;
    }

    .block-button {
        min-height: 46px;
    }

    .character-card {
        flex: 0 0 min(76vw, 188px);
        grid-template-columns: 54px minmax(0, 1fr);
        min-height: 70px;
        align-items: center;
        scroll-snap-align: start;
    }

    .character-image {
        width: 54px;
        height: 58px;
        object-fit: contain;
        background: rgba(255, 255, 255, 0.06);
    }

    .character-copy {
        padding-bottom: 8px;
    }

    .character-copy span {
        font-size: 0.66rem;
        letter-spacing: 0.05em;
    }

    .character-copy strong {
        font-size: 1.08rem;
    }
}

@media (max-width: 560px) {
    .lock-stage {
        grid-template-rows: minmax(0, 1fr) auto;
        gap: 10px;
        padding: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    }

    .lock-art {
        width: 100%;
        height: min(54dvh, 470px);
    }

    .lock-panel {
        width: 100%;
        padding: 18px;
        background: rgba(8, 13, 21, 0.88);
    }

    .lock-brand {
        justify-content: center;
        margin-bottom: 14px;
    }

    .password-form label {
        text-align: center;
    }

    .topbar {
        padding: 10px;
        flex-wrap: nowrap;
    }

    .world-panel {
        padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .topbar {
        gap: 10px;
    }

    .brand {
        min-width: 0;
    }

    .brand-mark {
        width: 32px;
        height: 32px;
    }

    .brand-name {
        font-size: 1rem;
    }

    .account-name {
        display: none;
    }

    .account {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .menu-toggle span,
    .fullscreen-toggle span,
    .account .button.ghost span {
        display: none;
    }

    .button {
        padding: 0 10px;
    }

    .character-copy strong {
        font-size: 1rem;
    }

    .kid-panel-title {
        font-size: 0.95rem;
    }

    .kid-score strong {
        font-size: 1rem;
    }

    .kid-quest-text {
        font-size: 0.88rem;
    }

    .celebration {
        min-height: 96px;
        font-size: 1.35rem;
    }

    .stats {
        top: 10px;
        right: 10px;
        bottom: auto;
        max-width: calc(100% - 20px);
    }

    .stats span {
        font-size: 0.8rem;
        min-height: 30px;
        padding: 6px 8px;
    }

    .stats span:first-child {
        display: none;
    }
}

@media (max-width: 380px) {
    .lock-art {
        height: min(52dvh, 430px);
    }

    .lock-panel {
        padding: 16px;
    }

    .password-row {
        grid-template-columns: 1fr;
    }

    .password-row .button {
        width: 100%;
    }

    .character-card {
        flex-basis: min(82vw, 172px);
        grid-template-columns: 48px minmax(0, 1fr);
        min-height: 64px;
        padding: 7px;
    }

    .character-image {
        width: 48px;
        height: 50px;
    }

    .character-copy span {
        font-size: 0.62rem;
    }

    .character-copy strong {
        font-size: 1rem;
    }

    .mobile-controls {
        --control-size: 46px;
        --control-gap: 6px;
    }
}

@media (max-width: 1050px) and (max-height: 520px) {
    .lock-stage {
        grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
        grid-template-rows: 1fr;
        align-items: center;
        justify-items: center;
        gap: 12px;
        padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    }

    .lock-stage::before {
        background:
            linear-gradient(90deg, rgba(5, 8, 15, 0.06) 0%, rgba(5, 8, 15, 0.28) 42%, rgba(5, 8, 15, 0.88) 100%),
            linear-gradient(180deg, rgba(5, 8, 15, 0.08), rgba(5, 8, 15, 0.46));
    }

    .lock-art {
        width: 100%;
        height: calc(100dvh - 20px);
        max-height: 500px;
    }

    .lock-panel {
        width: 100%;
        padding: 16px;
    }

    .lock-brand {
        margin-bottom: 12px;
    }

    .topbar {
        min-height: 48px;
        padding-top: max(6px, env(safe-area-inset-top));
        padding-bottom: 6px;
    }

    .world-panel {
        max-height: none;
        grid-template-columns: 1fr;
    }

    .kid-panel {
        display: none;
    }

    .character-card {
        min-height: 60px;
    }

    .character-image {
        width: 48px;
        height: 50px;
    }

    .palette {
        grid-auto-columns: 40px;
        grid-template-rows: 40px;
    }

    .block-button {
        min-height: 40px;
    }

    .mobile-controls {
        --control-size: 48px;
        --control-gap: 7px;
    }
}

@media (max-width: 1050px) and (orientation: landscape) and (min-width: 700px) {
    .game-layout {
        display: block;
    }

    .world-panel {
        display: flex;
        flex-direction: column;
        width: min(340px, calc(100vw - 18px));
        height: 100%;
        max-height: none;
        min-height: 0;
        padding: 10px;
        border-right: 1px solid var(--line);
        box-shadow: var(--shadow);
    }

    .stage {
        width: 100%;
        height: 100%;
    }

    .world-panel > .world-row:first-child,
    .world-panel > .world-row:nth-child(2),
    .world-panel > .character-list,
    .world-panel > .kid-panel,
    .world-panel > .palette {
        flex: 0 0 auto;
        grid-column: auto;
        grid-row: auto;
    }

    .world-row,
    .world-row + .world-row {
        grid-template-columns: minmax(0, 1fr) 42px 42px;
    }

    .kid-panel {
        display: grid;
        grid-template-columns: 1fr;
    }

    .kid-panel-head {
        grid-column: auto;
    }

    .character-list {
        display: grid;
        grid-template-columns: 1fr;
        overflow-x: visible;
        padding-bottom: 0;
    }

    .character-card {
        flex: none;
        grid-template-columns: 54px minmax(0, 1fr);
        min-height: 70px;
    }

    .character-image {
        width: 54px;
        height: 56px;
        object-fit: contain;
    }

    .palette {
        grid-auto-columns: auto;
        grid-auto-flow: row;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        grid-template-rows: none;
        overflow-x: visible;
        padding-bottom: 0;
    }

    .block-button {
        min-height: 40px;
    }
}

@media (max-width: 1050px),
    (pointer: coarse),
    (max-width: 1280px) and (max-height: 900px) {
    .shell[data-menu="open"] .world-panel {
        pointer-events: auto;
        opacity: 1;
        transform: translateX(0);
    }

    .shell[data-menu="open"] .menu-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .shell[data-menu="closed"] .world-panel {
        pointer-events: none;
        opacity: 0;
        transform: translateX(calc(-100% - 12px));
    }

    .shell[data-menu="closed"] .menu-scrim {
        opacity: 0;
        pointer-events: none;
    }
}
