@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Zen+Kaku+Gothic+New:wght@400;500;700&display=swap');

:root {
    --font-scale: 1;
    --ink: #142333;
    --muted: #5d7184;
    --panel: rgba(255, 255, 255, .96);
    --line: #d4e0e8;
    --cyan: #087e9a;
    --red: #d63d61;
    --gold: #a66d00;
    --green: #15945d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    height: 100vh;
    padding: 18px;
    overflow: hidden;
    overflow-x: hidden;
    background: linear-gradient(135deg, #dff5f7 0%, #eef4fa 48%, #f9e8ef 100%);
    color: var(--ink);
    font-family: 'Zen Kaku Gothic New', 'Space Grotesk', sans-serif;
    font-size: calc(16px * var(--font-scale));
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: .3;
    background: linear-gradient(rgba(31, 91, 119, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(31, 91, 119, .045) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.game {
    width: 100%;
    height: 100%;
    margin: auto;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 18px;
    height: 58px;
    margin-bottom: 12px;
}

h1 {
    margin: 0;
    font: 700 clamp(25px, 4vw, 42px) / 1 'Space Grotesk', sans-serif;
}

h1 span {
    color: var(--red);
}

.stats {
    display: flex;
    gap: 9px;
}

.stat {
    min-width: 126px;
    padding: 11px 15px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, .46);
    box-shadow: 0 10px 26px rgba(28, 61, 82, .12), inset 0 1px 0 rgba(255, 255, 255, .7);
    backdrop-filter: blur(16px) saturate(125%);
}

.stat small {
    display: block;
    color: var(--muted);
    font: 600 calc(11px * var(--font-scale)) 'Space Grotesk', sans-serif;
    letter-spacing: .16em;
}

.stat b {
    font: 700 calc(25px * var(--font-scale)) 'Space Grotesk', sans-serif;
}

.layout {
    display: grid;
    grid-template-columns: 55% 45%;
    justify-content: space-between;
    height: calc(100% - 70px);
}

.panel,
.typing {
    border: 1px solid var(--line);
    border-radius: 15px;
    background: rgba(255, 255, 255, .46);
    box-shadow: 0 12px 34px rgba(28, 61, 82, .12);
    backdrop-filter: blur(20px) saturate(125%);
}

.panel {
    padding: 20px;
    height: 100%;
}

.panel:first-child {
    display: flex;
    flex-direction: column;
}

.scene-wrap {
    position: relative;
    height: 100%;
    overflow: hidden;
    border: 1px solid #27506a;
    border-radius: 10px;
    background: #02070e;
}

.scene-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 42%, #02060e99 100%), linear-gradient(transparent 50%, #5de7ff08 50%);
    background-size: auto, 100% 4px;
    mix-blend-mode: screen;
}

.scene-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.scene-hud {
    position: absolute;
    inset: 14px;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    color: #b3d8e8;
    font: 600 10px 'Space Grotesk', sans-serif;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.signal {
    display: flex;
    align-items: center;
    gap: 7px;
}

.signal i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 12px var(--green);
}

.coords {
    color: #6d91a8;
}

.help {
    margin: 9px 2px 0;
    color: var(--muted);
    font-size: calc(12px * var(--font-scale));
}

.map-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1px 2px 10px;
}

.map-head h2 {
    margin: 0;
    font: 600 calc(14px * var(--font-scale)) 'Space Grotesk', sans-serif;
    letter-spacing: .12em;
}

.map-head span {
    color: var(--muted);
    font-size: calc(11px * var(--font-scale));
}

.map {
    display: grid;
    grid-template-columns: repeat(var(--map-columns, 15), 1fr);
    width: 100%;
    aspect-ratio: 1;
    gap: 2px;
    padding: 7px;
    border: 1px solid #c9dce5;
    border-radius: 10px;
    background: rgba(255, 255, 255, .32);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65);
}

.cell {
    position: relative;
    border-radius: 2px;
    background: #dce9ef;
}

