:root {
    --bg: #080a1c;
    --ink: #f4f1ff;
    --muted: #9aa0c8;
    --accent: #ffc24a;
    --accent-2: #3fe0d0;
    --danger: #ff5470;
    --gold: #ffcf40;
    --line: rgba(150, 170, 255, 0.26);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

#stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
}

/* ---------- HUD ---------- */
.hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud-mid { text-align: center; }
.hud-right { display: flex; justify-content: flex-end; gap: 8px; }

.score {
    font-size: clamp(28px, 7vw, 40px);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 18px rgba(255, 194, 74, 0.5);
}
.sub {
    margin-top: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--muted);
}
.sub span { color: var(--ink); }

.pills { display: flex; justify-content: center; gap: 6px; margin-top: 6px; min-height: 22px; }
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
}
.pill i { width: 9px; height: 9px; border-radius: 50%; }
.pill.orb i { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.pill.shield { color: #7fe9ff; border-color: rgba(127, 233, 255, 0.6); }
.pill.shield i { border: 2px solid #7fe9ff; }

.tool {
    pointer-events: auto;
    width: 40px; height: 40px;
    display: grid; place-items: center;
    padding: 0;
    color: var(--ink);
    background: rgba(22, 26, 62, 0.74);
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
}
.tool svg { width: 20px; height: 20px; fill: currentColor; }
.tool .cross { display: none; }
.tool.muted .wave { display: none; }
.tool.muted .cross { display: inline; }
.tool:active { transform: scale(0.94); }

/* ---------- transient messages ---------- */
.banner {
    position: fixed;
    top: calc(92px + env(safe-area-inset-top));
    left: 0; right: 0;
    z-index: 4;
    text-align: center;
    font-size: clamp(22px, 6vw, 34px);
    font-weight: 900;
    letter-spacing: 0.12em;
    color: #fff;
    text-shadow: 0 0 24px var(--accent);
    opacity: 0;
    pointer-events: none;
}
.banner.show { animation: banner 1.3s ease-out; }
@keyframes banner {
    0% { opacity: 0; transform: scale(0.7); }
    15% { opacity: 1; transform: scale(1.08); }
    70% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.05); }
}

.hint {
    position: fixed;
    left: 16px; right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 4;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    opacity: 0.85;
    pointer-events: none;
    animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: 0.45; } }

/* ---------- screens ---------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    padding: 16px;
    background: rgba(6, 8, 24, 0.78);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    overflow-y: auto;
}
.card {
    width: min(420px, 100%);
    margin: auto;
    padding: 24px 22px 20px;
    text-align: center;
    background: linear-gradient(180deg, rgba(28, 32, 74, 0.95), rgba(12, 14, 36, 0.97));
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(255, 194, 74, 0.06);
}

h1, h2 { margin: 0; font-weight: 900; letter-spacing: 0.04em; }
h1 {
    font-size: clamp(34px, 10vw, 46px);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
h2 { font-size: 26px; margin-bottom: 14px; }

.tagline { margin: 6px 0 16px; color: var(--muted); font-size: 15px; }

.logo { position: relative; width: 120px; height: 92px; margin: 0 auto 10px; }
.logo i {
    position: absolute;
    left: 22px; right: 22px; bottom: 4px;
    height: 10px;
    border-radius: 6px;
    border: 2px solid var(--accent-2);
    background: rgba(63, 224, 208, 0.28);
    box-shadow: 0 0 12px var(--accent-2);
}
.logo b {
    position: absolute;
    left: 50%; bottom: 14px;
    width: 24px; height: 24px;
    margin-left: -12px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff, #ffd98a 45%, #ff9a2e);
    box-shadow: 0 0 16px var(--accent);
    animation: hop 0.9s cubic-bezier(0.3, 0.6, 0.6, 1) infinite alternate;
}
@keyframes hop {
    from { transform: translateY(0) scale(1.12, 0.86); }
    12% { transform: translateY(-6px) scale(0.94, 1.08); }
    to { transform: translateY(-54px) scale(1); }
}

.howto {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    color: #d6dbf5;
}
.howto li { display: flex; gap: 10px; align-items: flex-start; padding: 5px 0; }
.howto strong { color: #fff; }
.dot { flex: none; width: 12px; height: 12px; margin-top: 3px; border-radius: 50%; }
.dot-move { background: radial-gradient(circle at 35% 30%, #fff, #ffb347); }
.dot-slam { border-radius: 3px; background: linear-gradient(180deg, #ffe27a, #ff9a2e); transform: scaleX(0.6); }
.dot-danger { border-radius: 3px; background: linear-gradient(90deg, #ff3d6e 34%, #ff9a3d 34% 67%, #5dff9a 67%); }
.dot-flood { border-radius: 3px 3px 6px 6px; background: linear-gradient(180deg, #ff46aa, #5a148c); }

.keys { margin: 12px 0 0; font-size: 12px; letter-spacing: 0.12em; color: var(--muted); }

.btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 14px 16px;
    font: inherit;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:hover { filter: brightness(1.12); }
.btn:focus-visible, .tool:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary {
    color: #1a1204;
    border: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    box-shadow: 0 8px 26px rgba(255, 194, 74, 0.28);
}
.btn.ghost { background: rgba(255, 255, 255, 0.03); }
.btn.small { width: auto; margin: 0; padding: 0 16px; font-size: 14px; white-space: nowrap; background: rgba(255, 194, 74, 0.16); border-color: rgba(255, 194, 74, 0.55); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- game over ---------- */
.newbest {
    display: inline-block;
    margin-bottom: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #2a1c00;
    background: var(--gold);
    border-radius: 999px;
}
.final {
    font-size: clamp(48px, 15vw, 68px);
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 28px rgba(255, 194, 74, 0.5);
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.stats div { padding: 10px 4px; background: rgba(255, 255, 255, 0.04); border-radius: 12px; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.save { display: flex; gap: 8px; }
.save input {
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--line);
    border-radius: 12px;
    -webkit-user-select: text;
    user-select: text;
}
.save .btn { height: 44px; }

.note { min-height: 18px; margin: 10px 0 6px; font-size: 13px; color: var(--muted); }

.board { list-style: none; margin: 0 0 6px; padding: 0; text-align: left; font-size: 14px; }
.board li {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 10px;
    border-radius: 10px;
    font-variant-numeric: tabular-nums;
}
.board li:nth-child(odd) { background: rgba(255, 255, 255, 0.035); }
.board li.me { background: rgba(255, 194, 74, 0.18); outline: 1px solid rgba(255, 194, 74, 0.55); }
.board .rank { font-weight: 800; color: var(--muted); }
.board li:nth-child(1) .rank { color: var(--gold); }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 800; }
.board .empty { display: block; text-align: center; color: var(--muted); background: none; }

@media (max-height: 560px) {
    .card { padding: 14px 18px; }
    .logo { display: none; }
    .howto { font-size: 13px; margin-bottom: 8px; }
    .howto li { padding: 2px 0; }
    .btn { padding: 10px 14px; margin-top: 8px; }
    .stats { margin: 10px 0; }
}

@media (prefers-reduced-motion: reduce) {
    .logo b, .hint { animation: none; }
}
