:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: #f4f6fb;
  color: #1f2933;
  --page-horizontal-spacing: clamp(1rem, 3vw, 1.75rem);
  --page-vertical-spacing: clamp(1.25rem, 5vh, 2.5rem);
  --column-gap: clamp(1.5rem, 5vw, 3rem);
  --section-gap: clamp(1rem, 4vh, 1.75rem);
  --card-padding: clamp(1rem, 4vh, 1.5rem);
  --score-item-min-height: clamp(64px, 10vh, 90px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--page-vertical-spacing) var(--page-horizontal-spacing);
  display: flex;
  flex-direction: column;
  gap: var(--page-vertical-spacing);
  min-height: 100vh;
}

.layout-column {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
}

.layout-column--right {
  order: 1;
  flex: 1;
}

.layout-column--left {
  order: 2;
  flex: 1;
  align-self: stretch;
}

@media (min-width: 960px) {
  .page {
    display: grid;
    grid-template-columns: max-content minmax(280px, 1fr);
    gap: var(--column-gap);
    align-items: start;
    align-content: center;
  }

  .layout-column--left,
  .layout-column--right {
    order: initial;
  }

  .layout-column--right > * {
    margin-bottom: 0;
  }

  .page-header,
  .instructions,
  .answer-panel,
  .feedback,
  .mode-toggle,
  .mode-control {
    text-align: left;
  }

  .page-header p,
  .feedback {
    margin: 0;
  }

  .layout-column--left {
    max-width: 360px;
  }

  .layout-column--left .staff-card {
    width: 100%;
  }

  .staff-scale-hint {
    text-align: left;
  }

  .mode-toggle {
    align-items: flex-start;
  }

  .mode-control {
    align-items: flex-start;
  }

  .mode-control__input {
    max-width: none;
  }
}

.page-header {
  text-align: center;
  margin: 0;
}

.page-header h1 {
  font-size: clamp(1.9rem, 3vw, 2.4rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 0 auto;
  max-width: 48ch;
  line-height: 1.6;
  font-size: clamp(0.95rem, 1.3vw, 1.05rem);
  color: #475466;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: clamp(0.75rem, 2vw, 1rem);
  margin: 0;
}

.score-item {
  background: #ffffff;
  border-radius: 14px;
  padding: clamp(0.75rem, 2vh, 1rem) clamp(0.9rem, 2.5vw, 1.25rem);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: var(--score-item-min-height);
}

.score-item--midi {
  appearance: none;
  border: 1.5px solid #d1d7e2;
  color: #1f3bd4;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease,
    color 120ms ease, background 120ms ease;
}

.score-item--midi:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(31, 59, 212, 0.14);
}

.score-item--midi:focus-visible {
  outline: none;
  border-color: #4e6aff;
  box-shadow: 0 0 0 3px rgba(78, 106, 255, 0.35);
}

.score-item--midi-connected {
  border-color: #4e6aff;
  color: #1f3bd4;
  background: #e7edff;
}

.score-item--midi-failed {
  border-color: #e24d4d;
  color: #7f1d1d;
  background: #ffe8e8;
}

.score-label {
  font-size: 0.9rem;
  color: #738091;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.score-value {
  font-size: clamp(1.35rem, 2.5vw, 1.7rem);
  font-weight: 700;
}

.instructions {
  margin: 0;
  text-align: center;
  color: #3c4858;
  line-height: 1.5;
  font-size: clamp(0.95rem, 1.2vw, 1.05rem);
}

.mode-toggle {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: clamp(0.9rem, 1.1vw, 1rem);
  color: #3c4858;
  text-align: center;
}

.mode-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  font-size: clamp(0.9rem, 1.1vw, 1rem);
  color: #3c4858;
  text-align: center;
}

.mode-toggle__label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.mode-toggle__label input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #4e6aff;
}

.mode-control__label {
  font-weight: 600;
}

.mode-control__input {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}

.mode-control__input--select {
  justify-content: center;
}

.mode-control__input--select select {
  width: min(100%, 320px);
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid #c8d1e0;
  background: #ffffff;
  color: #1f2933;
  font: inherit;
}

.mode-control__input input[type="range"] {
  flex: 1;
  accent-color: #4e6aff;
}

.mode-toggle__inline-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.mode-toggle__inline-control select {
  width: auto;
  min-width: 4.5ch;
  max-width: none;
  padding: 0.2rem 0.4rem;
  border-radius: 8px;
  border: 1px solid #c8d1e0;
  background: #ffffff;
  color: #1f2933;
  font: inherit;
}

.mode-toggle__inline-control select:disabled {
  background: #eef2f8;
  color: #7b8797;
}

.mode-control__input output {
  min-width: 3.5ch;
  font-weight: 600;
}

.mode-toggle__hint {
  margin: 0;
  font-size: clamp(0.8rem, 1vw, 0.85rem);
  color: #5b6779;
}

.mode-control__hint {
  margin: 0;
  font-size: clamp(0.8rem, 1vw, 0.85rem);
  color: #5b6779;
}

.inline-button {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: #e2e8ff;
  color: #1f3bd4;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.inline-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(31, 59, 212, 0.2);
}

.inline-button:active {
  transform: none;
}

.staff-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  justify-content: center;
  align-items: flex-start;
}

.staff-scale-hint {
  margin: 0;
  text-align: center;
  font-size: clamp(0.86rem, 1.05vw, 0.95rem);
  color: #5b6779;
  font-weight: 600;
}

