:root{
  --bg:#0a0a0c;
  --surface:#17171b;
  --surface-2:#212127;
  --line:#2c2c34;
  --text:#f4f4f6;
  --dim:#8b8b95;
  --accent:#ffb020;
  --go:#2fd07a;
  --stop:#ff4d4d;
  --pad: env(safe-area-inset-bottom, 0px);
}

*{box-sizing:border-box;margin:0;padding:0}
[hidden]{display:none!important}
html,body{height:100%}
body{
  background:var(--bg);
  color:var(--text);
  font:500 16px/1.2 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,Roboto,system-ui,sans-serif;
  -webkit-font-smoothing:antialiased;
  overscroll-behavior:none;
  touch-action:manipulation;
  -webkit-user-select:none;user-select:none;
  -webkit-tap-highlight-color:transparent;
}
button,input{font:inherit;color:inherit;background:none;border:none;touch-action:manipulation}
button{cursor:pointer}
svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}

/* ---------- play screen ---------- */
#play{
  height:100dvh;
  overflow-y:auto;
  touch-action:pan-y;
  display:flex;flex-direction:column;
  padding:calc(env(safe-area-inset-top,0px) + 10px) 16px calc(var(--pad) + 12px);
  gap:clamp(8px,2vh,20px);
}

.topbar{display:flex;align-items:center;gap:12px;min-height:44px}
.ghost{
  display:flex;align-items:center;gap:8px;
  color:var(--dim);font-size:15px;font-weight:600;
  padding:10px 12px;margin:-10px -12px;border-radius:12px;
}
.ghost:active{background:var(--surface)}
.ghost.accent{color:var(--accent)}
.now-playing{margin-left:auto;text-align:right;overflow:hidden}
#nowName{display:block;font-weight:700;font-size:17px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:60vw}
.pos{font-size:12px;color:var(--dim);letter-spacing:.08em;text-transform:uppercase}

