* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;                 /* no pull-to-refresh reload mid-song */
  -webkit-tap-highlight-color: transparent;  /* no grey flash on every tap */
}
button, input, select, textarea { font-family: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* dvh: mobile URL-bar safe. minmax(0,1fr): an auto row takes its item's max-content
   height, so a tall canvas grew the row past the window and pushed the play controls
   out of sight — the 0 minimum lets the row be exactly the window height. */
#app { display: grid; grid-template-columns: 248px 1fr; grid-template-rows: minmax(0, 1fr);
  height: 100vh; height: 100dvh; }

/* ---------- Sidebar ---------- */
#sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 18px; }
.brand-mark { font-size: 28px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 18px; letter-spacing: .3px; }
.brand-text span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }

#nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--muted); cursor: pointer;
  border: 1px solid transparent; font-size: 14px; transition: var(--speed);
  text-decoration: none;
}
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.nav-item.active .ico { filter: drop-shadow(0 0 6px var(--accent)); }
.nav-sep { font-size: 10px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--muted); opacity: .65; padding: 14px 12px 4px; }

.sidebar-foot { padding-top: 12px; border-top: 1px solid var(--line); margin-top: 8px; }
.io-indicator { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.io-row { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.io-row span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.io-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.io-dot.in.live { background: var(--good); box-shadow: 0 0 8px var(--good); }
.io-dot.out { background: var(--accent); }

/* ---------- Main ---------- */
#main { display: flex; flex-direction: column; overflow: hidden; }
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
#crumb { font-size: 15px; font-weight: 600; }
#crumb small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.health-mini { width: 140px; height: 12px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); overflow: hidden; position: relative; }
.health-mini::after { content: ""; position: absolute; inset: 0; width: var(--h, 100%);
  background: linear-gradient(90deg, var(--bad), var(--warn) 45%, var(--good));
  transition: width 200ms; }
.coin-chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); font-size: 13px; text-decoration: none; font-variant-numeric: tabular-nums; }
.coin-chip:hover { border-color: var(--warn); }
.coin-chip b { color: var(--warn); }
.streak-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px;
  border-radius: 999px; font-size: 13px; color: var(--warn);
  background: color-mix(in srgb, var(--warn) 16%, var(--panel-2)); border: 1px solid var(--warn); }
.streak-chip.cold { color: var(--muted); background: var(--panel-2); border-color: var(--line); }
#theme-quick, select.input, input.input, textarea.input {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; outline: none;
}
select.input:focus, input.input:focus, textarea.input:focus { border-color: var(--accent); }

/* min-height:0 or the flex item is sized by its content instead of the window —
   the canvas reports its own (stale, larger) pixel height, which pushed the play
   controls below the fold. Also what makes .play-shell's height:100% definite. */
#view { padding: 22px; overflow-y: auto; flex: 1; min-height: 0; }
#view.no-pad { padding: 0; }