.wall {
    background: linear-gradient(135deg, #516f80, #294958);
    box-shadow: inset 0 0 0 1px #83b4c4, 0 0 4px rgba(31, 91, 119, .45);
}

.cell.hidden {
    background: #b8c4c8;
    box-shadow: none;
}

.cell.hidden::before, .cell.hidden::after { display: none; }
.cell.hidden.wall, .cell.hidden.lock, .cell.hidden.goal, .cell.hidden.player { background: #b8c4c8; box-shadow: none; }

.lock {
    background: #ffdce5;
    box-shadow: 0 0 9px #ff557d88;
}

.goal {
    background: #ffe7a8;
    box-shadow: 0 0 12px #d69d22;
}

.player {
    z-index: 1;
    background: var(--green);
    box-shadow: 0 0 12px #15945d88;
}

.legend {
    display: flex;
    justify-content: space-between;
    margin-top: 11px;
    color: var(--muted);
    font-size: calc(11px * var(--font-scale));
}

.legend b {
    color: var(--ink);
    font-weight: 500;
}

.pause-top {
    position: fixed;
    top: 88px;
    right: 28px;
    z-index: 7;
}

.typing {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 6;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px 18px;
    width: min(760px, calc(100% - 56px));
    margin: 0;
    padding: 20px 24px;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 20px);
    transition: opacity .2s, transform .2s;
}

.typing.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}

.prompt {
    color: var(--muted);
    font-size: 16px;
}

.word {
    min-height: 48px;
    color: var(--cyan);
    font: 700 38px / 1.2 'Space Grotesk', sans-serif;
    letter-spacing: .08em;
}

.typing input {
    grid-column: 1 / -1;
    width: 100%;
    padding: 16px 18px;
    border: 1px solid #b9cbd5;
    border-radius: 8px;
    outline: 0;
    background: rgba(255, 255, 255, .58);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7);
    color: var(--ink);
    font: 600 22px 'Space Grotesk', sans-serif;
    text-align: center;
}

.msg {
    grid-column: 1 / -1;
    min-height: 20px;
    color: var(--gold);
    font-size: 16px;
    font-weight: 700;
}

.button {
    padding: 13px 20px;
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 9px;
    background: rgba(255, 255, 255, .34);
    color: #14506a;
    font: 600 15px 'Space Grotesk', sans-serif;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(20, 65, 84, .08), inset 0 1px 0 rgba(255, 255, 255, .7);
    backdrop-filter: blur(12px);
}

.button:hover, .button:focus-visible { background: rgba(255, 255, 255, .62); }

.loading-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(220, 239, 244, .72); color: var(--ink); backdrop-filter: blur(16px); }
.loading-box { width: min(620px, calc(100% - 36px)); min-height: 430px; padding: 52px clamp(28px, 8vw, 76px) 44px; border: 1px solid rgba(255, 255, 255, .78); border-radius: 28px; background: rgba(255, 255, 255, .48); box-shadow: 0 30px 90px rgba(20, 65, 84, .22), inset 0 1px 0 rgba(255, 255, 255, .85); backdrop-filter: blur(28px) saturate(135%); }
.loading-logo { width: min(460px, 100%); aspect-ratio: 16 / 9; margin: 0 auto 30px; animation: logo-pulse 1.5s ease-in-out infinite; }
.loading-label { margin: 0 0 16px; font: 700 14px 'Space Grotesk', sans-serif; letter-spacing: .14em; text-align: center; }
.progress-track { height: 10px; overflow: hidden; border: 1px solid #b7c8d2; background: #e3edf1; }
.progress-bar { width: 0; height: 100%; background: var(--red); transition: width .08s linear; }
.progress-value { margin: 10px 0 18px; color: var(--muted); font: 700 13px 'Space Grotesk', sans-serif; text-align: right; }
.launch-button { width: 100%; }
.launch-button.is-disabled { opacity: .45; cursor: wait; }
.loading-logo img { display: block; width: 100%; height: 100%; object-fit: contain; }
@keyframes logo-pulse { 50% { transform: translateY(-8px) rotate(1deg); } }
.loading-screen.is-complete { opacity: 0; pointer-events: none; transition: opacity .35s; }

.overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    place-items: center;
    background: rgba(20, 35, 51, .28);
    backdrop-filter: blur(10px);
}

