:root {
  --bg: #0b1020;
  --panel: #151c33;
  --panel2: #1d2644;
  --line: #2a3560;
  --text: #f3f5ff;
  --dim: #9aa4c7;
  --accent: #7c5cff;
  --good: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- library ---------- */
#library { max-width: 640px; margin: 0 auto; padding: calc(var(--sat) + 14px) 16px calc(var(--sab) + 28px); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { border-radius: 11px; flex: none; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; line-height: 1.1; }
.net { margin: 3px 0 0; font-size: 13px; color: var(--dim); display: flex; align-items: center; gap: 6px; }
.net::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.net.on::before { background: var(--good); }
.net.off::before { background: var(--warn); }
.round { width: 44px; height: 44px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); font-size: 19px; flex: none; display: grid; place-items: center; }
.round:active { background: var(--panel2); }

.btn { padding: 10px 16px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-weight: 650; font-size: 15px; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn.solid { background: var(--accent); border-color: transparent; color: #fff; }
.btn[disabled] { opacity: .5; }
.btn.big { display: block; width: 100%; padding: 14px; font-size: 17px; margin-top: 10px; }

.install, .saved { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 16px; margin-bottom: 12px; }
.install { background: linear-gradient(135deg, #3a2a8a, #1f2a66); position: relative; padding-right: 40px; }
.install div, .saved div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.install span, .saved span { font-size: 13px; color: var(--dim); }
.install span { color: #cfd5ff; }
.install .x { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; color: #cfd5ff; font-size: 13px; }
.saved { background: var(--panel); border: 1px solid var(--line); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.game { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; gap: 8px; position: relative; overflow: hidden; }
.game .art { height: 84px; border-radius: 12px; display: grid; place-items: center; font-size: 44px; background: linear-gradient(140deg, color-mix(in srgb, var(--c) 55%, #0b1020), color-mix(in srgb, var(--c) 18%, #0b1020)); }
.game h3 { margin: 2px 0 0; font-size: 16px; line-height: 1.2; }
.game p { margin: 0; font-size: 12.5px; color: var(--dim); min-height: 2.8em; }
.game .meta { font-size: 12px; color: var(--dim); display: flex; justify-content: space-between; gap: 6px; }
.game .meta .ok { color: var(--good); }
.game .row { display: flex; gap: 6px; margin-top: auto; }
.game .row .btn { flex: 1; padding: 10px 8px; }
.game .row .bin { flex: none; width: 42px; padding: 10px 0; color: var(--dim); }
.game .btn.play { background: var(--c); color: #0b1020; border-color: transparent; }
.game .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--c); width: 0; transition: width .25s; }

.foot { margin-top: 22px; text-align: center; color: var(--dim); font-size: 13px; }
.foot p { margin: 4px 0; }
.small { font-size: 11px; opacity: .6; }

/* ---------- player ---------- */
#player { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.bar { display: flex; align-items: center; gap: 8px; padding: calc(var(--sat) + 8px) 10px 8px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.bar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar .title strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title span { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.3em; }
.bar .score { display: flex; gap: 12px; }
.bar .score span { display: flex; flex-direction: column; align-items: center; min-width: 40px; }
.bar .score small { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.bar .score b { font-size: 18px; font-variant-numeric: tabular-nums; line-height: 1.1; }
#stage { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; padding-bottom: var(--sab); }
#stage canvas { display: block; position: absolute; left: 0; top: 0; }

.over, .sheet { position: fixed; inset: 0; background: rgba(5, 8, 20, .78); display: grid; place-items: center; padding: 24px; z-index: 20; animation: fade .18s; }
.over .card, .sheet .card { width: 100%; max-width: 330px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 22px; text-align: center; }
.card h2 { margin: 0 0 6px; font-size: 24px; }
.card p { margin: 0 0 8px; color: var(--dim); }
.newbest { color: var(--warn) !important; font-weight: 700; }
.sheet ol { text-align: left; padding-left: 22px; margin: 10px 0 6px; color: var(--text); }
.sheet li { margin: 8px 0; }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 20px); transform: translateX(-50%); background: #fff; color: #0b1020; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 30; max-width: 90vw; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
