:root {
  color-scheme: dark;
  --ink: #090907;
  --panel: #14130f;
  --panel-2: #1d1a14;
  --paper: #f7efdf;
  --paper-2: #e6dbc2;
  --muted: #a89f8c;
  --line: rgba(247, 239, 223, 0.16);
  --line-strong: rgba(247, 239, 223, 0.32);
  --coral: #ff6045;
  --mint: #34d8bf;
  --lime: #b8ee69;
  --danger: #ff5572;
  --score-ink: #17140e;
  --score-paper: #f4ecd9;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    repeating-linear-gradient(90deg, rgba(247, 239, 223, 0.025) 0 1px, transparent 1px 56px),
    repeating-linear-gradient(0deg, rgba(247, 239, 223, 0.022) 0 1px, transparent 1px 42px),
    var(--ink);
  color: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

button,
input,
select {
  font: inherit;
}

button,
.button-link,
select,
input {
  border-radius: 8px;
}

button,
.button-link {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  background: rgba(247, 239, 223, 0.08);
  color: var(--paper);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

button:hover:not(:disabled),
.button-link:hover:not(.disabled) {
  transform: translateY(-1px);
  border-color: rgba(247, 239, 223, 0.52);
  background: rgba(247, 239, 223, 0.13);
}

button:disabled,
.button-link.disabled {
  cursor: not-allowed;
  opacity: 0.45;
  pointer-events: none;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  background: #0f0e0b;
  color: var(--paper);
  padding: 0 11px;
}

input[type="file"] {
  padding: 9px;
  min-height: auto;
}

button:focus-visible,
.button-link:focus-visible,
input:focus,
select:focus {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

.primary {
  border-color: rgba(255, 96, 69, 0.72);
  background: var(--coral);
  color: #1b0b06;
  font-weight: 780;
}

.danger {
  color: var(--danger);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  grid-template-rows: 68px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100svh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 9, 7, 0.86);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--paper);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 790;
  text-decoration: none;
}

.brand img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand span {
  white-space: nowrap;
}

.job-pill {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 130px;
  color: var(--muted);
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
}

.state-dot.hot {
  background: var(--lime);
  animation: pulse 1.45s ease-out infinite;
}

@keyframes pulse {
  from { box-shadow: 0 0 0 0 rgba(184, 238, 105, 0.45); }
  to { box-shadow: 0 0 0 18px rgba(184, 238, 105, 0); }
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(270px, 36vh) minmax(390px, 1fr);
}

.capture-deck {
  position: relative;
  min-height: 270px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: radial-gradient(circle at 24% 22%, rgba(255, 96, 69, 0.14), transparent 32%), var(--ink);
}

#visualCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, rgba(9, 9, 7, 0.18), rgba(9, 9, 7, 0.64));
  pointer-events: none;
}

.processing-overlay[hidden] {
  display: none;
}

.processing-card {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(460px, 100%);
  padding: 15px 17px;
  border: 1px solid rgba(247, 239, 223, 0.22);
  border-radius: 8px;
  background: rgba(20, 19, 15, 0.82);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(14px);
}

.processing-card strong,
.processing-card span {
  display: block;
}

.processing-card strong {
  color: var(--paper);
  font-size: 1.04rem;
}

.processing-card span:last-child {
  margin-top: 3px;
  color: var(--mint);
  font-size: 0.88rem;
}

