:root {
  --bg: #070d1c;
  --panel: #0f1830;
  --panel-2: #131e3a;
  --edge: #a8cfff;
  --edge-in: #263a63;
  --ink: #f4f6ff;
  --muted: #9aa6d0;
  --cyan: #74e6ff;
  --gold: #ffd45f;
  --good: #6cf0ad;
  --bad: #ff6f88;
  --violet: #b98cff;
  --font: "DotGothic16", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100vh; background: radial-gradient(1200px 500px at 50% -10%, #1a2552 0%, var(--bg) 60%); }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
kbd { display: inline-block; min-width: 1.6em; padding: 0 .3em; margin: 0 1px; border: 2px solid #3a4c7c; border-bottom-width: 3px; border-radius: 3px; background: #10193a; font-size: .85em; text-align: center; line-height: 1.3; }

#app { max-width: 1280px; margin: 0 auto; padding: 10px 12px 18px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; letter-spacing: .08em; }
.brand img { width: 40px; height: 30px; object-fit: cover; image-rendering: pixelated; border: 2px solid var(--edge); }
.top-actions { display: flex; gap: 6px; align-items: center; }

.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; background: var(--panel); border: 2px solid #3a4c7c; border-radius: 3px; cursor: pointer; font-size: 13px; }
.chip .dot { width: 9px; height: 9px; background: #58617e; box-shadow: 0 0 0 2px #0006; }
.chip.ok { border-color: var(--good); }
.chip.ok .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.chip.warn .dot { background: var(--gold); }
.chip.err .dot { background: var(--bad); }

.icon-btn { width: 36px; height: 34px; display: inline-grid; place-items: center; background: var(--panel); border: 2px solid #3a4c7c; border-radius: 3px; cursor: pointer; font-size: 15px; }
.icon-btn:hover, .chip:hover { border-color: var(--edge); }

/* ---------- stage ---------- */
.stage { position: relative; aspect-ratio: 8 / 3; width: 100%; background: #0a1328; border: 4px solid var(--edge); box-shadow: 0 0 0 4px #14203a, 0 24px 60px #0009; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: #070d1c; font-size: 22px; letter-spacing: .2em; color: var(--muted); z-index: 50; }

/* HUD */
.hud { position: absolute; left: 0; right: 0; top: 0; display: grid; grid-template-columns: auto 1fr auto; gap: 1.2%; align-items: start; padding: 1% 1.2%; pointer-events: none; z-index: 5; font-size: clamp(10px, 1.35vw, 17px); }
.hud > * { pointer-events: auto; }
.hud-l, .hud-r { display: flex; align-items: center; gap: .6em; background: rgba(9, 15, 34, .82); border: 3px solid var(--edge); box-shadow: inset 0 0 0 2px var(--edge-in); padding: .35em .6em; }
.pp { width: 3.6em; height: 2.7em; border: 2px solid var(--edge); overflow: hidden; }
.pp img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; display: block; }
.hearts { font-size: 1.35em; letter-spacing: .1em; color: #ff5d7c; text-shadow: 0 2px 0 #0008; line-height: 1; }
.hearts .off { color: #3b3452; }
.hearts .stepmode { font-size: .7em; color: var(--cyan); letter-spacing: .05em; }
.lvname { color: var(--muted); font-size: .8em; margin-top: .2em; white-space: nowrap; }
.hud-c { align-self: center; }
.prog { height: .7em; background: #070b18cc; border: 2px solid #3a4c7c; }
.prog div { height: 100%; width: 0; background: linear-gradient(90deg, #7a89ff, #c080ff); transition: width .25s; }
.prog.boss div { background: linear-gradient(90deg, #ff6f88, #ffb35f); }
.progtxt { font-size: .75em; color: #cfd8ff; margin-top: .25em; text-shadow: 0 1px 2px #000; }
.stat { text-align: right; min-width: 4.8em; }
.stat small { display: block; color: var(--muted); font-size: .65em; }
.stat b { font-size: 1.25em; font-weight: normal; }
.stat.combo b { color: var(--gold); }
.stat.combo em { font-style: normal; font-size: .95em; padding: 0 .35em; margin-left: .2em; background: #2a3354; color: #aab4da; }
.cgauge { height: .3em; background: #070b18; margin-top: .15em; }
.cgauge i { display: block; height: 100%; width: 0; background: #7a89ff; transition: width .2s; }
.stat.combo.t1 em { background: #74e6ff; color: #04202a; }
.stat.combo.t1 .cgauge i { background: #74e6ff; }
.stat.combo.t2 em { background: #ffd45f; color: #2a1c00; }
.stat.combo.t2 .cgauge i { background: #ffd45f; }
.stat.combo.t3 em { background: linear-gradient(90deg, #c882ff, #ff8fd8); color: #1c0630; animation: pop .6s infinite; }
.stat.combo.t3 .cgauge i { background: linear-gradient(90deg, #c882ff, #ff8fd8); }
.stat.combo.t3 b { color: #e4b8ff; text-shadow: 0 0 8px #c882ff; }
.stat.combo.pop b { animation: pop .25s; }
@keyframes pop { 50% { transform: scale(1.35); } }
.hud .icon-btn { width: 2.2em; height: 2em; font-size: .9em; }

/* screens */
.screen { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 2%; overflow: auto; background: rgba(5, 9, 22, .35); }
#scrTitle { background: linear-gradient(90deg, rgba(5, 9, 22, .0) 30%, rgba(5, 9, 22, .6) 70%); justify-items: end; padding-right: 7%; }
.title-box { text-align: center; }
.title-box h1 { margin: 0; font-size: clamp(34px, 6.6vw, 84px); line-height: .95; letter-spacing: .06em; font-weight: normal; color: #fff; text-shadow: 0 4px 0 #3a2a7a, 0 8px 0 #120b2b, 0 0 30px #7b6cff88; }
.tag { color: #cfd8ff; margin: .9em 0 1.2em; font-size: clamp(11px, 1.3vw, 16px); text-shadow: 0 2px 3px #000; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; min-width: 220px; margin: 0 auto; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; min-width: 0; }
.hint-line { color: var(--muted); font-size: 12px; margin-top: 1em; text-shadow: 0 1px 2px #000; }

.btn { padding: 10px 18px; background: #1b2748; border: 3px solid #4a5f95; border-radius: 3px; cursor: pointer; font-size: 16px; letter-spacing: .05em; box-shadow: 0 4px 0 #0a1024; transition: transform .05s; }
.btn:hover { border-color: var(--edge); background: #22305a; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0a1024; }
.btn.primary { background: #5b5fe8; border-color: #b8c0ff; box-shadow: 0 4px 0 #2b2a86; }
.btn.primary:hover { background: #6d71f5; }
.btn.small { padding: 6px 12px; font-size: 13px; border-width: 2px; box-shadow: 0 3px 0 #0a1024; }
.btn.danger { border-color: #a0415a; }
.btn:disabled { opacity: .4; cursor: default; }

.panel { background: rgba(12, 20, 42, .95); border: 3px solid var(--edge); box-shadow: inset 0 0 0 3px var(--edge-in), 0 12px 40px #000a; padding: 16px 18px; max-height: 100%; overflow: auto; }
.panel.wide { width: min(100%, 1000px); }
.panel.narrow { min-width: 280px; text-align: center; }
.panel h2 { margin: 0 0 12px; font-weight: normal; letter-spacing: .1em; font-size: 26px; }
.panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }

.tabs { display: flex; border: 2px solid #3a4c7c; }
.tab { background: transparent; border: 0; padding: 6px 16px; cursor: pointer; color: var(--muted); }
.tab.on { background: #5b5fe8; color: #fff; }
.mode-desc { color: var(--muted); font-size: 12px; }

.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.lv { text-align: left; background: var(--panel-2); border: 2px solid #33456f; padding: 9px 10px; cursor: pointer; display: grid; gap: 3px; position: relative; border-radius: 2px; }
.lv:hover, .lv:focus-visible { border-color: var(--cyan); background: #19264a; outline: none; }
.lv .n { color: var(--cyan); font-size: 11px; }
.lv .t { font-size: 15px; }
.lv .d { color: var(--muted); font-size: 11px; line-height: 1.35; min-height: 2.7em; }
.lv .b { display: flex; justify-content: space-between; font-size: 12px; color: #cfd8ff; }
.lv .st { color: var(--gold); letter-spacing: 2px; }
.lv .st i { color: #3b4466; font-style: normal; }
.lv.sel { border-color: var(--gold); }
.lv.check { background: linear-gradient(135deg, #1d2140, #231a3f); border-color: #5a4a8a; }
.lv.next { border-color: var(--good); box-shadow: 0 0 0 1px var(--good), 0 0 14px #6cf0ad44; }
.lv .ps { margin-left: 6px; padding: 0 5px; background: var(--gold); color: #2a1c00; font-weight: normal; font-size: 10px; }
.lv .nx { margin-left: 6px; padding: 0 5px; background: var(--good); color: #062516; font-weight: normal; font-size: 10px; }
.levels .ch { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 10px; margin: 10px 0 0; padding: 4px 2px; border-bottom: 2px solid #2d3d66; font-size: 16px; }
.levels .ch:first-child { margin-top: 0; }
.levels .ch span { color: var(--cyan); font-size: 12px; }
.levels .ch em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }

/* result */
.result { width: min(100%, 780px); text-align: center; }
.result h2 { font-size: 34px; margin-bottom: 4px; }
.result h2.clear { color: var(--gold); }
.result h2.over { color: var(--bad); }
.stars { font-size: 34px; letter-spacing: 8px; color: var(--gold); min-height: 1.1em; text-shadow: 0 3px 0 #6b4a00; }
.stars i { color: #2d3558; font-style: normal; text-shadow: none; }
.res-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; margin: 10px 0 16px; text-align: left; }
.res-score small { display: block; color: var(--muted); font-size: 12px; }
.res-score b { font-size: 40px; font-weight: normal; }
.pass { min-height: 1.4em; font-size: 15px; color: var(--muted); margin-top: 2px; }
.pass b { color: #fff; font-weight: normal; }
.pass.ok { color: var(--good); }
.pass.ok b { color: var(--good); }
.panel-head .order { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.panel-head .order select { font-size: 12px; padding: 3px 6px; }
.rank { display: inline-block; min-width: 1.4em; font-size: 52px; line-height: 1; letter-spacing: 0; text-shadow: 0 4px 0 #0008; }
.rank.r-Splus { color: #ff8fd8; text-shadow: 0 0 18px #c882ff, 0 4px 0 #0008; }
.rank.r-S { color: var(--gold); }
.rank.r-A { color: var(--cyan); }
.rank.r-B { color: var(--good); }
.rank.r-C { color: var(--muted); }
.lv .rk { color: var(--gold); }
.newbest { margin-left: 10px; color: #1a1000; background: var(--gold); padding: 2px 8px; font-size: 13px; vertical-align: middle; animation: pop 1s infinite; }
.res-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.res-table td { padding: 3px 0; border-bottom: 1px dashed #2a3a63; }
.res-table td:last-child { text-align: right; }
.res-weak { background: #0a1228; border: 2px solid #2a3a63; padding: 10px 12px; }
.res-weak h3 { margin: 0 0 6px; font-weight: normal; font-size: 14px; color: var(--muted); }
.res-weak ol { margin: 0; padding-left: 1.3em; font-size: 15px; }
.res-weak li { margin: 4px 0; }
.res-weak li span { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* settings */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
fieldset { border: 2px solid #2d3d66; margin: 0; padding: 10px 12px; display: grid; gap: 8px; }
legend { color: var(--cyan); padding: 0 6px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.row.check { justify-content: flex-start; }
select { background: #111a36; border: 2px solid #3a4c7c; padding: 5px 8px; border-radius: 2px; }
input[type=range] { width: 55%; accent-color: #7a89ff; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: #7a89ff; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* how to */
.howto { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; font-size: 14px; line-height: 1.6; }
.howto h3 { margin: 4px 0; color: var(--cyan); font-weight: normal; }
.howto ul { margin: 0 0 10px; padding-left: 1.2em; }
.howto b { font-weight: normal; color: var(--gold); }
.howto b.bad { color: var(--bad); }

/* ---------- deck (below stage) ---------- */
.deck { display: grid; grid-template-columns: 1.1fr 1.1fr .8fr; gap: 8px; margin-top: 10px; }
.card { background: var(--panel); border: 3px solid var(--edge); box-shadow: inset 0 0 0 2px var(--edge-in); padding: 8px 12px; min-height: 104px; }
.card small { color: var(--muted); font-size: 11px; letter-spacing: .15em; }
.card .big { font-size: 34px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--muted); font-size: 13px; }
.target .big { color: #fff; text-shadow: 0 0 14px #5de8ff88; }
.tones { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.tones span { min-width: 38px; padding: 1px 6px 2px; text-align: center; background: #0a1228; border: 2px solid #33456f; font-size: 14px; line-height: 1.2; }
.tones span i { display: block; font-style: normal; font-size: 10px; color: #8fa0d8; }
.tones span.q { color: #46557f; }
.target .big .staff { vertical-align: middle; margin-right: 8px; }
.staff line { stroke: #c9d3f5; stroke-width: 1; }
.staff text { fill: #fff; font-family: "Apple Symbols", "Noto Music", "Segoe UI Symbol", serif; font-size: 15px; text-anchor: middle; }
.staff text.clef { font-size: 38px; text-anchor: start; }
.target .big .qk { vertical-align: middle; font-size: 28px; }
.card .desc { color: var(--muted); font-size: 11px; margin-top: 4px; }
.tones span.bass { border-color: var(--gold); color: var(--gold); }
.played .big { color: var(--good); }
.played .big.none { color: #46557f; }
.feedback { font-size: 13px; margin-top: 4px; min-height: 1.3em; }
.feedback .bad { color: var(--bad); }
.feedback .ok { color: var(--good); }
.tools { display: flex; flex-direction: column; gap: 7px; align-items: stretch; justify-content: center; }
.tools kbd { font-size: 10px; }
.oct { color: var(--muted); font-size: 12px; text-align: center; }

.piano-wrap { grid-column: 1 / -1; overflow-x: auto; background: #050a16; border: 3px solid var(--edge); box-shadow: inset 0 0 0 2px var(--edge-in); padding: 6px; }
.piano { position: relative; height: 150px; min-width: 860px; user-select: none; -webkit-user-select: none; touch-action: none; }
.key { position: absolute; top: 0; cursor: pointer; }
.key.white { height: 100%; background: linear-gradient(#f4f4fa, #dcdde8); border: 1px solid #9ea3b8; border-radius: 0 0 4px 4px; z-index: 1; }
.key.black { height: 62%; background: linear-gradient(#262b3d, #11141f); border: 1px solid #000; border-radius: 0 0 3px 3px; z-index: 2; }
.key b { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-weight: normal; font-size: 10px; color: #6a6f86; }
.key .kb { position: absolute; left: 0; right: 0; text-align: center; font-style: normal; font-size: 11px; }
.key.white .kb { bottom: 20px; color: #9aa0bb; }
.key.black .kb { bottom: 5px; color: #8b90ad; }
.key.hint.white { background: linear-gradient(#f4f4fa, #c6f3ff); }
.key.hint.black { background: linear-gradient(#2b4d66, #193346); }
.key.hint::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); width: 10px; height: 10px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.key.white.hint::after { bottom: 38px; }
.key.black.hint::after { bottom: 22px; }
.key.hint-bass::after { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.key.on.white { background: linear-gradient(#b4ffd6, #6cf0ad); }
.key.on.black { background: linear-gradient(#9b86ff, #6a52e0); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .deck { grid-template-columns: 1fr 1fr; }
  .tools { grid-column: 1 / -1; flex-direction: row; min-height: 0; }
  .card { min-height: 86px; }
  .card .big { font-size: 26px; }
  .howto { grid-template-columns: 1fr; }
  .res-grid { grid-template-columns: 1fr; }
  /* menus need more room than the 8:3 stage offers on phones */
  .screen { position: fixed; z-index: 40; background: rgba(5, 9, 22, .92); padding: 12px; }
  #scrTitle { justify-items: center; padding-right: 12px; background: rgba(5, 9, 22, .78); }
  .title-box h1 { font-size: 48px; }
  .btn { padding: 8px 14px; font-size: 15px; }
  .top-actions .chip span { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 480px) {
  .brand span { display: none; }
  .piano { min-width: 640px; height: 130px; }
}