.staff-card {
  background: linear-gradient(180deg, #ffffff 0%, #f8f9fe 100%);
  border-radius: 18px;
  padding: var(--card-padding);
  position: relative;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  gap: clamp(0.75rem, 2vh, 1rem);
  align-items: flex-start;
  max-width: 100%;
}

.staff-card h2 {
  margin: 0;
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4b5d75;
}

.staff-card.active {
  border-color: #4e6aff;
  box-shadow: 0 12px 28px rgba(55, 81, 255, 0.23);
  transform: translateY(-4px);
}

.staff-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(280px, 33vw, 320px);
  min-height: 190px;
}

.staff-svg svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
}

.clef {
  fill: #1f2933;
  font-family: "Noto Music", "Bravura", "Petaluma", "Times New Roman", "Segoe UI Symbol", serif;
}

.clef-treble {
  letter-spacing: -0.08em;
}

.staff-line {
  stroke: #1f2933;
  stroke-width: 1.5;
}

.ledger-line {
  stroke: #1f2933;
  stroke-width: 1.4;
  stroke-linecap: round;
}

.key-signature-accidental {
  font-family: "Noto Music", "Bravura", "Petaluma", "Times New Roman", "Segoe UI Symbol", serif;
}

.key-signature-accidental--alt {
  fill: #e1741a;
}

.note-group.hidden {
  display: none;
}

.note-head {
  fill: #111827;
}

.answer-panel {
  text-align: center;
  margin: 0;
}

.answer-buttons {
  display: inline-grid;
  grid-template-columns: repeat(7, minmax(44px, 1fr));
  gap: clamp(0.5rem, 1.5vw, 0.75rem);
  padding: clamp(0.75rem, 2vh, 1rem) clamp(1rem, 3vw, 1.5rem);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.1);
}

.answer-buttons--chromatic {
  grid-template-columns: repeat(6, minmax(64px, 1fr));
}

.answer-buttons--chromatic .answer-button {
  font-size: clamp(0.88rem, 1.4vw, 0.98rem);
}

.answer-button {
  padding: clamp(0.65rem, 2vh, 0.85rem) 0.5rem;
  font-size: clamp(1.05rem, 1.8vw, 1.2rem);
  font-weight: 600;
  border-radius: 12px;
  border: 1.5px solid #d1d7e2;
  background: linear-gradient(180deg, #f8f9fe 0%, #eef1ff 100%);
  color: #18223a;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.answer-button:focus-visible {
  outline: none;
  border-color: #4e6aff;
  box-shadow: 0 0 0 3px rgba(78, 106, 255, 0.35);
}

.answer-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.answer-button.correct {
  border-color: #1ca77b;
  background: linear-gradient(180deg, #d6f6eb 0%, #b8f2de 100%);
  color: #0f5132;
}

.answer-button.incorrect {
  border-color: #e24d4d;
  background: linear-gradient(180deg, #ffe4e4 0%, #ffd0d0 100%);
  color: #7f1d1d;
}

.feedback {
  margin: 0 auto;
  max-width: 46ch;
  text-align: center;
  font-size: clamp(1rem, 1.5vw, 1.1rem);
  padding: clamp(0.75rem, 2vh, 1rem) clamp(1rem, 2.5vw, 1.25rem);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
}

.feedback.positive {
  border: 1px solid #1ca77b;
  color: #0f5132;
  background: #dcf7ec;
}

.feedback.negative {
  border: 1px solid #e24d4d;
  color: #7f1d1d;
  background: #ffe8e8;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) and (orientation: portrait) {
  :root {
    --page-horizontal-spacing: 0.75rem;
    --page-vertical-spacing: 0.75rem;
    --section-gap: 0.65rem;
    --card-padding: 0.65rem;
    --score-item-min-height: 52px;
  }

  body {
    min-height: 100dvh;
  }

  .page {
    min-height: 100dvh;
    gap: 0.6rem;
    padding-bottom: calc(5rem + env(safe-area-inset-bottom));
  }

  .layout-column--left {
    order: 1;
  }

  .layout-column--right {
    order: 2;
    gap: 0.6rem;
  }

  .page-header h1 {
    font-size: clamp(1.3rem, 7vw, 1.6rem);
    margin-bottom: 0.35rem;
  }

  .scoreboard {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .score-item {
    border-radius: 10px;
    padding: 0.45rem 0.3rem;
  }

  .score-label {
    margin-bottom: 0.2rem;
    font-size: 0.67rem;
    letter-spacing: 0.04em;
  }

  .score-value {
    font-size: clamp(0.95rem, 4.8vw, 1.1rem);
  }

  .instructions,
  .mode-toggle,
  .mode-control,
  .mode-control__hint {
    font-size: 0.84rem;
  }

  .mode-toggle__inline-control {
    white-space: normal;
    justify-content: center;
  }

  .mode-control__input--select select {
    width: 100%;
  }

  .mode-control__input {
    max-width: none;
  }

  .staff-wrapper {
    gap: 0.55rem;
  }

  .staff-card {
    border-radius: 12px;
    gap: 0.45rem;
  }

  .staff-card h2 {
    font-size: 0.78rem;
    letter-spacing: 0.03em;
  }

  .staff-card.active {
    transform: none;
  }

  .staff-svg {
    width: clamp(210px, 67vw, 250px);
    min-height: 170px;
  }

  .answer-panel {
    position: fixed;
    left: var(--page-horizontal-spacing);
    right: var(--page-horizontal-spacing);
    bottom: max(0.45rem, env(safe-area-inset-bottom));
    z-index: 30;
  }

  .answer-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.35rem;
    padding: 0.45rem;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
  }

  .answer-buttons--chromatic {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .answer-buttons--chromatic .answer-button {
    font-size: 0.84rem;
  }

  .answer-button {
    min-height: 40px;
    padding: 0.42rem 0;
    border-radius: 10px;
    font-size: 0.96rem;
  }

  .feedback {
    font-size: 0.9rem;
    padding: 0.6rem 0.75rem;
  }
}
