*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0d0a16;
    --panel: #1d1730;
    --line: #3b3157;
    --text: #f2eefb;
    --muted: #a99cc4;
    --accent: #b76cff;
    --hot: #ff5fa2;
    --cool: #4fd8e8;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed; inset: 0; overflow: hidden;
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at 50% 100%, rgba(183, 108, 255, 0.18), transparent 60%),
        linear-gradient(180deg, #07050d, #150f24);
    user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.shell {
    display: flex; flex-direction: column;
    height: 100%; min-height: 100dvh;
    max-width: 560px; margin: 0 auto;
    padding:
        max(6px, env(safe-area-inset-top))
        max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(8px, env(safe-area-inset-left));
}

.toolbar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; height: 38px; }
.toolbar-spacer { flex: 1; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 31px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 9px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 0.88rem; line-height: 1;
    text-decoration: none; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.icon-btn-text { font-size: 0.76rem; font-weight: 600; }
.icon-btn:active { transform: scale(0.94); border-color: var(--accent); }

.hud { display: flex; gap: 5px; flex: 0 0 auto; margin: 5px 0; }

.hud span {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 4px 2px; border-radius: 9px; background: rgba(255, 255, 255, 0.06);
}

.hud b { font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.hud i { font-style: normal; font-size: 0.56rem; letter-spacing: 0.08em; color: var(--muted); }

.board-area { flex: 1 1 auto; min-height: 0; display: flex; align-items: stretch; justify-content: center; }
#board { display: block; border-radius: 12px; touch-action: none; }

/* The four keys. They are the whole control scheme on a phone, so they are as
   tall as they can be without pushing the lanes off the screen. */
.keys { display: flex; gap: 6px; flex: 0 0 auto; margin-top: 6px; }

.key {
    flex: 1; min-height: 76px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); border-radius: 14px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 1.5rem; line-height: 1; cursor: pointer;
    transition: transform 0.06s ease, background 0.06s ease;
}
.key.is-down { transform: scale(0.96); background: rgba(183, 108, 255, 0.3); border-color: var(--accent); }

.hint-text { margin-top: 5px; text-align: center; font-size: 0.66rem; color: var(--muted); min-height: 1.2em; }

.overlay {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 18px;
    background: rgba(6, 4, 12, 0.9);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    z-index: 50;
}

.overlay.is-open { display: flex; }

.panel {
    width: 100%; max-width: 340px; max-height: 100%; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
    padding: 22px 18px;
    border: 1px solid var(--line); border-radius: 20px;
    background: linear-gradient(180deg, #2a2143, #140f22);
    text-align: center; animation: pop 0.22s ease;
}

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

.title {
    font-size: clamp(1.8rem, 8vw, 2.4rem); font-weight: 800; letter-spacing: 0.08em;
    background: linear-gradient(135deg, #ffd0ec, var(--accent) 55%, var(--cool));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.panel-title { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.06em; color: var(--accent); }
.subtitle { color: var(--muted); font-size: 0.85rem; line-height: 1.7; }

.grade {
    font-size: 3.4rem; font-weight: 900; line-height: 1;
    background: linear-gradient(135deg, #ffe6a0, var(--hot) 50%, var(--accent));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.modes { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.mode {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 15px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.95rem; font-weight: 700; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.mode small { font-size: 0.68rem; font-weight: 500; color: var(--muted); }
.mode:active { transform: scale(0.98); border-color: var(--accent); }

/* Choosing how hard it is, as a row rather than a list: it is a second choice
   made straight after the tune, not a menu of its own. */
.levels { display: flex; gap: 6px; }
.level {
    flex: 1; padding: 9px 4px;
    border: 1px solid var(--line); border-radius: 11px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.level.is-on { border-color: var(--accent); background: rgba(183, 108, 255, 0.22); }

.btn {
    min-height: 46px; padding: 12px 20px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.92rem; font-weight: 700;
    text-decoration: none; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

.btn:active { transform: scale(0.97); }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, #e3b6ff, #a45ce8); color: #16081f; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { padding: 9px 6px; border-radius: 11px; background: rgba(255, 255, 255, 0.06); }
.stat b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.62rem; color: var(--muted); }

@media (max-height: 700px) {
    .hud { margin: 3px 0; }
    .key { min-height: 62px; }
    .hint-text { display: none; }
}

@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }
