:root {
  color-scheme: dark;
  --bg: #090a0d;
  --panel: #111318;
  --panel-raised: #171a20;
  --line: #2b2f38;
  --line-soft: #20242b;
  --text: #f4f2eb;
  --muted: #8d929d;
  --accent: #ff6b35;
  --accent-hot: #ff845b;
  --record: #ff335f;
  --cyan: #00c2a8;
  --radius: 12px;
  font-family: Inter, "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); overscroll-behavior: none; }
button, input, select { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1500px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar, .monitor-header, .instrument-header, .transport, .event-tools, footer {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; min-height: 54px; gap: 18px; }
.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 12px; height: 36px; background: var(--accent); box-shadow: 7px 0 0 #63331f; transform: skewY(-18deg); }
h1 { font-size: clamp(15px, 2vw, 20px); letter-spacing: .14em; line-height: 1; margin: 0; }
.brand-block p { color: var(--muted); font-size: 10px; letter-spacing: .11em; margin: 5px 0 0; text-transform: uppercase; }
.project-actions { display: flex; align-items: center; gap: 7px; }
.save-state { color: var(--cyan); font: 700 10px/1 ui-monospace, monospace; letter-spacing: .1em; margin-right: 4px; }

button, input, select { border: 1px solid var(--line); background: #12151a; border-radius: 7px; }
button { cursor: pointer; min-height: 36px; padding: 7px 11px; font-size: 11px; font-weight: 750; letter-spacing: .07em; }
button:hover:not(:disabled), button:focus-visible { border-color: #59606d; background: #1c2027; outline: none; }
button:disabled { opacity: .35; cursor: default; }
.quiet-button { color: var(--muted); }
.icon-button { min-width: 38px; padding-inline: 8px; font-size: 15px; }
.danger-hover:hover { color: #ff6f86; border-color: #853448 !important; }

main { display: grid; grid-template-columns: minmax(0, 1.28fr) minmax(360px, .72fr); gap: 10px; flex: 1; }
.panel { background: linear-gradient(145deg, #13161b, #0f1115); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.monitor { display: flex; flex-direction: column; min-height: 590px; }
.monitor-header { min-height: 70px; justify-content: space-between; gap: 16px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.pattern-identity { min-width: 0; flex: 1; }
.state-chip, .dialog-kicker { display: inline-flex; color: var(--accent); font: 800 9px/1 ui-monospace, monospace; letter-spacing: .14em; margin-bottom: 7px; }
.state-chip.is-recording { color: var(--record); }
.pattern-name { display: block; width: 100%; border: 0; background: transparent; border-radius: 0; padding: 0; color: var(--text); font-size: clamp(19px, 3vw, 29px); font-weight: 720; letter-spacing: -.025em; }
.pattern-name:focus { outline: none; color: white; }
.numeric-controls { display: flex; gap: 8px; }
.numeric-controls label { color: var(--muted); font: 700 9px/1 ui-monospace, monospace; letter-spacing: .1em; }
.numeric-controls input, .numeric-controls select { display: block; width: 68px; height: 34px; color: var(--text); margin-top: 6px; padding: 4px 7px; }
.numeric-controls select { width: 72px; }

.dual-monitor { width: calc(100% - 24px); min-height: 62px; margin: 10px 12px 0; padding: 9px 11px; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: 10px; text-align: left; background: #0c0e12; border-color: #252a32; }
.dual-monitor:not(.is-empty) { border-left: 3px solid var(--context-color, var(--cyan)); }
.dual-kicker { grid-row: 1 / 3; align-self: center; color: var(--muted); font: 800 8px/1 ui-monospace, monospace; writing-mode: vertical-rl; transform: rotate(180deg); letter-spacing: .12em; }
.dual-title { font-size: 13px; font-weight: 760; align-self: end; }
.dual-meta { color: var(--muted); font-size: 10px; align-self: start; margin-top: 3px; }
.dual-action { grid-column: 3; grid-row: 1 / 3; align-self: center; color: var(--cyan); font-size: 10px; }

.timeline { --lane-head: 42px; position: relative; flex: 1; min-height: 285px; margin: 10px 12px; overflow: hidden; background: #090b0e; border: 1px solid #252a32; border-radius: 8px; touch-action: none; }
.timeline-grid { position: absolute; inset: 0 0 0 var(--lane-head); background-image: linear-gradient(to bottom, transparent 33%, #1b1f26 33%, #1b1f26 calc(33% + 1px), transparent calc(33% + 1px), transparent 66%, #1b1f26 66%, #1b1f26 calc(66% + 1px), transparent calc(66% + 1px)), repeating-linear-gradient(to right, #242932 0 1px, transparent 1px var(--beat-width, 30px)); }
.timeline-grid::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(to right, transparent 0 calc(var(--bar-width, 120px) - 2px), #444a56 calc(var(--bar-width, 120px) - 2px) var(--bar-width, 120px)); opacity: .7; pointer-events: none; }
.lane-label { position: absolute; left: 0; width: var(--lane-head); height: 33.333%; display: grid; place-items: center; color: #626874; border-right: 1px solid #292e37; font: 800 8px/1 ui-monospace, monospace; letter-spacing: .07em; z-index: 4; background: #0e1014; }
.lane-pattern { top: 0; }
.lane-sample { top: 33.333%; border-top: 1px solid var(--line-soft); }
.lane-note { top: 66.666%; border-top: 1px solid var(--line-soft); }
.timeline-events { position: absolute; inset: 0 0 0 var(--lane-head); }
.timeline-event { position: absolute; height: calc(33.333% - 12px); min-width: 7px; padding: 5px 7px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border: 1px solid color-mix(in srgb, var(--event-color), white 12%); border-radius: 5px; background: color-mix(in srgb, var(--event-color), #101318 55%); color: #fff; font-size: 10px; text-align: left; box-shadow: inset 0 -8px 20px rgb(0 0 0 / 18%); }
.timeline-event[data-kind="pattern"] { top: 6px; }
.timeline-event[data-kind="sample"] { top: calc(33.333% + 6px); }
.timeline-event[data-kind="note"] { top: calc(66.666% + 6px); }
.timeline-event.is-selected { border-color: white; box-shadow: 0 0 0 2px rgb(255 255 255 / 22%); z-index: 3; }
.playhead, .edit-cursor { position: absolute; top: 0; bottom: 0; left: var(--lane-head); width: 2px; background: var(--accent); pointer-events: none; z-index: 8; transform: translateX(0); }
.playhead span, .edit-cursor span { position: absolute; top: 0; left: -4px; width: 10px; height: 7px; background: inherit; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.edit-cursor { width: 1px; background: #7b8290; opacity: .9; z-index: 7; }
.timeline.is-playing .edit-cursor { opacity: .25; }
.empty-message { position: absolute; inset: 0 0 0 var(--lane-head); display: grid; place-items: center; color: #5f6570; font-size: 12px; pointer-events: none; }
.timeline:not(.is-empty) .empty-message { display: none; }

.event-tools { justify-content: space-between; gap: 12px; min-height: 45px; padding: 5px 12px; border-top: 1px solid var(--line-soft); color: var(--muted); font: 700 9px/1 ui-monospace, monospace; letter-spacing: .08em; }
.event-tools > div { display: flex; gap: 5px; }
.event-tools button { min-height: 30px; padding: 5px 9px; font-size: 9px; }
.transport { min-height: 67px; padding: 8px 12px; gap: 7px; border-top: 1px solid var(--line); background: #0c0e11; }
.transport-button { min-width: 78px; min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.transport-button.primary.is-active { border-color: var(--accent); background: #2a1913; }
.transport-button.record.is-active { border-color: var(--record); background: #30121a; color: #ffb4c1; box-shadow: inset 0 0 20px rgb(255 51 95 / 12%); }
.transport-icon { font-size: 14px; }
.position-readout { margin-left: auto; text-align: right; }
.position-readout strong { display: block; font: 750 19px/1 ui-monospace, monospace; letter-spacing: .05em; }
.position-readout span { display: block; color: var(--muted); font-size: 9px; margin-top: 5px; }

.instrument { display: flex; flex-direction: column; min-height: 590px; }
.instrument-header { min-height: 70px; padding: 10px; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line-soft); }
.mode-switch { display: flex; }
.mode-switch button { border-radius: 0; min-width: 68px; }
.mode-switch button:first-child { border-radius: 7px 0 0 7px; }
.mode-switch button:last-child { border-radius: 0 7px 7px 0; margin-left: -1px; }
.mode-switch .is-active { color: white; border-color: var(--accent); background: #281812; z-index: 1; }
.mode-switch .goto-button { margin-left: 7px; border-radius: 7px; color: var(--cyan); }
.mode-switch .goto-button.is-active { border-color: var(--cyan); background: #0b2b29; box-shadow: 0 0 18px rgb(0 194 168 / 16%); }
.instrument-header p { flex: 1; color: var(--muted); font-size: 10px; line-height: 1.35; margin: 0; }
.accent-button { color: #ffd4c4; border-color: #743821; background: #271711; }
.input-actions { display: flex; align-items: center; gap: 7px; }
.octave-control { align-items: center; gap: 6px; color: var(--muted); font: 800 9px/1 ui-monospace, monospace; }
.octave-control button { min-height: 32px; padding: 4px 9px; }
.octave-control strong { color: white; }
.piano-control { color: var(--muted); font: 800 8px/1 ui-monospace, monospace; letter-spacing: .06em; }
.piano-control select { display: block; height: 32px; margin-top: 4px; padding: 3px 5px; color: white; font-size: 9px; }

.pad-grid { display: grid; grid-template-columns: repeat(4, minmax(72px, 1fr)); grid-template-rows: repeat(4, minmax(78px, 1fr)); gap: 8px; flex: 1; padding: 10px; }
.pad { position: relative; min-height: 78px; border: 1px solid #343943; border-radius: 9px; background: #15181d; overflow: hidden; isolation: isolate; transition: transform 70ms ease, border-color 100ms ease, box-shadow 100ms ease; }
.pad::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 120%, var(--pad-color, transparent), transparent 70%); opacity: .22; z-index: -1; }
.pad-main { width: 100%; height: 100%; min-height: 78px; padding: 12px 9px 10px; border: 0; background: transparent; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; text-align: left; }
.pad-main:hover { border: 0 !important; background: rgb(255 255 255 / 3%) !important; }
.pad-index { position: absolute; top: 8px; left: 9px; color: #6c727d; font: 800 9px/1 ui-monospace, monospace; }
.pad-kind { position: absolute; top: 8px; right: 9px; color: var(--pad-color, #59606b); font: 800 8px/1 ui-monospace, monospace; letter-spacing: .1em; }
.pad-name { width: 100%; font-size: clamp(11px, 1.5vw, 14px); font-weight: 760; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad-meta { color: var(--muted); font-size: 9px; margin-top: 4px; }
.pad-menu { position: absolute; top: 2px; right: 2px; min-width: 32px; min-height: 29px; padding: 0; border: 0; background: transparent; color: transparent; z-index: 3; }
.pad.is-empty { border-style: dashed; border-color: #292e36; }
.pad.is-empty .pad-main { align-items: center; justify-content: center; text-align: center; color: #555c67; }
.pad.is-empty .pad-name { font-size: 10px; letter-spacing: .09em; }
.empty-sample { position: absolute; right: 6px; bottom: 6px; min-height: 26px; padding: 3px 6px; color: #565d68; border-color: #272c34; background: #111318; font-size: 8px; z-index: 4; }
.pad.is-root { border-color: white; box-shadow: inset 0 0 0 1px white, 0 0 18px rgb(255 255 255 / 10%); }
.pad.is-playing { border-color: var(--pad-color); box-shadow: inset 0 0 0 1px var(--pad-color), 0 0 24px color-mix(in srgb, var(--pad-color), transparent 70%); }
.pad.is-playing::before { opacity: .65; animation: breathe 650ms ease-in-out infinite alternate; }
.pad.is-record-target { box-shadow: inset 0 0 0 2px var(--record), 0 0 22px rgb(255 51 95 / 20%); border-color: var(--record); }
.pad.is-flashing { transform: scale(.975); filter: brightness(1.5); }
@keyframes breathe { to { opacity: .95; } }

.note-pad, .menu-pad { position: relative; min-height: 78px; padding: 12px 9px 10px; border-radius: 9px; touch-action: none; user-select: none; overflow: hidden; }
.note-pad { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; text-align: left; border-color: #343943; background: radial-gradient(circle at 50% 120%, #6c63ff55, transparent 68%), #15181d; }
.note-pad strong { font-size: clamp(10px, 1.35vw, 13px); }
.note-degree { color: var(--muted); font: 750 8px/1 ui-monospace, monospace; margin-bottom: 6px; }
.note-pad.is-tonic { border-color: var(--accent); background: radial-gradient(circle at 50% 120%, #ff6b3588, transparent 72%), #1a1513; }
.note-pad.is-dominant { border-color: var(--cyan); background: radial-gradient(circle at 50% 120%, #00c2a866, transparent 72%), #111918; }
.note-pad.is-down { filter: brightness(1.5); transform: scale(.975); }
.menu-pad { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; text-align: left; background: #15181d; }
.menu-pad strong { font-size: 12px; }
.menu-pad small { min-height: 11px; margin-top: 5px; color: var(--muted); font-size: 9px; }
.menu-badge { position: absolute; top: 8px; right: 9px; color: var(--cyan); font: 800 8px/1 ui-monospace, monospace; }
.menu-pad.is-back { border-color: #59606d; }
.menu-pad.is-danger { border-color: #713043; color: #ff91a4; }
.menu-pad.is-vacant { border-style: dashed; border-color: #252a32; opacity: .42; }
.is-hidden { display: none !important; }

footer { justify-content: space-between; gap: 15px; min-height: 22px; color: #666c77; font: 700 8px/1 ui-monospace, monospace; letter-spacing: .1em; }
#status { color: #a4a9b2; }

.pad-dialog { width: min(420px, calc(100% - 28px)); color: var(--text); background: #12151a; border: 1px solid #414753; border-radius: 12px; padding: 18px; box-shadow: 0 20px 70px rgb(0 0 0 / 70%); }
.pad-dialog::backdrop { background: rgb(0 0 0 / 72%); backdrop-filter: blur(4px); }
.pad-dialog h2 { margin: 0 0 18px; font-size: 24px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dialog-actions button { min-height: 47px; }
.dialog-actions .danger { color: #ff91a4; border-color: #713043; }
.dialog-close { width: 100%; margin-top: 10px; color: var(--muted); }

@media (max-width: 850px) {
  .app-shell { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 44px; }
  .project-actions .save-state { display: none; }
  .quiet-button { min-height: 31px; padding: 4px 7px; font-size: 8px; }
  main { grid-template-columns: 1fr; }
  .monitor, .instrument { min-height: auto; }
  .timeline { min-height: 250px; height: 38dvh; flex: none; }
  .instrument { min-height: 53dvh; }
  .instrument-header p { display: none; }
  .pad-grid { min-height: 430px; }
  footer span:last-child { display: none; }
}

@media (max-width: 520px) {
  .brand-block p { display: none; }
  .brand-mark { height: 27px; }
  .project-actions { gap: 3px; }
  .monitor-header { align-items: flex-end; }
  .numeric-controls { gap: 4px; }
  .numeric-controls label { font-size: 7px; }
  .numeric-controls input, .numeric-controls select { width: 52px; height: 31px; padding: 3px; }
  .numeric-controls select { width: 58px; }
  .pattern-name { font-size: 19px; }
  .dual-monitor { min-height: 56px; }
  .transport { gap: 4px; }
  .transport-button { min-width: 57px; min-height: 44px; padding: 5px; font-size: 8px; }
  .position-readout strong { font-size: 15px; }
  .position-readout span { display: none; }
  .event-tools { overflow: hidden; }
  .event-tools > span { max-width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pad-grid { gap: 5px; padding: 7px; min-height: 370px; }
  .pad-main { padding: 9px 6px 7px; }
  .pad-index { top: 6px; left: 6px; }
  .pad-kind { top: 6px; right: 6px; }
  .pad-name { font-size: 10px; }
  .pad-meta { font-size: 8px; }
  .mode-switch button { min-width: 52px; padding-inline: 6px; font-size: 8px; }
  .mode-switch .goto-button { margin-left: 3px; }
  .input-actions { gap: 3px; }
  .piano-control select { width: 58px; }
}
