:root {
  color-scheme: light;
  --ink: #121826;
  --muted: #667085;
  --line: #dde2ea;
  --paper: #f8f7f2;
  --surface: #ffffff;
  --navy: #111827;
  --rose: #f5677c;
  --cyan: #36b8c7;
  --amber: #e8a23a;
  --violet: #8b7cf6;
  --shadow: 0 18px 55px rgba(31, 41, 55, 0.09);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 12% 0%, rgba(54,184,199,.08), transparent 28rem), var(--paper); }
button, input, select { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid rgba(54,184,199,.28); outline-offset: 2px; }

.app-shell { min-height: 100vh; max-width: 1600px; margin: 0 auto; padding: 0 30px 24px; }
.topbar { height: 84px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(18,24,38,.1); }
.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand strong { display: block; font-size: 18px; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); margin-top: 2px; font-size: 12px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; background: var(--navy); display: flex; gap: 3px; padding: 9px; align-items: end; box-shadow: 0 7px 18px rgba(17,24,39,.2); }
.brand-mark i { display: block; flex: 1; height: 23px; background: white; border-radius: 2px 2px 4px 4px; }
.brand-mark i:nth-child(2) { height: 16px; background: var(--rose); align-self: start; }
.header-actions { display: flex; gap: 10px; align-items: center; }

