:root {
  color-scheme: light dark;
  --ink: #1f1c1a;
  --muted: #6f6862;
  --paper: #f6f1e9;
  --panel: #fffdf8;
  --line: #e5ddd0;
  --accent: #d2452c;        /* vermilion */
  --accent-soft: #f7d9cf;
  --indigo: #3d4a8f;
  --indigo-soft: #d9ddf3;
  --key-white: #ffffff;
  --key-black: #26221f;
  --radius: 0.9rem;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 6px 24px rgb(0 0 0 / 0.05);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eee8df;
    --muted: #a39b91;
    --paper: #15130f;
    --panel: #1e1b17;
    --line: #34302a;
    --accent: #f06a4e;
    --accent-soft: #5a2b22;
    --indigo: #9aa6ff;
    --indigo-soft: #2c3361;
    --key-white: #e9e4dc;
    --key-black: #0c0b09;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}

header, main, footer {
  max-width: 60rem;
  margin: 0 auto;
  padding-inline: 1rem;
}

/* ---- Header */

header {
  position: relative;
  padding-block: 3rem 1.5rem;
  overflow: hidden;
}
.kanji {
  position: absolute;
  right: 0;
  top: 0.5rem;
  margin: 0;
  font-size: clamp(5rem, 18vw, 10rem);
  line-height: 1;
  color: var(--accent);
  opacity: 0.12;
  user-select: none;
}
h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.tagline { margin: 0.25rem 0 0; color: var(--muted); max-width: 32rem; }

/* ---- Panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  text-transform: capitalize;
}

/* ---- Controls */

.controls { display: flex; flex-wrap: wrap; gap: 1.5rem; }
fieldset { border: 0; margin: 0; padding: 0; }
legend {
  padding: 0;
  margin-bottom: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.inline { display: flex; gap: 0.4rem; }

select, .play, .segmented span {
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.45rem 0.7rem;
}
select { text-transform: capitalize; cursor: pointer; }
select:focus-visible, button:focus-visible, .segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segmented { display: flex; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; cursor: pointer; }
.segmented label:first-child span { border-radius: 0.6rem 0 0 0.6rem; }
.segmented label:last-child span { border-radius: 0 0.6rem 0.6rem 0; border-left: 0; }
.segmented input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.play {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.play:hover { filter: brightness(1.08); }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.secondary {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.45rem 0.7rem;
}
.secondary:hover { border-color: var(--indigo); }
.secondary.connected { border-color: var(--indigo); background: var(--indigo-soft); }
.midi-status { margin: -0.5rem 0 0.75rem; font-size: 0.85rem; color: var(--muted); }
.midi-status:empty { display: none; }

.size { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.9rem; }
.size input, .volume input { accent-color: var(--accent); }
.volume { display: flex; align-items: center; gap: 0.4rem; min-height: 2.4rem; }
.size output { font-weight: 700; color: var(--ink); min-width: 1ch; }

.error {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
}

/* ---- Keyboard */

.keyboard-wrap { overflow-x: auto; padding-bottom: 0.25rem; }
.keyboard {
  --w: calc(100% / var(--whites));
  position: relative;
  display: flex;
  height: 10rem;
  min-width: calc(var(--whites) * 1.9rem);
}
.key {
  font: inherit;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: background-color 0.15s, transform 0.08s;
}
.key span { font-size: 0.7rem; font-weight: 600; margin-bottom: 0.4rem; pointer-events: none; }
.key.white {
  flex: 1;
  background: var(--key-white);
  border: 1px solid var(--line);
  border-radius: 0 0 0.4rem 0.4rem;
  color: var(--muted);
}
.key.black {
  position: absolute;
  top: 0;
  left: calc(var(--at) * var(--w));
  width: calc(var(--w) * 0.62);
  height: 62%;
  transform: translateX(-50%);
  z-index: 1;
  background: var(--key-black);
  border: 0;
  border-radius: 0 0 0.3rem 0.3rem;
  color: #fff;
}
.key.black span { font-size: 0.6rem; }

.key.white.in-key { background: color-mix(in srgb, var(--accent-soft) 45%, var(--key-white)); }
.key.white.in-scale { background: var(--accent-soft); color: var(--ink); }
.key.black.in-scale { background: color-mix(in srgb, var(--accent) 70%, black); }
.key.root { background: var(--accent); color: #fff; }
.key.white.root { background: var(--accent); color: #fff; }
.key.in-chord { box-shadow: inset 0 -0.5rem 0 var(--indigo); }
.key.playing { transform: translateY(2px); filter: brightness(1.15); }
.key.white.pressed, .key.black.pressed { background: var(--indigo); color: #fff; transform: translateY(2px); }
.key.black.pressed { transform: translateX(-50%) translateY(2px); }
.key.white.off-key, .key.black.off-key { background: var(--muted); }
.key.black.playing { transform: translateX(-50%) translateY(2px); }

/* ---- Scale notes */

.notes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}
.notes li {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.2rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.08s;
}
.notes small { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.05em; }
.notes li.root { border-color: var(--accent); color: var(--accent); }
.notes li:hover, .notes li.playing { background: var(--accent-soft); }
.notes li.playing { transform: translateY(-2px); }

/* ---- Chords */

.chords {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.75rem;
}
.chord {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.8rem 0.9rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  transition: border-color 0.15s, transform 0.08s;
}
.chord:hover { border-color: var(--indigo); transform: translateY(-1px); }
.chord.selected { border-color: var(--indigo); background: var(--indigo-soft); }
.degree {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--indigo);
}
.chord-notes { font-size: 0.85rem; color: var(--muted); }
.chord.selected .chord-notes { color: var(--ink); }

/* ---- Footer */

footer {
  padding-block: 1rem 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
footer a { color: var(--accent); }

/* ---- Shared small pieces */

.hint { color: var(--muted); font-size: 0.85rem; margin: 0.75rem 0; }
.pattern { margin: 0.75rem 0 0; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.08em; white-space: pre; }
.chip {
  font: inherit;
  color: inherit;
  display: inline-block;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.85rem;
  font-weight: 600;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--accent); text-decoration: line-through; }
.chip.current { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.chip.changed { background: var(--accent-soft); border-color: var(--accent); }
.secondary:disabled, .play:disabled { opacity: 0.4; cursor: default; }
.actions + .actions { margin-top: 0.75rem; }
.sequence-row { display: flex; align-items: center; gap: 0.5rem; min-height: 2.5rem; margin: 0.75rem 0; }
.sequence-row .hint { margin: 0; }

/* ---- Modes compared */

.modes { display: flex; flex-direction: column; gap: 0.5rem; }
.mode-row {
  display: grid;
  grid-template-columns: 9rem 9rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
}
.mode-row.selected { border-color: var(--indigo); background: var(--indigo-soft); }
.mode-name {
  font: inherit;
  color: inherit;
  text-align: left;
  text-transform: capitalize;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.mode-name:hover { color: var(--accent); }
.steps { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.08em; }
.mode-notes { display: flex; flex-wrap: wrap; gap: 0.3rem; }
@media (max-width: 40rem) {
  .mode-row { grid-template-columns: 1fr auto; }
  .steps, .mode-notes { grid-column: 1 / -1; }
}

/* ---- Notation */

.text {
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.45rem 0.7rem;
  width: 9rem;
}
.text:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.note-result { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 1rem; min-height: 2.5rem; }
.midi-number { font-family: Georgia, "Times New Roman", serif; font-size: 1.3rem; font-weight: 600; color: var(--indigo); }
.error-inline { color: var(--accent); }

/* Octave number shown only where the octave changes */
sup { font-size: 0.65em; margin-left: 0.05em; color: var(--muted); }

/* ---- Settings bar: stays at the top while scrolling, since it drives the whole page */

.controls.sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 1rem 1.5rem;
  padding: 0.75rem 1rem;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: 0;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.08);
}
.controls.sticky legend { margin-bottom: 0.2rem; }
@media (max-width: 40rem) {
  .controls.sticky { gap: 0.5rem 1rem; padding: 0.5rem 0.75rem; }
  .controls.sticky legend { display: none; }
}