/* ---------- Generic components ---------- */
.row { display: flex; gap: var(--gap); flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.grid { display: grid; gap: var(--gap); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.page-head { margin-bottom: 18px; }
.page-head p { color: var(--muted); margin: 4px 0 0; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px;
}
.panel.tight { padding: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: var(--speed);
  display: flex; flex-direction: column; gap: 8px;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .title { font-weight: 600; }
.card .sub { font-size: 12px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tag.beginner { color: var(--good); border-color: var(--good); }
.tag.intermediate { color: var(--warn); border-color: var(--warn); }
.tag.advanced { color: var(--bad); border-color: var(--bad); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 15px; cursor: pointer; font-size: 14px;
  transition: var(--speed);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.lg { padding: 12px 22px; font-size: 15px; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.field .input, label.field select, label.field input, label.field textarea { color: var(--text); }

.slider { display: flex; align-items: center; gap: 10px; }
.slider input[type=range] { flex: 1; accent-color: var(--accent); }
.slider .val { width: 44px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat .num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
table.data tr:hover td { background: var(--panel-2); }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; font-size: 13px; }
.pill.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.progress { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- Toasts ---------- */
#toast-host { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 15px; min-width: 220px; max-width: 360px;
  box-shadow: 0 8px 28px rgba(0,0,0,.35); animation: toast-in 180ms ease; font-size: 14px; }
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Tuner ---------- */
.tuner-wrap { display: grid; grid-template-columns: 1fr; gap: 20px; max-width: 720px; margin: 0 auto; }
.tuner-display { text-align: center; padding: 26px; }
.tuner-note { font-size: 86px; font-weight: 800; line-height: 1; letter-spacing: -2px; }
.tuner-note small { font-size: 26px; vertical-align: super; color: var(--muted); }
.tuner-freq { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 4px; }
.tuner-meter { position: relative; height: 70px; margin: 22px 0 8px; }
.tuner-needle { position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: var(--accent);
  transform-origin: bottom center; transition: transform 90ms linear, background 120ms; }
.tuner-scale { position: absolute; inset: auto 0 0 0; height: 2px; background: var(--line); }
.tuner-center { position: absolute; bottom: 0; left: 50%; width: 2px; height: 18px; background: var(--muted); transform: translateX(-50%); }
.tuner-verdict { font-size: 16px; font-weight: 600; }
.tuner-verdict.intune { color: var(--good); }
.tuner-verdict.flat, .tuner-verdict.sharp { color: var(--warn); }
.string-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.string-btn { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--line);
  background: var(--panel-2); cursor: pointer; font-weight: 700; font-size: 15px; transition: var(--speed); }
.string-btn.target { border-color: var(--accent); }
.string-btn.intune { border-color: var(--good); background: color-mix(in srgb, var(--good) 18%, var(--panel-2)); }

/* ---------- Highway / Play ---------- */
.play-shell { position: relative; height: 100%; display: flex; flex-direction: column; }
/* Canvas + HUD live on a stage so (a) the overlay covers the highway and not the
   control bar, and (b) the canvas can shrink: a flex item's min-height is auto,
   which for a canvas means its own intrinsic height — the one the ResizeObserver
   keeps writing back. It could grow but never shrink, so on a short screen it
   pushed the controls off the bottom. */
.play-stage { position: relative; flex: 1; min-height: 0; }
#highway-canvas, #kara-canvas { display: block; width: 100%; height: 100%; background: var(--highway); }
.play-overlay { position: absolute; inset: 0; pointer-events: none; }
.play-hud { position: absolute; top: 14px; left: 14px; right: 14px; display: flex;
  justify-content: space-between; align-items: flex-start; pointer-events: none; }
.hud-box { background: rgba(0,0,0,.42); backdrop-filter: blur(4px); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 12px; pointer-events: auto; }
.play-avatar { width: 52px; height: 60px; flex: none; background: rgba(0,0,0,.42);
  backdrop-filter: blur(4px); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 2px; pointer-events: auto; }
.killfeed { position: absolute; right: 16px; top: 70px; display: flex; flex-direction: column;
  gap: 6px; align-items: flex-end; pointer-events: none; }
.kill { padding: 5px 11px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: rgba(0,0,0,.5); border: 1px solid var(--line); animation: toast-in 140ms; }
.kill.perfect { color: var(--j-perfect); border-color: var(--j-perfect); }
.kill.good { color: var(--j-good); border-color: var(--j-good); }
.kill.off { color: var(--j-off); border-color: var(--j-off); }
.kill.miss { color: var(--j-miss); border-color: var(--j-miss); }
.healthbar-big { height: 16px; border-radius: 10px; background: rgba(0,0,0,.4);
  border: 1px solid var(--line); overflow: hidden; width: 260px; }
.healthbar-big > i { display: block; height: 100%; transition: width 160ms;
  background: linear-gradient(90deg, var(--bad), var(--warn) 50%, var(--good)); }
.play-controls { display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  border-top: 1px solid var(--line); background: var(--bg-2); flex-wrap: wrap; }
.play-bottom-fade { position:absolute; left:0; right:0; bottom:0; height:90px; pointer-events:none;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.25)); }
.lyric-line { position:absolute; left:0; right:0; bottom:18px; text-align:center; font-size:22px;
  font-weight:700; text-shadow: 0 2px 10px rgba(0,0,0,.8); pointer-events:none; --kw-future: var(--muted); }
.lyric-line .kw { color: var(--kw-future); transition: color 90ms; }
.lyric-line .kw.done { color: var(--accent); }
.lyric-line .kw.cur { -webkit-background-clip: text; background-clip: text; color: transparent; }
.banner { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; }
.banner .panel { text-align:center; max-width: 480px; }
.big-grade { font-size: 64px; font-weight: 800; }

/* ---------- Karaoke ---------- */
.view-pad { padding: 22px; }
.kara-pick { cursor: pointer; transition: transform 120ms, border-color 120ms; }
.kara-pick:hover { transform: translateY(-2px); border-color: var(--accent); }
.kara-stage { position:absolute; left:0; right:0; top:46%; transform: translateY(-50%);
  text-align:center; pointer-events:none; padding: 0 6%; --kw-future: var(--muted); }
.kara-stage > div { text-shadow: 0 2px 14px rgba(0,0,0,.85); line-height: 1.18; }
.kara-countin { height: 26px; letter-spacing: 8px; color: var(--accent); font-size: 18px; opacity: .85; }
.kara-prev { font-size: 20px; opacity: .4; min-height: 24px; }
.kara-cur { font-size: clamp(28px, 5vw, 54px); font-weight: 800; margin: 6px 0 10px; min-height: 60px; }
.kara-next { font-size: 24px; opacity: .62; min-height: 28px; }
.kara-next2 { font-size: 19px; opacity: .34; min-height: 22px; }
.kara-cur .kw { color: var(--kw-future); transition: color 90ms; }
.kara-cur .kw.done { color: var(--accent); }
.kara-cur .kw.cur { -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Editor / piano roll ---------- */
.roll-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--highway); }
#roll-canvas { display: block; width: 100%; cursor: crosshair; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: 220px; display: block; }
.legend { display:flex; gap:14px; flex-wrap:wrap; font-size:12px; color: var(--muted); }
.legend i { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:5px; vertical-align: middle; }

/* ---------- Minigame ---------- */
.quiz-choices { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quiz-choice { padding: 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; font-size: 16px; text-align:center; transition: var(--speed); }
.quiz-choice:hover { border-color: var(--accent); }
.quiz-choice.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 20%, var(--panel-2)); }
.quiz-choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 20%, var(--panel-2)); }

