:root {
  --bg: #0e1014;
  --panel: #161a21;
  --fg: #e8eaee;
  --muted: #7d8592;
  --line: #9aa3b0;
  --white-key: #eceef2;
  --black-key: #1b1e24;
  --ok: #5fd38d;
  --warn: #e8b84a;
  --error: #ef6a6a;
  --music-font: 'Noto Music', 'Bravura Text', 'Apple Symbols', 'Segoe UI Symbol', serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(90px, 24vh) auto;
  gap: 12px;
  padding: 12px 16px 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
  user-select: none;
}

/* Header */
.top {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-radius: 14px;
}

.chord-symbol {
  font-size: clamp(36px, 7vh, 84px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chord-description {
  color: var(--muted);
  font-size: clamp(13px, 1.8vh, 18px);
  min-height: 1.3em;
}

.note-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}

.pill {
  min-width: 44px;
  padding: 6px 12px;
  border-radius: 999px;
  color: #0b0c0f;
  font-size: clamp(18px, 3vh, 28px);
  font-weight: 700;
  text-align: center;
}

.pill.sustained {
  color: #d6d9df;
}

.note-list {
  margin-top: 6px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  min-height: 1.2em;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-size: 13px;
}

.controls select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #2b313b;
  border-radius: 6px;
  padding: 3px 6px;
  font: inherit;
}

.pedal {
  padding: 2px 8px;
  border: 1px solid #2b313b;
  border-radius: 6px;
  color: var(--muted);
  font-style: italic;
}

.pedal.down {
  background: var(--warn);
  border-color: var(--warn);
  color: #0b0c0f;
}

.midi-status {
  max-width: 240px;
  text-align: right;
  color: var(--muted);
}

.midi-status::before {
  content: '●  ';
}

.midi-status[data-level='ok']::before {
  color: var(--ok);
}

.midi-status[data-level='warn']::before {
  color: var(--warn);
}

.midi-status[data-level='error']::before {
  color: var(--error);
}

/* Middle row */
.middle {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.middle svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--panel);
  border-radius: 14px;
}

/* Staff */
.staff-line {
  stroke: var(--line);
  stroke-width: 1;
}

.staff-line.system {
  stroke-width: 2;
}

.ledger-line {
  stroke: var(--line);
  stroke-width: 1.2;
}

.clef {
  fill: var(--fg);
  font-family: var(--music-font);
}

.clef.treble {
  font-size: 40px;
}

.clef.bass {
  font-size: 40px;
}

.note-head {
  stroke: #0b0c0f;
  stroke-width: 0.8;
}

.staff {
  overflow: visible;
}

.accidental {
  font-family: var(--music-font);
  font-size: 22px;
  text-anchor: middle;
  dominant-baseline: central;
}

/* Circle of fifths */
.circle-ring {
  fill: none;
  stroke: #2b313b;
  stroke-width: 1;
}

.circle-ring.inner {
  stroke-dasharray: 2 4;
}

.circle-shape {
  fill: rgb(255 255 255 / 0.07);
  stroke: rgb(255 255 255 / 0.55);
  stroke-width: 2;
  stroke-linejoin: round;
}

.circle-root-lines line {
  stroke-width: 2.5;
  stroke-dasharray: 5 4;
  opacity: 0.8;
}

.circle-node {
  fill: #20252e;
  stroke: #2b313b;
  stroke-width: 1.5;
}

.circle-node.root {
  stroke: var(--fg);
  stroke-width: 3.5;
}

.circle-label {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
}

.circle-label.active {
  fill: #0b0c0f;
}

.circle-minor {
  fill: #4d5562;
  font-size: 10px;
  text-anchor: middle;
  dominant-baseline: central;
}

/* Keyboard */
.keyboard {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.key.white {
  fill: var(--white-key);
  stroke: #9aa0aa;
  stroke-width: 0.6;
}

.key.black {
  fill: var(--black-key);
  stroke: #000;
  stroke-width: 0.6;
}

.key-label {
  font-size: 9px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

.key-label.c-marker {
  fill: #9aa0aa;
  font-weight: 500;
}

.key-label.active {
  fill: #0b0c0f;
  font-weight: 700;
}

.hint {
  color: #4d5562;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 760px) {
  body {
    grid-template-rows: auto minmax(0, 1fr) minmax(80px, 18vh) auto;
    padding: 8px 16px;
  }

  .top {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .controls {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
  }

  .middle {
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr);
  }
}