.button, .icon-button, .chip-button, .text-button, .view-tab { border: 0; transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease; }
.button:active, .icon-button:active, .chip-button:active, .view-tab:active { transform: translateY(1px); }
.button { height: 42px; border-radius: 12px; padding: 0 17px; font-weight: 700; }
.button.primary { color: white; background: var(--navy); }
.button.secondary { color: var(--ink); background: var(--surface); border: 1px solid var(--line); }
.button.secondary:hover { border-color: #bdc4d0; box-shadow: 0 5px 16px rgba(31,41,55,.06); }
.icon-button { width: 40px; height: 40px; border-radius: 50%; background: #eceff3; color: var(--ink); font-weight: 800; }
.text-button { background: none; color: var(--muted); padding: 6px; font-size: 13px; }
.text-button:hover { color: var(--ink); }

main { padding-top: 24px; }
.song-bar { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 18px; }
.song-copy label, .eyebrow { display: block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-bottom: 7px; }
.select-wrap select { min-width: 290px; max-width: 52vw; border: 0; background: transparent; color: var(--ink); font-size: clamp(24px, 3vw, 38px); font-weight: 800; padding: 0 34px 0 0; appearance: auto; }
.song-copy p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.view-switcher { display: flex; padding: 5px; gap: 4px; background: #e9e9e4; border-radius: 15px; overflow-x: auto; max-width: 60%; }
.view-tab { white-space: nowrap; padding: 10px 16px; border-radius: 11px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.view-tab[aria-selected="true"] { background: white; color: var(--ink); box-shadow: 0 4px 13px rgba(31,41,55,.08); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: stretch; }
.roll-card, .mixer-card, .transport-card { background: var(--surface); border: 1px solid rgba(18,24,38,.08); border-radius: 20px; box-shadow: var(--shadow); }
.roll-card { min-width: 0; overflow: hidden; }
.roll-toolbar { min-height: 62px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.roll-toolbar strong { font-size: 16px; margin-right: 8px; }
.roll-toolbar span { font-size: 13px; color: var(--muted); }
.zoom-control { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.zoom-control input { width: 110px; accent-color: var(--rose); }
.roll-shell { position: relative; display: grid; grid-template-columns: 70px minmax(0,1fr); height: clamp(390px, 55vh, 590px); background: #151b28; overflow: hidden; }
.keyboard-canvas { width: 70px; height: 100%; z-index: 2; box-shadow: 8px 0 22px rgba(0,0,0,.25); cursor: pointer; touch-action: none; }
.keyboard-canvas:focus-visible { outline: 3px solid var(--rose); outline-offset: -3px; }
.timeline-scroll { position: relative; overflow-x: auto; overflow-y: hidden; scrollbar-color: #657084 #242c3b; scrollbar-width: thin; }
#pianoRoll { height: 100%; display: block; touch-action: pan-x; }
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; color: #aab3c3; }
.empty-state[hidden] { display: none; }
.legend { min-height: 46px; display: flex; gap: 18px; align-items: center; padding: 10px 18px; overflow-x: auto; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; color: var(--muted); font-size: 12px; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; }

.mixer-card { padding: 18px; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.panel-heading h2, .dialog-heading h2 { margin: 0; font-size: 19px; }
.track-list { padding-top: 10px; display: grid; gap: 8px; max-height: 550px; overflow-y: auto; }
.track-row { padding: 11px 10px; border-radius: 13px; background: #f7f8fa; border: 1px solid transparent; }
.track-row.is-muted { opacity: .5; }
.track-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.track-swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.track-name { min-width: 0; flex: 1; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-count { color: var(--muted); font-size: 11px; }
.track-actions { display: flex; gap: 5px; }
.tiny-button { border: 1px solid var(--line); background: white; border-radius: 7px; min-width: 29px; height: 26px; color: var(--muted); font-size: 11px; font-weight: 800; }
.tiny-button.active { background: var(--navy); border-color: var(--navy); color: white; }
.track-volume { width: 100%; accent-color: var(--navy); }

.transport-card { margin-top: 18px; padding: 16px 20px; display: grid; grid-template-columns: minmax(330px, 1fr) auto; gap: 28px; align-items: center; position: sticky; bottom: 12px; z-index: 5; }
.transport-main { display: flex; align-items: center; gap: 10px; }
.play-button { width: 52px; height: 52px; border: 0; border-radius: 50%; background: var(--rose); color: white; font-size: 19px; box-shadow: 0 9px 22px rgba(245,103,124,.34); flex: 0 0 auto; }
.seek-group { min-width: 0; flex: 1; }
#seekRange { width: 100%; accent-color: var(--rose); }
.time-row { display: flex; justify-content: space-between; margin-top: 3px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 11px; }
.practice-controls { display: flex; align-items: center; gap: 18px; }
.speed-box, .volume-box { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.speed-box select { border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: white; color: var(--ink); }
.volume-box input { width: 90px; accent-color: var(--navy); }
.loop-box { display: grid; grid-template-columns: repeat(3, auto); gap: 5px; }
.loop-box span { grid-column: 1 / -1; color: var(--muted); font-size: 11px; text-align: center; margin-top: 2px; }
.chip-button { border-radius: 8px; padding: 7px 9px; background: #eef0f4; color: var(--ink); font-size: 11px; font-weight: 700; }
.chip-button[aria-pressed="true"] { color: white; background: var(--cyan); }

footer { display: flex; gap: 24px; justify-content: center; padding-top: 18px; color: #7a8392; font-size: 12px; }

dialog { width: min(540px, calc(100vw - 32px)); border: 0; border-radius: 20px; padding: 24px; color: var(--ink); box-shadow: 0 30px 100px rgba(17,24,39,.3); }
dialog::backdrop { background: rgba(17,24,39,.58); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.dialog-intro { color: var(--muted); line-height: 1.65; font-size: 14px; }
.field { display: grid; gap: 7px; font-size: 13px; font-weight: 700; margin-top: 18px; }
.field input, .field select { height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: white; color: var(--ink); }
.file-field { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 12px; border: 1px dashed #bec5d0; border-radius: 13px; padding: 13px; }
.file-field strong, .file-field small { display: block; }
.file-field strong { font-size: 13px; }
.file-field small { color: var(--muted); margin-top: 3px; }
.file-field input { max-width: 230px; font-size: 12px; }
.dialog-actions { display: flex; justify-content: end; gap: 10px; margin-top: 22px; }
.dialog-error { margin-top: 12px; padding: 10px; border-radius: 9px; background: #fff0f2; color: #b4233a; font-size: 13px; }
.xml-dialog { width: min(660px, calc(100vw - 32px)); }
.xml-summary { margin-top: 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary-stat { padding: 12px; border-radius: 12px; background: #f4f6f8; }
.summary-stat strong, .summary-stat span { display: block; }
.summary-stat strong { font-size: 18px; }
.summary-stat span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.mapping-heading { margin-top: 20px; padding-bottom: 8px; display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.mapping-heading span { color: var(--muted); font-size: 11px; }
.mapping-list { max-height: 290px; overflow-y: auto; display: grid; gap: 8px; padding-top: 10px; }
.mapping-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.mapping-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--rose); }
.mapping-row input[type="text"] { min-width: 0; width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; font-weight: 700; }
.mapping-count { color: var(--muted); font-size: 11px; white-space: nowrap; }
.shortcut-list { display: grid; gap: 0; margin: 20px 0 0; }
.shortcut-list div { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding: 13px 0; }
.shortcut-list dt { font-weight: 800; }
.shortcut-list dd { margin: 0; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--navy); color: white; border-radius: 999px; padding: 11px 17px; font-size: 13px; opacity: 0; pointer-events: none; transition: .22s ease; z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .mixer-card { order: 2; }
  .track-list { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); max-height: none; }
  .transport-card { grid-template-columns: 1fr; gap: 14px; }
  .practice-controls { justify-content: space-between; }
}

@media (max-width: 680px) {
  .app-shell { padding: 0 12px 18px; }
  .topbar { height: 70px; }
  .brand small { display: none; }
  .button.secondary { padding: 0 11px; }
  .song-bar { display: block; }
  .select-wrap select { min-width: 0; width: 100%; max-width: 100%; font-size: 27px; }
  .view-switcher { max-width: 100%; margin-top: 16px; }
  .roll-shell { height: 430px; grid-template-columns: 54px minmax(0, 1fr); }
  .keyboard-canvas { width: 54px; }
  .roll-toolbar { align-items: start; }
  .zoom-control { display: grid; justify-items: end; }
  .transport-card { padding: 13px; bottom: 6px; }
  .practice-controls { display: grid; grid-template-columns: auto 1fr; }
  .loop-box { grid-column: 1 / -1; grid-row: 1; }
  .volume-box { justify-items: end; }
  footer { display: none; }
  .file-field { display: grid; }
  .file-field input { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
