/* Shared layout for MUS 2006 Ear Training.
   Change the tokens here and every page follows. */

:root {
  color-scheme: light;
  --paper: #f4f2eb;
  --card: #fffefa;
  --ink: #24372d;
  --muted: #718078;
  --green: #26724d;
  --green-dark: #1e5e3f;
  --line: #dfe5db;
  --lime: #c7e48c;
  --orange: #e68d57;
  --yellow: #e5c35f;
  --red: #d97868;
  --shadow: 0 14px 40px rgba(35, 55, 43, 0.07);
  --radius: 17px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --wrap: 1080px;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 85% 0, rgba(199, 228, 140, 0.28), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
a { color: inherit; }
button, a, .pill { touch-action: manipulation; }
img { max-width: 100%; height: auto; }

code {
  padding: 0 4px;
  border-radius: 5px;
  background: rgba(38, 114, 77, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

[hidden] { display: none !important; }

.skip {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 5;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--green);
  color: white;
  transform: translateY(-140%);
}

.skip:focus { transform: none; }

.shell {
  width: min(100%, var(--wrap));
  margin: 0 auto;
  padding:
    16px
    max(16px, env(safe-area-inset-right))
    calc(28px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.03em;
  text-decoration: none;
  white-space: nowrap;
}

.brand b { color: var(--green); font-weight: 750; }

.mark {
  width: 27px;
  height: 27px;
  border-radius: 9px;
  background: var(--green);
  position: relative;
  flex: none;
  transform: rotate(-7deg);
}

.mark::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 8px;
  width: 8px;
  height: 8px;
  border: 2px solid #f1f5e7;
  border-radius: 50%;
  box-shadow: 4px -4px 0 -1px var(--lime);
}

.nav-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  max-width: 100%;
}

.pill,
.nav-current {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.72);
  color: var(--green);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.pill[aria-current="page"],
.nav-current {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.hero { position: relative; padding: 28px 0 20px; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 12px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 22px;
  height: 2px;
  border-radius: 2px;
  background: var(--orange);
}

h1 {
  max-width: 14ch;
  margin: 0;
  font-size: clamp(34px, 9vw, 76px);
  font-weight: 730;
  letter-spacing: -0.075em;
  line-height: 0.98;
}

h1 .period,
.green { color: var(--green); }

.lede {
  max-width: 62ch;
  margin: 16px 0 0;
  color: #6e7b72;
  font-size: 16px;
  line-height: 1.65;
}

.hero .course-status { position: static; display: inline-flex; margin-top: 16px; }

.card-grid,
.level-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.test-card,
.part-card,
.level-card,
.note-card {
  position: relative;
  display: flex;
  min-height: 220px;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 254, 250, 0.92);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.test-card h2,
.part-card h2,
.level-card h2 {
  margin: 0;
  font-size: clamp(28px, 3vw, 40px);
  letter-spacing: -0.07em;
  line-height: 1;
}

.part-card h2,
.level-card h2 { font-size: clamp(22px, 2vw, 28px); }

.card-kicker,
.section-label {
  margin: 0 0 8px;
  color: #79877c;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card-title {
  margin: 8px 0 10px;
  color: #52645a;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.test-card p,
.part-card p,
.level-card .desc,
.note-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 18px;
  color: var(--green);
  font-size: 13px;
  font-weight: 750;
}

.section { margin-top: 36px; }

.section h2 {
  margin: 0 0 6px;
  font-size: clamp(26px, 3vw, 34px);
  letter-spacing: -0.06em;
}

.section .intro {
  max-width: 68ch;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
}

.kicker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.tag {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f8f2;
  color: #637168;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  color: #6f7b72;
  font-size: 14px;
  font-weight: 650;
}

.progress-row strong,
.level-percent { color: var(--green); }

.track {
  display: flex;
  height: 7px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5eae2;
}

.track .seg { display: block; height: 100%; width: 0; }
.track .learned { background: var(--green); }
.track .queued { background: var(--yellow); }
.track .fresh { background: #e7c4bc; }

.caption {
  margin: 6px 0 0;
  color: #7f8a81;
  font-size: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 8px 0 0;
  color: #7f8a81;
  font-size: 14px;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: 0;
}

.legend .learned { background: var(--green); }
.legend .queued { background: var(--yellow); }
.legend .fresh { background: #e7c4bc; }

.progress-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.9);
  color: #52645a;
  font-size: 13px;
  font-weight: 700;
}

.test-card > .progress-status,
.part-card > .progress-status {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 0;
  border: 0;
  background: transparent;
}

.progress-dot {
  width: 11px;
  height: 11px;
  flex: none;
  border: 2px solid rgba(36, 55, 45, 0.13);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.72);
  background: #d9534f;
}

.progress-status[data-progress-state="in-progress"] .progress-dot { background: #e3b12f; }
.progress-status[data-progress-state="complete"] .progress-dot { background: var(--green); }

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

.course-status .progress-label,
.part-card > .progress-status .progress-label,
.test-card > .progress-status .progress-label {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
}

.test-card > .progress-status .progress-label,
.part-card > .progress-status .progress-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 36px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: #829087;
  font-size: 14px;
  flex-direction: column;
}

.worksheet {
  display: grid;
  justify-items: start;
  gap: 8px;
  width: min(220px, 100%);
  margin: 28px 0 0;
}

.worksheet a {
  display: block;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  box-shadow: var(--shadow);
}

.worksheet figcaption {
  color: var(--muted);
  font-size: 13px;
}

.worksheet figcaption span {
  display: block;
  color: var(--green);
  font-weight: 700;
}

.follow-row { margin-top: 28px; }
.note-card { min-height: 0; }
.note-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--green);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}

