:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #121620;
  --panel-2: #181d29;
  --line: rgba(255,255,255,.09);
  --line-strong: rgba(255,255,255,.17);
  --text: #f8f9fc;
  --muted: #9aa3b5;
  --accent: #8f7cff;
  --accent-2: #5de1d0;
  --danger: #ff6d83;
  --keyboard-h: 132px;
  --top-space: env(safe-area-inset-top, 0px);
  --bottom-space: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: ui-rounded, "SF Pro Rounded", "Hiragino Sans", system-ui, sans-serif; }
body { overscroll-behavior: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(100%, 720px);
  height: 100dvh;
  margin: 0 auto;
  padding: calc(10px + var(--top-space)) 12px calc(8px + var(--bottom-space));
  display: grid;
  grid-template-rows: auto auto minmax(0,1fr) auto;
  gap: 9px;
  overflow: hidden;
}

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 55px; }
.eyebrow { margin: 0 0 2px; font-size: 10px; letter-spacing: .2em; color: var(--accent-2); font-weight: 800; }
h1 { margin: 0; font-size: 22px; line-height: 1; }
.transport { display: flex; align-items: center; gap: 8px; }
.icon-btn, .play-btn, .secondary-btn {
  border: 1px solid var(--line-strong); color: var(--text); background: var(--panel-2); box-shadow: 0 4px 18px rgba(0,0,0,.18);
}
.icon-btn { width: 40px; height: 40px; border-radius: 13px; font-size: 21px; }
.icon-btn.danger { color: var(--danger); }
.play-btn { width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(145deg, var(--accent), #6d5ce7); border: none; font-size: 17px; padding-left: 4px; }
.play-btn.playing { background: linear-gradient(145deg, #ff8a6c, #ff5f7f); }

.controls { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 7px; align-items: end; }
.controls label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.controls select, .controls input { width: 100%; height: 36px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 0 9px; outline: none; }
.secondary-btn { height: 36px; border-radius: 11px; padding: 0 11px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.secondary-btn.active { background: rgba(143,124,255,.23); border-color: var(--accent); }

.score-wrap { min-height: 0; display: grid; grid-template-rows: minmax(0,1fr) var(--keyboard-h); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; background: var(--panel); box-shadow: 0 18px 50px rgba(0,0,0,.3); }
.score { position: relative; overflow: hidden; touch-action: none; background: linear-gradient(180deg, rgba(93,225,208,.035), transparent 35%), #10141d; }
#gridCanvas, .note-layer, .playhead { position: absolute; inset: 0; width: 100%; height: 100%; }
.note-layer { pointer-events: auto; }
.note {
  position: absolute; border-radius: 9px; transform: translateZ(0);
  background: linear-gradient(180deg, #9b8aff, #7665e7);
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: 0 5px 14px rgba(80,67,190,.35), inset 0 1px 0 rgba(255,255,255,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 900; color: white; user-select: none;
}
.note.sharp { background: linear-gradient(180deg, #56dccc, #2faea2); box-shadow: 0 5px 14px rgba(39,154,144,.33); }
.note.selected { outline: 3px solid #fff; outline-offset: 1px; z-index: 3; }
.rest { position: absolute; left: 50%; transform: translateX(-50%); border-radius: 999px; background: rgba(255,255,255,.18); border: 1px dashed rgba(255,255,255,.45); color: var(--muted); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; }
.now-line { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent-2) 12%, var(--accent-2) 88%, transparent); pointer-events: none; }
.now-line span { position: absolute; right: 6px; bottom: 5px; font-size: 8px; letter-spacing: .12em; color: var(--accent-2); font-weight: 900; }
.playhead { height: 2px; background: #ff6f91; box-shadow: 0 0 12px #ff6f91; top: auto; bottom: 0; z-index: 5; pointer-events: none; }

.keyboard { position: relative; display: flex; background: #07090d; border-top: 1px solid var(--line-strong); overflow: hidden; touch-action: manipulation; }
.white-key { position: relative; flex: 1; height: 100%; background: linear-gradient(180deg,#fff,#dce0e9); border: 0; border-right: 1px solid #9aa1ad; color: #252a34; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px; font-size: 9px; font-weight: 900; }
.white-key:last-child { border-right: 0; }
.white-key.active { background: linear-gradient(180deg,#ded8ff,#a99cff); }
.black-key { position: absolute; top: 0; z-index: 2; height: 61%; width: 8.3%; transform: translateX(-50%); border: 1px solid #000; border-radius: 0 0 7px 7px; background: linear-gradient(180deg,#252a34,#07090d); box-shadow: 0 5px 7px rgba(0,0,0,.5); color: #dfe6f2; font-size: 8px; font-weight: 800; padding: 0 0 6px; display: flex; align-items: flex-end; justify-content: center; }
.black-key.active { background: linear-gradient(180deg,#57dfd0,#1b8f87); }

.hint { color: var(--muted); text-align: center; min-height: 15px; font-size: 10px; line-height: 1.3; }

@media (max-width: 430px) {
  :root { --keyboard-h: 118px; }
  .app-shell { padding-inline: 8px; }
  .controls { grid-template-columns: 1fr .8fr auto auto; gap: 5px; }
  .secondary-btn { padding-inline: 8px; font-size: 11px; }
  .black-key { width: 8.8%; }
}