/* ---------- Fretboard / capo ---------- */
.capo-note { display:inline-flex; align-items:center; gap:8px; padding:6px 12px; border-radius:999px;
  border:1px solid var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Mobile vs desktop ----------
   Three switches, each keyed to what it actually detects:
     width   -> how much layout fits (rail, then bottom tab bar)
     pointer -> finger or mouse (touch target size)
     height  -> landscape phone, where the note highway wants the whole screen
   ponytail: no JS device sniffing and no manual mode toggle — the browser already
   knows all three, and "Request desktop site" is a built-in browser menu item.
   Add a stored override only if someone actually wants mobile layout on a desktop. */

/* Tablet / narrow: collapse the sidebar to a centered icon rail. */
@media (max-width: 820px) {
  #app { grid-template-columns: 60px 1fr; }
  .brand-text, .nav-item span:not(.ico), .io-indicator { display: none; }
  #sidebar { padding: 14px 6px; }
  .brand { justify-content: center; padding: 6px 0 14px; }
  .nav-item { justify-content: center; padding: 11px 0; gap: 0; }
  .nav-item .ico { font-size: 19px; }
  .nav-sep { text-align: center; padding: 12px 0 4px; font-size: 8px; letter-spacing: .6px; }
}

/* Phones: trim chrome and stack every multi-column form grid to one column.
   ponytail: one rule collapses all .grid form layouts instead of editing ~9 inline
   styles across views; the locker swatch grid uses a raw inline display:grid (no .grid
   class) so it stays multi-column, which is what we want there. */
@media (max-width: 560px) {
  #view { padding: 14px; }
  #topbar { padding: 10px 14px; }
  #crumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-right { gap: 8px; }
  /* Give the title the width back: the play view already draws its own health bar,
     and the theme picker lives in Settings. */
  #health-mini, #theme-quick { display: none; }
  .panel { padding: 14px; overflow-x: auto; }       /* wide tables scroll in-panel, not off-page */
  .grid { grid-template-columns: 1fr !important; }   /* beat inline gridTemplateColumns on phones */
  .quiz-choices { grid-template-columns: 1fr; }
  .healthbar-big { width: 100%; }
  #toast-host { left: 14px; right: 14px; bottom: 78px; }  /* clear of the tab bar */
  .toast { min-width: 0; max-width: none; }

  /* The rail becomes a thumb-reachable bottom tab bar: the note highway scrolls
     right-to-left, so every pixel of width is lookahead time. */
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  #sidebar { order: 2; flex-direction: row; padding: 2px 0;
    border-right: 0; border-top: 1px solid var(--line); }
  .brand, .nav-sep, .sidebar-foot { display: none; }
  #nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: none; min-width: 58px; }
  /* Without this the icon row's content width wins and stretches the whole app
     wider than the screen — grid/flex items default to min-width:auto. */
  #sidebar, #nav, #main { min-width: 0; }

  /* One scrollable row of controls instead of four wrapped ones — the rows it
     saves go to the highway. */
  .play-controls { flex-wrap: nowrap; overflow-x: auto; gap: 10px; padding: 8px 12px; }
  .play-controls > * { flex: none; }
  .play-hud { top: 8px; left: 8px; right: 8px; }
  .lyric-line { font-size: 17px; }
}