/* beat lights */
.beats{display:flex;justify-content:center;align-items:center;gap:12px;height:34px}
.beat{
  width:18px;height:18px;border-radius:50%;
  background:var(--surface-2);
  transition:transform .06s ease-out, background-color .06s ease-out, box-shadow .12s ease-out;
}
.beat.on{background:#6e6e7a;transform:scale(1.5)}
.beat.on.one{background:var(--accent);box-shadow:0 0 24px rgba(255,176,32,.55)}
.beat.muted.on{background:#3a3a44;box-shadow:none}
.beat.muted.on.one{background:#6b5520;box-shadow:none}

/* tempo readout */
.tempo{display:flex;align-items:center;justify-content:space-between;gap:10px}
.readout{flex:1;text-align:center;min-width:0}
.bpm{
  font-size:clamp(76px,24vw,132px);
  font-weight:800;line-height:.92;letter-spacing:-.04em;
  font-variant-numeric:tabular-nums;
}
.bpm.countdown{color:var(--accent)}
.hint{margin-top:-4px;text-align:center;white-space:nowrap;font-size:11px;font-weight:600;letter-spacing:.1em;color:#5f5f6b;text-transform:uppercase}
#nowPlaying,.readout,.beats{transition:transform .16s ease-out,opacity .16s ease-out;will-change:transform}
#nowPlaying.dragging,.readout.dragging,.beats.dragging{transition:none}
.bpm-label{margin-top:6px;font-size:12px;font-weight:700;letter-spacing:.22em;color:var(--dim)}
.round{
  width:74px;height:74px;flex:0 0 74px;border-radius:50%;
  background:var(--surface);border:1px solid var(--line);
  font-size:34px;font-weight:400;line-height:1;color:var(--text);
}
.round:active{background:var(--surface-2);transform:scale(.96)}
.round.small{width:56px;height:56px;flex-basis:56px;font-size:26px}

.nudge{display:grid;grid-template-columns:1fr 1.4fr 1fr;gap:10px}
.chip{
  height:52px;border-radius:14px;background:var(--surface);border:1px solid var(--line);
  font-weight:700;font-size:17px;color:var(--dim);
}
.chip:active{background:var(--surface-2)}
.chip.tap{color:var(--text);letter-spacing:.1em}
.chip.tap.hit{background:var(--accent);color:#111;border-color:var(--accent)}

/* settings */
.settings{display:flex;flex-direction:column;gap:clamp(8px,1.6vh,14px)}
.field{display:flex;flex-direction:column;gap:7px;min-width:0}
.field label,.field>span{font-size:11px;font-weight:700;letter-spacing:.16em;text-transform:uppercase;color:var(--dim)}
.row2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.seg{
  display:grid;grid-auto-flow:column;grid-auto-columns:1fr;gap:4px;
  background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:4px;
}
.seg button{
  height:48px;border-radius:10px;font-weight:700;font-size:16px;color:var(--dim);
}
.seg button[aria-pressed="true"]{background:var(--surface-2);color:var(--text);box-shadow:inset 0 0 0 1px var(--line)}
#modeSeg button[aria-pressed="true"],#edMode button[aria-pressed="true"]{background:var(--accent);color:#141414;box-shadow:none}

.new-song{
  height:64px;border-radius:18px;
  background:var(--surface);border:1px solid var(--line);
  font-size:19px;font-weight:700;color:var(--text);
  display:flex;align-items:center;justify-content:center;gap:10px;
}
.new-song span{font-size:13px;font-weight:600;color:var(--dim)}
.new-song:active{background:var(--surface-2)}

/* transport */
.transport{margin-top:auto;display:flex;gap:10px;align-items:stretch}
.side{
  width:64px;flex:0 0 64px;border-radius:18px;background:var(--surface);border:1px solid var(--line);
  display:grid;place-items:center;color:var(--text);
}
.side svg{width:28px;height:28px}
.side:disabled{opacity:.3}
.side:not(:disabled):active{background:var(--surface-2)}
.start{
  flex:1;height:96px;border-radius:20px;
  background:var(--go);color:#06210f;
  font-size:26px;font-weight:800;letter-spacing:.14em;
}
.start:active{filter:brightness(.92)}
.start.playing{background:var(--stop);color:#2a0505}

/* ---------- sheets ---------- */
.sheet{
  position:fixed;inset:0;background:var(--bg);z-index:20;
  display:flex;flex-direction:column;
  padding:calc(env(safe-area-inset-top,0px) + 8px) 16px calc(var(--pad) + 12px);
  animation:rise .18s ease-out;
}
@keyframes rise{from{transform:translateY(18px)}to{transform:none}}
.sheet-head{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:52px;margin-bottom:8px}
.sheet-head h2{font-size:18px;font-weight:700}
.songs{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch;display:flex;flex-direction:column;gap:8px;padding-bottom:8px}
.song{
  position:relative;overflow:hidden;border-radius:16px;
  border:1px solid var(--line);background:var(--stop);
}
.song-inner{
  position:relative;z-index:1;
  display:flex;align-items:center;gap:12px;
  background:var(--surface);padding:14px 12px 14px 16px;
  transition:transform .18s ease-out;touch-action:pan-y;
}
.song.active{border-color:var(--accent)}
.song.active .song-inner{background:#1d1a14}
.row-delete{
  position:absolute;top:0;right:0;bottom:0;width:96px;z-index:0;
  display:grid;place-items:center;
  background:var(--stop);color:#2a0505;font-weight:800;font-size:15px;letter-spacing:.06em;
}
.row-delete:active{filter:brightness(.9)}
.song .meta{flex:1;min-width:0}
.song .name{font-size:19px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.song .sub{margin-top:4px;font-size:13px;color:var(--dim);font-weight:600}
.song .num{width:26px;color:var(--dim);font-weight:700;font-variant-numeric:tabular-nums;font-size:15px}
.song .bpmtag{font-size:26px;font-weight:800;font-variant-numeric:tabular-nums;letter-spacing:-.02em}
.song .edit{width:44px;height:44px;border-radius:12px;display:grid;place-items:center;color:var(--dim);background:var(--surface-2)}
.empty{color:var(--dim);text-align:center;padding:40px 20px;line-height:1.5}
.undo{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  background:var(--surface-2);border:1px solid var(--line);border-radius:14px;
  padding:12px 12px 12px 16px;margin-top:8px;
}
.undo-text{font-size:15px;color:var(--dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.undo-text b{color:var(--text);font-weight:700}
#undoBtn{color:var(--accent);font-weight:800;font-size:16px;padding:8px 10px;margin:-8px -10px;letter-spacing:.04em}
.sheet-foot{display:flex;flex-direction:column;gap:8px;padding-top:10px}
.wide{height:60px;border-radius:16px;background:var(--surface-2);border:1px solid var(--line);font-weight:700;font-size:17px}
.wide.subtle{background:none;color:var(--dim);border-color:transparent;height:48px}
.wide.danger{color:var(--stop);background:none;border-color:#43222a;margin-top:8px}
.wide:active{filter:brightness(1.25)}

.form{display:flex;flex-direction:column;gap:18px;overflow-y:auto;padding-top:6px}
.form input[type=text],.form input[type=number]{
  background:var(--surface);border:1px solid var(--line);border-radius:14px;
  height:60px;padding:0 16px;font-size:19px;font-weight:600;width:100%;
}
.form input:focus{outline:2px solid var(--accent);outline-offset:-1px}
.tempo-edit{display:flex;align-items:center;gap:10px}
.tempo-edit input{text-align:center;font-size:30px;font-weight:800;font-variant-numeric:tabular-nums;-moz-appearance:textfield}
.tempo-edit input::-webkit-outer-spin-button,.tempo-edit input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}

@media (min-width:600px){
  #play,.sheet{max-width:520px;margin:0 auto}
}
@media (prefers-reduced-motion:reduce){
  *{animation:none!important;transition:none!important}
}