.overlay.show {
    display: grid;
}

.overlay[hidden] { display: none; }

#pause-overlay[hidden] { display: none; }
.pause-actions { display: grid; gap: 10px; margin-top: 22px; }
.rules-overlay { z-index: 12; padding: 24px; }
section.modal.rules-panel { position: relative; width: min(800px, 100%); max-height: calc(100vh - 48px); overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; padding: clamp(28px, 7vw, 44px); border: 1px solid rgba(255, 255, 255, .72); border-radius: 20px; background: rgba(255, 255, 255, .62); box-shadow: 0 24px 70px rgba(20, 35, 51, .2), inset 0 1px 0 rgba(255, 255, 255, .8); backdrop-filter: blur(28px) saturate(130%); text-align: left; }
section.modal.rules-panel::-webkit-scrollbar { display: none; }
section.modal.rules-panel h2 { margin: 8px 0 14px; color: var(--cyan); font-family: inherit; font-size: 32px; text-align: left; }
.rules-panel .eyebrow { color: var(--red); font: 700 12px / 1.2 'Space Grotesk', sans-serif; }
.rules-panel > p { line-height: 1.8; }
.rules-steps { display: grid; gap: 14px; margin: 22px 0 0; padding: 0; list-style: none; counter-reset: rules; }
.rules-steps li { position: relative; display: grid; gap: 3px; padding: 13px 15px 13px 45px; border: 1px solid rgba(255, 255, 255, .62); border-radius: 10px; background: rgba(255, 255, 255, .24); counter-increment: rules; }
.rules-steps li::before { content: counter(rules); position: absolute; top: 13px; left: 15px; color: var(--red); font: 700 18px 'Space Grotesk', sans-serif; }
.rules-steps b { color: var(--ink); }
.rules-steps span { color: var(--muted); line-height: 1.8; }

.modal {
    width: min(430px, 90%);
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, .62);
    box-shadow: 0 24px 70px rgba(20, 35, 51, .2), inset 0 1px 0 rgba(255, 255, 255, .8);
    backdrop-filter: blur(28px) saturate(130%);
    text-align: center;
}

.modal h2 {
    margin: 0 0 8px;
    color: var(--cyan);
    font: 700 calc(32px * var(--font-scale)) 'Space Grotesk', sans-serif;
}

.modal p {
    color: var(--muted);
    line-height: 1.8;
}

.result-actions {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.result-actions .button {
    width: 100%;
    color: #14506a;
    text-decoration: none;
}

.publish-modal { width: min(440px, 100%); }
.publish-modal .eyebrow { margin: 0 0 8px; color: var(--red); font: 700 12px / 1.2 'Space Grotesk', sans-serif; letter-spacing: .12em; }
.publish-modal h2 { margin: 0 0 10px; }
.publish-modal p { color: var(--muted); line-height: 1.7; }
.publish-name { display: grid; gap: 7px; margin-top: 18px; color: var(--muted); font-size: 13px; }
.publish-name input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, .7); color: var(--ink); font: inherit; }
.publish-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }

.difficulty-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.difficulty-actions .button {
    padding-inline: 6px;
}

.fallback {
    display: none;
    padding: 26px;
    color: var(--red);
    font-weight: 700;
}

.tutorial-levels {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}

.tutorial-levels a {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 8px;
    background: rgba(255, 255, 255, .38);
    color: var(--cyan);
    font-weight: 700;
    text-decoration: none;
}

.topbar img { width: 200%; max-width: 300px; }

.modal__close { position: absolute; top: 12px; right: 14px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .35); color: var(--muted); font-size: 28px; line-height: 1; cursor: pointer; }