:root {
  --bg: #f6f1e8;
  --panel: #fffaf0;
  --paper: #ffffff;
  --ink: #1f2530;
  --muted: #66707d;
  --line: #ded6c9;
  --teal: #087c75;
  --teal-dark: #065d58;
  --amber: #c98216;
  --rose: #b64055;
  --blue: #2e5e9e;
  --shadow: 0 18px 50px rgba(31, 37, 48, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

section {
  scroll-margin-top: 90px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid rgba(31, 37, 48, 0.1);
  background: rgba(246, 241, 232, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background:
    linear-gradient(90deg, transparent 28%, var(--ink) 28% 34%, transparent 34% 62%, var(--ink) 62% 68%, transparent 68%),
    var(--paper);
  box-shadow: inset 0 -9px 0 rgba(8, 124, 117, 0.2);
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.top-actions {
  display: flex;
  align-items: center;
}

.top-actions {
  gap: 8px;
}

.main-nav a,
.ghost-button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.main-nav a:hover,
.main-nav a:focus-visible,
.ghost-button:hover,
.ghost-button:focus-visible {
  border-color: var(--line);
  background: var(--paper);
  outline: none;
}

.ghost-button {
  background: transparent;
}

.practice-band {
  min-height: calc(100vh - 72px);
  padding: clamp(22px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(115deg, rgba(8, 124, 117, 0.16), transparent 42%),
    linear-gradient(180deg, #fcf8ef 0%, #efe7d9 100%);
}

.practice-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: clamp(18px, 4vw, 36px);
  max-width: 1240px;
  margin: 0 auto;
}

.lesson-panel,
.melody-score-card,
.staff-card,
.song-player {
  border: 1px solid rgba(31, 37, 48, 0.12);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: var(--shadow);
}

.lesson-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: clamp(18px, 3vw, 28px);
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1.12;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  letter-spacing: 0;
}

.target-box {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.target-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.target-box strong {
  font-size: 2.7rem;
  line-height: 1;
}

.result-line {
  min-height: 36px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(8, 124, 117, 0.1);
  color: var(--teal-dark);
  font-weight: 800;
}

.result-line.is-wrong {
  background: rgba(182, 64, 85, 0.12);
  color: var(--rose);
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats-strip span {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.stats-strip b {
  display: block;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1.1;
}

.trainer-actions,
.settings-panel {
  display: grid;
  gap: 10px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 900;
}

.primary-button {
  border: 1px solid var(--teal-dark);
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--teal-dark);
  outline: none;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.toggle-row,
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(31, 37, 48, 0.09);
  color: var(--muted);
  font-weight: 800;
}

.toggle-row:last-child,
.field-row:last-child {
  border-bottom: 0;
}

.toggle-row input {
  width: 42px;
  height: 24px;
  accent-color: var(--teal);
}

.field-row input {
  width: 72px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
}

.trainer-surface {
  display: grid;
  grid-template-rows: auto minmax(230px, 32vh) minmax(210px, 1fr);
  gap: 18px;
  min-width: 0;
}

.melody-score-card {
  min-width: 0;
  padding: 16px 18px 18px;
  overflow: hidden;
}

.score-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.score-heading div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.score-heading strong,
.score-heading > span {
  overflow-wrap: anywhere;
}

.score-heading strong {
  font-size: 1.05rem;
}

.score-heading > span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  text-align: right;
}

.score-scroll {
  min-width: 0;
  padding: 6px 0 10px;
  overflow-x: auto;
  scrollbar-color: var(--teal) rgba(31, 37, 48, 0.08);
}

.melody-score {
  display: grid;
  grid-template-columns: 54px minmax(var(--score-width), 1fr);
  align-items: center;
  min-width: 100%;
}

.score-clef {
  position: relative;
  z-index: 2;
  color: var(--blue);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 4.6rem;
  font-weight: 700;
  line-height: 1;
}

.score-staff {
  position: relative;
  height: 112px;
}

.score-staff > span {
  position: absolute;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--ink);
}

.score-staff > span:nth-child(1) {
  top: 18%;
}

.score-staff > span:nth-child(2) {
  top: 34%;
}

.score-staff > span:nth-child(3) {
  top: 50%;
}

.score-staff > span:nth-child(4) {
  top: 66%;
}

.score-staff > span:nth-child(5) {
  top: 82%;
}

.score-note {
  position: absolute;
  z-index: 1;
  top: var(--score-y, 50%);
  left: var(--score-x);
  width: 18px;
  height: 13px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  transform: translate(-50%, -50%) rotate(-18deg);
  transition: background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.score-note::after {
  position: absolute;
  bottom: 6px;
  left: 14px;
  width: 2px;
  height: 38px;
  background: var(--ink);
  content: "";
  transform: rotate(18deg);
  transform-origin: bottom center;
}

.score-note.has-ledger-line::before {
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 2px;
  background: var(--ink);
  content: "";
  transform: translate(-50%, -50%) rotate(18deg);
}

.score-note.is-done {
  border-color: var(--teal);
  background: var(--teal);
  opacity: 0.5;
}

.score-note.is-current {
  border-color: var(--ink);
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(221, 137, 5, 0.2);
}

.staff-card {
  position: relative;
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  min-height: 230px;
  padding: clamp(16px, 3vw, 28px);
  overflow: hidden;
}

.clef {
  color: var(--blue);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 6rem;
  font-weight: 700;
  line-height: 1;
}

.staff {
  position: relative;
  height: 150px;
}

.staff span {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 999px;
  background: var(--ink);
}

.staff span:nth-child(1) {
  top: 18%;
}

.staff span:nth-child(2) {
  top: 34%;
}

.staff span:nth-child(3) {
  top: 50%;
}

.staff span:nth-child(4) {
  top: 66%;
}

.staff span:nth-child(5) {
  top: 82%;
}

.note-orb {
  position: absolute;
  z-index: 1;
  left: 48%;
  top: var(--note-y, 66%);
  width: 36px;
  height: 27px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--amber);
  transform: translate(-50%, -50%) rotate(-18deg);
  transition: top 180ms ease;
}

.note-orb.has-ledger-line::before {
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 3px;
  border-radius: 999px;
  background: var(--ink);
  content: "";
  transform: translate(-50%, -50%) rotate(18deg);
}

.note-orb::after {
  position: absolute;
  left: 29px;
  bottom: 12px;
  width: 3px;
  height: 80px;
  border-radius: 999px;
  background: var(--ink);
  content: "";
  transform: rotate(18deg);
  transform-origin: bottom center;
}

.keyboard-wrap {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(31, 37, 48, 0.12);
  border-radius: 8px;
  background: #2f3137;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.keyboard {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 240px;
  padding-top: 2px;
}

.key {
  position: relative;
  border: 0;
  user-select: none;
}

.white-key {
  flex: 1 1 0;
  min-width: 34px;
  height: 238px;
  margin: 0 1px;
  border: 1px solid #cfc8bc;
  border-bottom: 10px solid #c3b9aa;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #fffdfa 0%, #f3eee4 100%);
  color: var(--ink);
}

.black-key {
  position: absolute;
  top: 0;
  left: calc(((var(--after) + 1) * (100% / 14)) - 2.35%);
  z-index: 2;
  width: 4.7%;
  min-width: 24px;
  max-width: 52px;
  height: 148px;
  border-radius: 0 0 6px 6px;
  border-bottom: 8px solid #111318;
  background: linear-gradient(180deg, #30343b 0%, #111318 100%);
  color: #ffffff;
}

.key-label {
  position: absolute;
  right: 5px;
  bottom: 12px;
  left: 5px;
  display: block;
  overflow: hidden;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.black-key .key-label {
  bottom: 10px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.68rem;
}

.hide-labels .key-label {
  display: none;
}

.key.is-active,
.key.is-target {
  filter: saturate(1.25);
  outline: 3px solid var(--amber);
  outline-offset: -3px;
}

.key.is-correct {
  outline: 4px solid var(--teal);
  outline-offset: -4px;
}

.key.is-wrong {
  outline: 4px solid var(--rose);
  outline-offset: -4px;
}

.content-band {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(34px, 5vw, 62px) clamp(18px, 4vw, 44px);
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-head.compact {
  display: block;
}

.split-band {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: clamp(18px, 4vw, 32px);
  align-items: start;
}

.song-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.song-item {
  display: grid;
  gap: 8px;
  min-height: 106px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: left;
}

.song-item strong,
.song-item span {
  overflow-wrap: anywhere;
}

.song-item strong {
  font-size: 1rem;
}

.song-item span {
  color: var(--muted);
  font-weight: 750;
}

.song-item.is-selected {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 2px rgba(8, 124, 117, 0.18);
}

.song-player {
  padding: 18px;
}

.song-player h3 {
  margin: 6px 0 4px;
  font-size: 1.35rem;
}

.song-player p {
  color: var(--muted);
  font-weight: 700;
}

.note-chain {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 44px;
  margin: 18px 0;
}

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

.song-actions button {
  flex: 1 1 180px;
}

.note-chip {
  min-width: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

.note-chip.is-done {
  border-color: var(--teal);
  background: rgba(8, 124, 117, 0.12);
  color: var(--teal-dark);
}

.note-chip.is-current {
  border-color: var(--orange);
  background: rgba(221, 139, 18, 0.16);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px rgba(221, 139, 18, 0.18);
}

@media (max-width: 940px) {
  section {
    scroll-margin-top: 170px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .top-actions {
    margin-left: auto;
  }

  .main-nav {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .practice-grid,
  .split-band {
    grid-template-columns: 1fr;
  }

  .song-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  section {
    scroll-margin-top: 350px;
  }

  .practice-band {
    padding: 18px 12px 28px;
  }

  .content-band {
    padding-right: 12px;
    padding-left: 12px;
  }

  .lesson-panel {
    padding: 16px;
  }

  .stats-strip,
  .song-list {
    grid-template-columns: 1fr;
  }

  .staff-card {
    grid-template-columns: 48px 1fr;
    min-height: 200px;
  }

  .clef {
    font-size: 4.4rem;
  }

  .keyboard {
    min-width: 620px;
    min-height: 178px;
  }

  .white-key {
    min-width: 40px;
    margin: 0;
    height: 176px;
  }

  .black-key {
    width: 4.9%;
    min-width: 24px;
    height: 112px;
  }

  .key-label {
    right: 2px;
    left: 2px;
    font-size: 0.66rem;
  }

  .black-key .key-label {
    display: none;
  }

  .main-nav a,
  .ghost-button {
    padding-right: 8px;
    padding-left: 8px;
  }

}