.button:focus-visible,
.pill:focus-visible,
.back-button:focus-visible,
.reset-link:focus-visible,
.rating-button:focus-visible {
  outline: 3px solid rgba(38, 114, 77, 0.35);
  outline-offset: 3px;
}

.button.primary {
  background: var(--green);
  color: white;
  box-shadow: 0 6px 16px rgba(38, 114, 77, 0.16);
}

.button.secondary {
  border-color: #d7e0d4;
  background: rgba(255, 255, 255, 0.7);
}

.button:disabled { cursor: not-allowed; opacity: 0.45; transform: none; }

.reset-link,
.back-button {
  min-height: 44px;
  padding: 10px 0;
  border: 0;
  background: none;
  color: #859087;
  cursor: pointer;
  font-size: 15px;
  text-decoration: underline;
  text-decoration-color: #cdd5ca;
  text-underline-offset: 3px;
}

.back-button {
  text-decoration: none;
  color: #647267;
  font-weight: 670;
}

.back-button span { margin-right: 4px; color: var(--green); }

.quiz-intro,
.study,
.results {
  width: min(100%, 880px);
  margin: 0 auto;
  padding-top: 12px;
}

.quiz-intro h1 { max-width: none; }

.study-topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 4px;
}

.session-label {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
}

.card-counter {
  justify-self: start;
  color: #7a867c;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.learning-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 auto 8px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.8);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.learning-indicator[data-stage="early"] { color: #8a5a32; }
.learning-indicator[data-stage="mid"] { color: #6d5814; }

.study-heading { margin: 18px 0 12px; text-align: center; }
.study-heading p { margin: 0; color: #748076; }

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

.flashcard:has(.answer-face[hidden]) { grid-template-columns: minmax(0, 1fr); }

.face {
  min-height: 0;
  padding: 16px 16px 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 254, 250, 0.9);
}

.answer-face { border-color: #d4e1cf; background: #f8fbf4; }

.face-heading {
  padding-bottom: 10px;
  border-bottom: 1px solid #e9ece5;
  color: #6e7a71;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.card-copy {
  display: grid;
  min-height: 0;
  align-content: center;
  justify-items: stretch;
  gap: 12px;
  padding-top: 14px;
  text-align: center;
}

.clip {
  display: grid;
  gap: 10px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.play-clip {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
}

audio {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
}

.answer-label {
  margin: 0;
  color: #263d30;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1.2;
}

.card-copy .audio-missing {
  width: 100%;
}

.session-status {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: #748076;
  font-size: 14px;
  text-align: center;
}

.session-status.error { color: #a9543a; }

.session-controls {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: grid;
  place-items: stretch;
  width: 100%;
  margin-top: 8px;
  padding: 12px 0 calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(244, 242, 235, 0), var(--paper) 18px);
}

.session-controls .button { width: 100%; min-height: 52px; font-size: 17px; }

.rating-panel { width: 100%; text-align: center; }
.rating-prompt { margin: 0 0 10px; color: #78847a; font-size: 15px; }

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

.rating-button {
  width: 100%;
  min-height: 52px;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 17px;
  font-weight: 750;
}

.rating-button[data-rating="again"] {
  border: 1px solid #dc9887;
  background: #f4d4ca;
  color: #783e33;
}

.rating-button[data-rating="hard"] {
  border: 1px solid #d8b944;
  background: #f4e5a0;
  color: #584819;
}

.rating-button[data-rating="good"] {
  border: 1px solid #a9c69b;
  background: #d8e9d1;
  color: #2e6340;
}

.storage-hint {
  margin: 14px 0 0;
  color: #95a096;
  font-size: 13px;
  text-align: center;
}

.results {
  display: flex;
  min-height: 60vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.result-symbol {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 48px;
  margin-bottom: 12px;
}

.result-symbol i {
  display: block;
  width: 7px;
  border-radius: 4px;
  background: #9bbd76;
}

.result-symbol i:nth-child(1) { height: 18px; }
.result-symbol i:nth-child(2) { height: 36px; background: var(--orange); }
.result-symbol i:nth-child(3) { height: 26px; background: var(--green); }

.result-score {
  margin: 8px 0;
  color: var(--green);
  font-size: 22px;
  font-weight: 730;
  letter-spacing: -0.04em;
}

.result-detail {
  max-width: 46ch;
  margin: 0;
  color: #768278;
}

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: min(100%, 420px);
  margin-top: 22px;
}

.result-actions .button { width: 100%; }

.reset-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 18px 55px rgba(32, 56, 42, 0.2);
}

.reset-dialog::backdrop {
  background: rgba(36, 55, 45, 0.38);
}

.dialog-content { padding: 22px; }
.dialog-content h2 { margin: 0; font-size: 22px; letter-spacing: -0.04em; }
.dialog-content p { margin: 10px 0 0; color: #6f7b72; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: stretch; gap: 8px; margin-top: 18px; }

.dialog-button {
  flex: 1 1 140px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
}

.dialog-button.confirm {
  border-color: transparent;
  background: var(--green);
  color: white;
}

.loading-note,
.error-panel {
  max-width: 62ch;
  margin: 28px 0;
  color: var(--muted);
}

.error-panel {
  padding: 16px 18px;
  border: 1px solid #e7c4bc;
  border-radius: 14px;
  background: #fff8f5;
  color: #783e33;
}

.actions { display: flex; flex-direction: column; align-items: stretch; gap: 10px; margin-top: 18px; }
.actions .button { width: 100%; }
.study .actions { justify-content: center; }
.level-card .progress-row { margin-top: auto; padding-top: 16px; }
.quiz-intro .button.primary { min-height: 52px; font-size: 17px; }

@media (min-width: 720px) {
  .shell { padding-top: 28px; }
  .topbar { align-items: center; flex-direction: row; }
  .nav-pills { flex-wrap: wrap; justify-content: flex-end; width: auto; overflow: visible; }
  .hero { padding: 56px 0 28px; }
  h1 { max-width: 18ch; }
  .card-grid,
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-footer { flex-direction: row; }
  .quiz-intro,
  .study,
  .results { padding-top: 28px; }
  .study-topline { grid-template-columns: 1fr auto 1fr; }
  .session-label,
  .card-counter { text-align: center; }
  .card-counter { justify-self: end; text-align: right; }
  .flashcard:not(:has(.answer-face[hidden])) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .face { min-height: 220px; }
  .rating-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .actions { flex-direction: row; align-items: center; }
  .actions .button { width: auto; }
  .result-actions { flex-direction: row; width: auto; }
  .result-actions .button { width: auto; }
  .session-controls { place-items: center; background: none; }
  .session-controls .button { width: auto; min-width: 220px; min-height: 48px; font-size: 16px; }
  .rating-button { min-height: 48px; font-size: 15px; }
  .rating-panel { width: min(100%, 560px); }
}

@media (min-width: 1040px) {
  .hero { padding-right: 170px; }
  .hero .course-status { position: absolute; right: max(20px, env(safe-area-inset-right)); top: 56px; margin-top: 0; }
  .card-grid,
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (hover: hover) and (pointer: fine) {
  .test-card:hover,
  .part-card:hover,
  .level-card:hover {
    transform: translateY(-3px);
    border-color: #afc8aa;
  }
  .pill:hover { border-color: #afc8aa; background: #f4f8ef; }
  .button:hover,
  .rating-button:hover { transform: translateY(-1px); }
  .button.primary:hover { background: var(--green-dark); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
  .test-card:hover,
  .part-card:hover,
  .level-card:hover,
  .button:hover,
  .rating-button:hover { transform: none; }
}