.processing-ring {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 3px solid rgba(247, 239, 223, 0.18);
  border-top-color: var(--mint);
  border-radius: 999px;
  animation: spin 880ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.capture-readout {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: minmax(145px, 1fr) minmax(145px, 1fr) minmax(240px, 1.6fr);
  gap: 12px;
  pointer-events: none;
}

.capture-readout > div {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 19, 15, 0.76);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.capture-readout strong {
  display: block;
  margin-top: 2px;
  color: var(--paper);
  font-size: 1.45rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.capture-readout span:last-child {
  display: block;
  margin-top: 5px;
  min-width: 0;
  overflow: hidden;
  color: var(--mint);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.score-deck {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--score-paper);
  color: var(--score-ink);
}

.score-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid rgba(23, 20, 14, 0.13);
}

.score-head .eyebrow {
  color: rgba(23, 20, 14, 0.56);
}

.score-head h1 {
  margin: 2px 0 0;
  font-size: 1.42rem;
  line-height: 1.12;
  letter-spacing: 0;
}

.score-actions {
  display: flex;
  gap: 10px;
}

.score-actions .button-link {
  border-color: rgba(23, 20, 14, 0.22);
  background: rgba(23, 20, 14, 0.06);
  color: var(--score-ink);
}

.score-container {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 22px;
}

.score-timeline {
  display: flex;
  gap: 6px;
  max-width: 100%;
  margin-bottom: 14px;
  padding-bottom: 8px;
  overflow-x: auto;
}

.note-pill {
  min-width: 48px;
  min-height: 32px;
  flex: 0 0 auto;
  padding: 0 10px;
  border: 1px solid rgba(23, 20, 14, 0.18);
  border-radius: 8px;
  background: rgba(23, 20, 14, 0.05);
  color: var(--score-ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.note-pill:hover,
.note-pill.selected {
  border-color: rgba(255, 96, 69, 0.58);
  background: rgba(255, 96, 69, 0.12);
}

.note-pill.playing {
  border-color: rgba(52, 216, 191, 0.72);
  background: rgba(52, 216, 191, 0.24);
  box-shadow: inset 0 -3px 0 rgba(52, 216, 191, 0.72);
}

.score-system {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  min-width: min-content;
}

.measure-container {
  width: 254px;
  height: 145px;
  flex: 0 0 auto;
}

.measure-container.first {
  width: 342px;
}

.measure-container svg {
  overflow: visible;
}

.score-note {
  transition: opacity 140ms ease, filter 140ms ease;
}

.score-note.playing {
  filter: drop-shadow(0 0 5px rgba(255, 96, 69, 0.55));
}

.score-note.playing path,
.score-note.playing text {
  fill: var(--coral);
  stroke: var(--coral);
}

.empty-score {
  min-height: 250px;
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  color: rgba(23, 20, 14, 0.52);
}

.empty-staff {
  width: min(620px, 82vw);
}

.empty-staff span {
  display: block;
  height: 1px;
  margin-bottom: 16px;
  background: rgba(23, 20, 14, 0.26);
}

.side-panel {
  grid-column: 2;
  grid-row: 2;
  min-height: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: rgba(20, 19, 15, 0.95);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.playback-section {
  margin-top: auto;
}

.panel-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 2px;
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-section label {
  display: block;
  margin: 13px 0 7px;
  color: var(--paper-2);
  font-size: 0.9rem;
  font-weight: 720;
}

.button-row,
.split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.wide {
  width: 100%;
  margin-top: 10px;
}

.file-status {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.mode-label {
  color: var(--mint);
  font-size: 0.82rem;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--mint);
}

.playback-range {
  margin: 3px 0 8px;
}

.playback-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.playback-meta strong {
  min-width: 54px;
  color: var(--paper);
  text-align: right;
}

.transport-row {
  display: grid;
  grid-template-columns: 1fr 1fr 0.78fr;
  gap: 8px;
  margin-top: 10px;
}

.transport-row button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 0.86rem;
}

.detected-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.detected-list div {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(247, 239, 223, 0.08);
  border-radius: 8px;
  background: rgba(8, 8, 6, 0.2);
}

.detected-list dt,
.detected-list dd {
  margin: 0;
}

.detected-list dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
  text-transform: uppercase;
}

.detected-list dd {
  margin-top: 3px;
  overflow: hidden;
  color: var(--paper);
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-label {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--paper-2);
  font-weight: 720;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.edit-grid button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 0.88rem;
}

.event-section {
  min-height: 250px;
}

.event-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 3px 9px;
  align-items: center;
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid rgba(247, 239, 223, 0.08);
  border-radius: 8px;
  background: rgba(8, 8, 6, 0.22);
  cursor: pointer;
}

.event-list li:hover,
.event-list li.selected {
  border-color: rgba(52, 216, 191, 0.58);
  background: rgba(52, 216, 191, 0.09);
}

.event-list li.playing {
  border-color: rgba(255, 96, 69, 0.72);
  background: rgba(255, 96, 69, 0.13);
  box-shadow: inset 3px 0 0 var(--coral);
}

.event-list li.selected.playing {
  border-color: rgba(52, 216, 191, 0.78);
  background: linear-gradient(90deg, rgba(255, 96, 69, 0.16), rgba(52, 216, 191, 0.1));
}

.event-list span,
.event-list strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-list small {
  grid-column: 2;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: left;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 68px auto auto;
  }

  .side-panel {
    grid-column: 1;
    grid-row: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 18px;
    overflow: visible;
  }

  .panel-section {
    padding: 0;
    border-bottom: 0;
  }
}

@media (max-width: 820px) {
  .workspace {
    grid-template-rows: 430px auto;
  }

  .capture-readout {
    grid-template-columns: 1fr;
  }

  .capture-deck {
    min-height: 430px;
  }

  .score-head {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .score-actions {
    width: 100%;
  }

  .score-actions .button-link {
    flex: 1 1 0;
  }

  .side-panel {
    display: block;
  }

  .panel-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .brand {
    gap: 8px;
    font-size: 0.93rem;
  }

  .brand img {
    width: 34px;
    height: 34px;
  }

  .job-pill {
    min-width: auto;
    font-size: 0.85rem;
  }

  .button-row,
  .split-row,
  .edit-grid,
  .transport-row {
    grid-template-columns: 1fr;
  }

  .score-container {
    padding: 16px;
  }
}
