* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

:root { --ink: #eaf3fb; --gold: #ffd166; --accent: #63d9c0; --muted: #8fa5bb; }

html, body {
    height: 100%; overflow: hidden; background: #16212e; color: var(--ink);
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
.wrap { position: relative; width: 100%; height: 100dvh; }
#stage { display: block; width: 100%; height: 100%; touch-action: none; }

.hud {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; align-items: flex-start; gap: 7px;
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud > * { pointer-events: auto; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 38px; height: 36px; padding: 0 8px;
    border: 1px solid rgba(99, 217, 192, 0.28); border-radius: 10px;
    background: rgba(10, 18, 28, 0.55); color: var(--ink);
    font-size: 15px; font-weight: 700; text-decoration: none; cursor: pointer; flex: 0 0 auto;
    backdrop-filter: blur(6px);
}
.icon-btn-text { font-size: 13px; }
.hud-mid { flex: 1; text-align: center; pointer-events: none; }
.level-name { font-size: 16px; font-weight: 800; text-shadow: 0 2px 6px rgba(0,0,0,0.6); }
.timer { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.timer b { color: var(--ink); }
.dot { margin: 0 5px; opacity: 0.5; }

.hint {
    position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
    padding: 7px 16px; border-radius: 10px;
    background: rgba(10, 18, 28, 0.7); color: var(--muted);
    font-size: 13px; white-space: nowrap; pointer-events: none;
    opacity: 0; transition: opacity 0.3s;
}
.hint.show { opacity: 1; }

.pedal {
    position: absolute; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    padding: 9px 22px; border-radius: 999px;
    border: 1px solid rgba(99, 217, 192, 0.35);
    background: rgba(10, 18, 28, 0.5);
    font-size: 13px; font-weight: 700; color: var(--accent);
    pointer-events: none; opacity: 0.85;
}
.pedal.on { background: rgba(99, 217, 192, 0.3); color: #06231d; opacity: 1; }

.overlay {
    position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
    padding: 20px; background: rgba(8, 13, 20, 0.9); z-index: 20;
}
.overlay.is-open { display: flex; }
.overlay-card {
    width: 100%; max-width: 330px; padding: 24px 20px; border-radius: 20px;
    background: linear-gradient(180deg, #24384d, #17232f);
    border: 1px solid rgba(99, 217, 192, 0.22); text-align: center;
}
.overlay-wide { max-width: 420px; }
.title { font-size: 30px; letter-spacing: 4px; color: var(--accent); }
.subtitle { margin: 8px 0 18px; font-size: 13px; color: var(--muted); }
.over-title { font-size: 25px; color: var(--accent); letter-spacing: 3px; }
.over-title.lose { color: #ff8f7a; }
.over-sub { margin: 4px 0 12px; font-size: 13px; color: var(--muted); min-height: 18px; }
.stars { margin-top: 8px; font-size: 26px; letter-spacing: 5px; color: var(--gold); min-height: 32px; }

.btn {
    min-height: 46px; padding: 0 18px;
    border: 1px solid rgba(99, 217, 192, 0.28); border-radius: 13px;
    background: rgba(0, 0, 0, 0.24); color: var(--ink);
    font-size: 16px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.btn-primary {
    background: linear-gradient(140deg, #7ff0d6, #2fae95);
    border-color: #a5f7e6; color: #05231c;
}
.btn-wide { width: 100%; margin-top: 8px; }
.how { margin-top: 18px; text-align: left; }
.how-row {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 5px 0; font-size: 12px; color: var(--muted);
}
.how-key { color: var(--ink); font-weight: 600; flex: 0 0 auto; }
.result-row {
    display: flex; justify-content: space-between;
    padding: 7px 4px; font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.level-grid {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px; margin: 14px 0;
}
.level-cell {
    padding: 10px 6px; border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(0, 0, 0, 0.24);
    color: var(--ink); font: inherit; cursor: pointer;
}
.level-cell.done { border-color: rgba(99, 217, 192, 0.45); background: rgba(99, 217, 192, 0.12); }
.level-cell .num { display: block; font-size: 16px; font-weight: 800; }
.level-cell .nm { display: block; margin-top: 1px; font-size: 11px; color: var(--muted); }
.level-cell .st { display: block; margin-top: 3px; font-size: 11px; color: var(--gold); min-height: 14px; }