/* Touch: fingers need ~44px, and manipulation drops the 300ms double-tap delay. */
@media (pointer: coarse) {
  .btn, .nav-item, .quiz-choice, select.input, input.input { min-height: 44px; }
  button, a, select, input, .card, .quiz-choice { touch-action: manipulation; }
}

/* No hover (touch): a tapped card would otherwise keep its hover lift stuck on. */
@media (hover: none) {
  .card:hover, .kara-pick:hover { transform: none; }
}

/* Landscape phone on the immersive routes (play/karaoke): give them the whole
   screen. Both views carry their own "← Songs" button, so nothing is trapped. */
@media (max-height: 500px) and (orientation: landscape) {
  #app:has(#view.no-pad) { grid-template-columns: 1fr; }
  #app:has(#view.no-pad) #sidebar,
  #main:has(#view.no-pad) #topbar { display: none; }
  /* One swipeable row, not two wrapped ones — 97px of controls out of 390 was
     a quarter of the screen. */
  #view.no-pad .play-controls { flex-wrap: nowrap; overflow-x: auto; padding: 5px 10px; gap: 8px; }
  #view.no-pad .play-controls > * { flex: none; }
  #view.no-pad .play-avatar { display: none; }
}

/* Portrait phone: the highway is only as wide as the screen, so say so once and
   fade out. Pure CSS — no element, no timer, gone the moment you rotate. */
@media (max-width: 700px) and (orientation: portrait) {
  .play-shell::after {
    content: "↻ Rotate for more of the note highway";
    position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%);
    background: rgba(0,0,0,.6); border: 1px solid var(--line); border-radius: 999px;
    padding: 7px 15px; font-size: 13px; white-space: nowrap; pointer-events: none;
    animation: hint-fade 7s forwards;
  }
}
@keyframes hint-fade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
