:root {
  color-scheme: light;
  --navy-950: #0b1f33;
  --navy-900: #102a43;
  --navy-800: #173f5f;
  --blue-100: #dcecf7;
  --blue-50: #eef7fc;
  --paper: #ffffff;
  --ink: #162536;
  --muted: #5a6b7b;
  --gold: #c77418;
  --gold-dark: #8f4d08;
  --gold-soft: #fff0d4;
  --line: #cbd9e4;
  --success: #146b52;
  --shadow: 0 18px 45px rgba(9, 31, 51, 0.13);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-size: 18px;
}

* { box-sizing: border-box; }
.discovery-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.65rem; margin: 1rem 0; }
.discovery-actions button, .discovery-footer button { width: 100%; white-space: normal; overflow-wrap: anywhere; }
.discovery-actions [aria-pressed="true"] { color: white; background: var(--navy-800); }
.discovery-change { padding: 1rem; background: var(--gold-soft); color: var(--navy-800); border-radius: 12px; font-size: 1.4rem; font-weight: 800; text-align: center; }
.discovery-footer { margin-top: 1.2rem; border-top: 1px solid var(--line); padding-top: 1rem; }
#discovery-records { overflow-wrap: anywhere; }
[hidden] { display: none !important; }

.practice-modes, .melody-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-bottom: 1rem; }
.practice-modes button { flex: 1; }
.practice-modes [aria-pressed="true"] { background: var(--navy-800); color: white; }
.melody-position { padding: 0.65rem 1rem; background: var(--navy-950); color: white; border-radius: 10px; font-weight: 700; }
.melody-challenge { display: flex; align-items: center; gap: 0.65rem; min-height: 48px; margin-bottom: 0.8rem; }
.melody-challenge input { width: 22px; height: 22px; flex: 0 0 22px; accent-color: var(--navy-800); }
.melody-bars { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.melody-bar { min-width: 0; padding: 0.8rem; border: 2px solid var(--line); border-radius: 12px; background: var(--blue-50); }
.melody-bar[aria-current] { border-color: var(--gold-dark); background: var(--gold-soft); }
.melody-bar h3 { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.4rem; }
.melody-chord { color: var(--navy-800); }
.melody-bar select, .melody-bar button { width: 100%; min-width: 0; max-width: 100%; margin-top: 0.5rem; }
.melody-hints { margin: 1rem 0; padding: 0.8rem; border: 1px solid var(--line); border-radius: 10px; }
.melody-hints summary { cursor: pointer; min-height: 44px; font-weight: 700; }
.melody-hints p { margin: 0.6rem 0; }
.melody-example { padding: 1rem; margin: 0.8rem 0; background: var(--blue-50); border-radius: 12px; }
.melody-example-chords { font-size: 1.2rem; font-weight: 700; overflow-wrap: anywhere; }
#melody-records { overflow-wrap: anywhere; margin-bottom: 1.5rem; }
@media (max-width: 590px) {
  .melody-bars { grid-template-columns: minmax(0, 1fr); }
  .melody-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .practice-modes { display: grid; grid-template-columns: minmax(0, 1fr); }
  .recent-item { flex-wrap: wrap; }
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(23, 63, 95, 0.07) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--blue-50);
  line-height: 1.7;
}

button, select { font: inherit; }
button, select { min-height: 48px; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.65; }

:focus-visible {
  outline: 4px solid #f2a63b;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 20;
  transform: translateY(-150%);
  padding: 0.7rem 1rem;
  color: white;
  background: var(--navy-950);
  border-radius: 8px;
}
.skip-link:focus { transform: none; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.15rem clamp(1rem, 4vw, 3rem);
  color: white;
  background: var(--navy-950);
  border-bottom: 4px solid var(--gold);
}

.brand { display: flex; align-items: center; gap: 1rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  color: var(--navy-950);
  background: var(--gold-soft);
  border-radius: 50%;
  font-weight: 800;
  font-family: Georgia, serif;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.15rem, 2.4vw, 1.55rem); line-height: 1.35; }
h2 { margin-bottom: 0.25rem; font-size: clamp(1.35rem, 3vw, 1.8rem); line-height: 1.4; }
h3 { font-size: 1.08rem; }
.eyebrow {
  margin-bottom: 0.1rem;
  color: #a9cee6;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.top-tabs { display: flex; gap: 0.35rem; }
.tab-button {
  padding: 0.55rem 1rem;
  color: #dbeaf4;
  background: transparent;
  border: 1px solid #55738a;
  border-radius: 999px;
}
.tab-button.is-active {
  color: var(--navy-950);
  background: white;
  border-color: white;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, 290px) minmax(0, 820px);
  justify-content: center;
  gap: 1.4rem;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 1.5rem clamp(0.85rem, 3vw, 2rem) 3rem;
}
.app-shell > * {
  min-width: 0;
  max-width: 100%;
}

