:root {
    --bg: #0a0514;
    --ink: #fbefff;
    --muted: #b39ac8;
    --accent: #ff5fd2;
    --accent-2: #ffb347;
    --danger: #ff5470;
    --gold: #ffcf40;
    --line: rgba(255, 140, 230, 0.24);
}

* { 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, 95, 210, 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(40, 18, 58, 0.72);
    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(10, 5, 20, 0.76);
    -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(44, 22, 66, 0.95), rgba(18, 9, 32, 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, 95, 210, 0.07);
}

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: 84px; margin: 0 auto 10px; }
.logo i { position: absolute; left: 0; right: 0; height: 3px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.logo i:first-child { top: 0; }
.logo i:last-child { bottom: 0; }
.logo b {
    position: absolute;
    left: 50%;
    top: 3px;
    width: 26px; height: 26px;
    margin-left: -13px;
    border-radius: 7px;
    background: #fff;
    box-shadow: 0 0 16px var(--accent), inset 0 -7px 0 var(--accent-2);
    animation: flip 2.2s cubic-bezier(0.7, 0, 0.3, 1) infinite;
}
@keyframes flip {
    0%, 35% { transform: translateY(0) scaleY(-1); }
    50%, 85% { transform: translateY(52px) scaleY(1); }
    100% { transform: translateY(0) scaleY(-1); }
}

.howto {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    color: #e6d3f2;
}
.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-flip { border-radius: 4px; background: #fff; box-shadow: inset 0 -4px 0 var(--accent); }
.dot-danger { border-radius: 3px; background: linear-gradient(90deg, #ff3d6e 50%, #ff9a3d 50%); }
.dot-hole { border-radius: 0; background: #000; border: 2px solid #ff3d6e; border-bottom: 0; }
.dot-orb { background: linear-gradient(90deg, var(--gold) 50%, #7fe9ff 50%); }

.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: #1c0518;
    border: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    box-shadow: 0 8px 26px rgba(255, 95, 210, 0.3);
}
.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, 95, 210, 0.16); border-color: rgba(255, 95, 210, 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, 95, 210, 0.55);
}
.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, 95, 210, 0.18); outline: 1px solid rgba(255, 95, 210, 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; }
}