.level-panel, .practice-card, .control-bar, .records-view {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.level-panel {
  align-self: start;
  position: sticky;
  top: 1rem;
  padding: 1rem;
  border-radius: 18px;
}
.level-panel .eyebrow { color: var(--gold-dark); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 0.5rem; }
.panel-heading h2 { font-size: 1.18rem; }
.attempt-badge {
  white-space: nowrap;
  padding: 0.25rem 0.6rem;
  color: var(--navy-800);
  background: var(--blue-100);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.level-list {
  display: grid;
  gap: 0.45rem;
  max-width: 100%;
  margin-top: 0.9rem;
  overscroll-behavior-x: contain;
}
.level-button {
  display: grid;
  grid-template-columns: 2.1rem 1fr;
  gap: 0.65rem;
  align-items: center;
  width: 100%;
  padding: 0.55rem 0.65rem;
  text-align: left;
  color: var(--ink);
  background: white;
  border: 1px solid transparent;
  border-radius: 10px;
}
.level-button:hover { background: var(--blue-50); }
.level-button.is-active {
  color: white;
  background: var(--navy-800);
}
.level-number {
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  color: var(--navy-900);
  background: var(--gold-soft);
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 800;
}
.level-name { font-size: 0.88rem; font-weight: 700; line-height: 1.35; }

.workspace { min-width: 0; }
.control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.9rem;
  border-radius: 14px;
}
.control-bar > * {
  min-width: 0;
  max-width: 100%;
}
.control-bar label { display: flex; align-items: center; gap: 0.45rem; }
.control-bar label span { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
select {
  padding: 0.35rem 2.1rem 0.35rem 0.65rem;
  color: var(--ink);
  background: white;
  border: 1px solid #9cb1c1;
  border-radius: 8px;
}
.control-bar select,
.control-bar input,
.control-bar button {
  width: 100%;
  max-width: 100%;
}
.volume-control input { width: 120px; accent-color: var(--gold); }
.mute-toggle {
  align-self: center;
  padding: 0.35rem 0.8rem;
  color: var(--navy-800);
  background: white;
  border: 1px solid #9cb1c1;
  border-radius: 8px;
  font-weight: 700;
}
.mute-toggle[aria-pressed="true"] { color: white; background: var(--navy-800); }

.feeling-guide {
  margin-bottom: 0.9rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.feeling-guide summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  color: var(--navy-800);
  cursor: pointer;
  font-weight: 800;
}
.feeling-guide summary small { color: var(--muted); font-size: 0.75rem; font-weight: 400; }
.feeling-guide[open] summary { border-bottom: 1px solid var(--line); }
.feeling-guide-intro { margin: 0; padding: 0.9rem 1rem 0; color: var(--muted); font-size: 0.88rem; }
.feeling-guide-list { display: grid; gap: 1.1rem; padding: 1rem; }
.feeling-guide-list h3 { margin-bottom: 0.55rem; color: var(--navy-900); }
.feeling-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.feeling-card {
  min-width: 0;
  padding: 0.75rem;
  background: var(--blue-50);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.feeling-card div { display: flex; align-items: center; gap: 0.55rem; }
.feeling-symbol {
  display: inline-grid;
  place-items: center;
  min-width: 2.6rem;
  min-height: 2.2rem;
  padding: 0.15rem 0.4rem;
  color: white;
  background: var(--navy-800);
  border-radius: 8px;
  font-family: Georgia, "Yu Mincho", serif;
  font-weight: 800;
}
.feeling-card p { margin: 0.55rem 0 0.35rem; font-size: 0.85rem; }
.feeling-card small { color: var(--muted); font-size: 0.76rem; }

.practice-card {
  position: relative;
  overflow: hidden;
  padding: clamp(1.2rem, 4vw, 2.35rem);
  border-radius: 22px;
}
.practice-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: linear-gradient(90deg, var(--gold), #f1b859, var(--navy-800));
}
.lesson-meta { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.level-badge {
  padding: 0.2rem 0.65rem;
  color: var(--gold-dark);
  background: var(--gold-soft);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.lesson-counter { color: var(--muted); font-size: 0.82rem; }
.lesson-summary { color: var(--muted); }

.progression {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  min-height: 104px;
  padding: 1.2rem;
  margin: 1.2rem 0;
  background: var(--navy-950);
  border-radius: 16px;
}
.chord-token, .question-token {
  display: inline-grid;
  place-items: center;
  min-width: 3.2rem;
  min-height: 3.2rem;
  padding: 0.25rem 0.8rem;
  color: var(--navy-950);
  background: white;
  border-radius: 12px;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: 1.3rem;
  font-weight: 800;
}
.question-token {
  color: white;
  background: transparent;
  border: 2px dashed #e4a546;
}
.flow-arrow { color: #e8bd73; font-size: 1.35rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 52px;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  font-weight: 800;
}
.button-primary { color: white; background: var(--navy-800); border: 2px solid var(--navy-800); }
.button-primary:hover { background: var(--navy-950); }
.button-secondary { color: var(--navy-800); background: white; border: 2px solid var(--navy-800); }
.button-sound { color: var(--gold-dark); background: var(--gold-soft); border: 2px solid #e6a94e; }

.prediction-prompt {
  padding: 1rem 1.1rem;
  margin: 1.25rem 0;
  background: var(--blue-50);
  border-left: 5px solid var(--gold);
}
.prediction-prompt p { margin-bottom: 0.2rem; font-weight: 700; }
.prediction-prompt .subtle { margin: 0; color: var(--muted); font-size: 0.88rem; font-weight: 400; }

.answer-panel {
  padding-top: 1.4rem;
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
}
.answer-label { margin-bottom: 0.2rem; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.answer-chord {
  margin-bottom: 0.5rem;
  color: var(--navy-900);
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 800;
  line-height: 1.25;
}
.alternative-answer { color: var(--gold-dark); font-weight: 700; }
.candidate-actions { display: grid; gap: 0.65rem; margin-top: 0.85rem; }
.candidate-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem;
  background: var(--blue-50);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.candidate-card p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.candidate-card strong { display: block; color: var(--navy-900); font-size: 1rem; }
.explanation { padding: 0.8rem 1rem; background: #f6f9fb; border-radius: 10px; }
.answer-feeling {
  padding: 0.85rem 1rem;
  margin: 0.85rem 0;
  background: var(--gold-soft);
  border-left: 5px solid var(--gold);
  border-radius: 10px;
}
.answer-feeling p { margin-bottom: 0.25rem; }
.answer-feeling-title { color: var(--navy-900); }
.answer-feeling small { color: var(--gold-dark); }
.song-references {
  padding: 1rem;
  margin: 0.85rem 0;
  background: #f6f9fb;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.song-references h3 { margin-bottom: 0.65rem; color: var(--navy-900); }
.song-reference-card { min-width: 0; }
.song-reference-card p { margin-bottom: 0.4rem; overflow-wrap: anywhere; }
.song-reference-meta { color: var(--gold-dark); font-size: 0.9rem; font-weight: 700; }
.song-reference-meta span { font-family: Georgia, "Yu Mincho", serif; }
.song-reference-caution { margin: 0.7rem 0 0; color: var(--muted); font-size: 0.76rem; }
.assessment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1rem;
}
.assessment p { margin: 0; }
.assessment div { display: flex; gap: 0.55rem; }

.records-view {
  padding: clamp(1.2rem, 4vw, 2rem);
  border-radius: 22px;
}
.records-heading { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.records-heading .eyebrow { color: var(--gold-dark); }
.record-total { display: grid; text-align: right; }
.record-total strong { color: var(--navy-800); font-size: 2.2rem; line-height: 1; }
.record-total span { color: var(--muted); font-size: 0.78rem; }
.level-records { display: grid; gap: 0.75rem; margin: 1.4rem 0; }
.record-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 2fr auto;
  gap: 0.8rem;
  align-items: center;
}
.record-row strong { font-size: 0.9rem; }
.progress-track { height: 10px; overflow: hidden; background: var(--blue-100); border-radius: 999px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--success)); border-radius: inherit; }
.record-count { color: var(--muted); font-size: 0.8rem; }
.recent-card { padding: 1rem; background: var(--blue-50); border-radius: 14px; }
.recent-card h3 { margin-bottom: 0.6rem; }
.recent-item { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-top: 1px solid var(--line); }
.recent-item:first-child { border-top: 0; }
.recent-result { white-space: nowrap; color: var(--muted); font-size: 0.82rem; }
.empty-record { color: var(--muted); }

.sr-only {
  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: 820px) {
  .app-header { align-items: flex-start; }
  .brand-mark { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .level-panel { position: static; }
  .level-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 0.35rem;
    scroll-snap-type: x proximity;
  }
  .level-button {
    flex: 0 0 175px;
    scroll-snap-align: start;
  }
}

@media (max-width: 590px) {
  :root { font-size: 18px; }
  .app-header { display: grid; padding: 0.9rem; }
  .top-tabs { width: 100%; }
  .tab-button { flex: 1; }
  .app-shell { padding: 0.8rem 0.65rem 2rem; }
  .control-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.65rem; padding: 0.75rem; }
  .control-bar label { display: grid; gap: 0.1rem; }
  .control-bar select { width: 100%; min-width: 0; padding-right: 0.2rem; }
  .volume-control input { width: 100%; }
  .feeling-guide summary { align-items: flex-start; flex-direction: column; gap: 0.1rem; }
  .feeling-grid { grid-template-columns: minmax(0, 1fr); }
  .candidate-card { align-items: stretch; flex-direction: column; }
  .practice-card { border-radius: 16px; }
  .progression { padding: 0.8rem; gap: 0.4rem; }
  .chord-token, .question-token { min-width: 2.75rem; min-height: 2.75rem; padding: 0.2rem 0.55rem; }
  .assessment { display: grid; }
  .assessment div { display: grid; grid-template-columns: 1fr 1fr; }
  .records-heading { display: grid; }
  .record-total { text-align: left; }
  .record-row { grid-template-columns: 1fr auto; }
  .progress-track { grid-column: 1 / -1; grid-row: 2; }
}

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