/* ── Variables ───────────────────────────────────────────────── */
:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #21262d;
  --border:   #30363d;
  --text:     #e6edf3;
  --dim:      #7d8590;
  --gold:     #d4a853;
  --gold-hi:  #f0c87a;
  --green:    #3fb950;
  --red:      #c9726a;
  --r:        12px;
  --r-lg:     20px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

#app-root { width: 100%; max-width: 480px; }

/* ── Screens ─────────────────────────────────────────────────── */
.screen {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

.hidden { display: none !important; }

/* ── Exam countdown banner ──────────────────────────────────── */
.exam-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 20px;
  margin: max(env(safe-area-inset-top, 0px), 16px) 0 4px;
  text-align: center;
}
.exam-banner-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.exam-countdown {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}
.exam-composers {
  font-size: 0.78rem;
  color: var(--dim);
  line-height: 1.8;
}

/* ── Good luck banner ───────────────────────────────────────── */
.good-luck-banner {
  background: linear-gradient(135deg, #1a1f2e, #21262d);
  border: 1px solid var(--gold);
  border-radius: var(--r-lg);
  padding: 16px 20px;
  margin: max(env(safe-area-inset-top, 0px), 16px) 0 4px;
  text-align: center;
}
.good-luck-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold-hi);
  margin-bottom: 10px;
}
.good-luck-list {
  font-size: 0.78rem;
  color: var(--dim);
  line-height: 1.8;
  letter-spacing: 0.02em;
}

/* ── HOME ────────────────────────────────────────────────────── */
header {
  text-align: center;
  padding: max(env(safe-area-inset-top, 0px), 32px) 0 28px;
}

.logo { font-size: 3rem; margin-bottom: 8px; }

header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--gold-hi);
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--dim);
  font-size: 0.9rem;
  margin-top: 6px;
}
.credit {
  color: var(--dim);
  font-size: 0.8rem;
  margin-top: 8px;
  letter-spacing: 0.03em;
}
.credit-logo {
  height: 14px;
  width: auto;
  vertical-align: -2px;
  margin-right: 2px;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 4px 20px;
  margin-bottom: 16px;
}

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  gap: 12px;
}
.setting-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.setting-row > span { font-size: 0.95rem; }

.mode-tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.mode-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.mode-btn.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #000;
  font-weight: 600;
}

/* Toggle */
.toggle {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.knob {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 28px;
  transition: background 0.2s, border-color 0.2s;
}
.knob::before {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  left: 2px; top: 2px;
  background: var(--dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
input:checked + .knob { background: var(--gold); border-color: var(--gold); }
input:checked + .knob::before { transform: translateX(22px); background: #000; }

.list-dropdown {
  position: relative;
  margin-bottom: 12px;
}
.list-dropdown-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.list-dropdown-btn:hover,
.list-dropdown[data-open] .list-dropdown-btn {
  border-color: var(--gold);
}
.list-dropdown-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-dropdown-arrow {
  color: var(--gold);
  font-size: 0.7rem;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.list-dropdown[data-open] .list-dropdown-arrow { transform: rotate(180deg); }

.list-dropdown-menu {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  list-style: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.list-dropdown-item {
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.list-dropdown-item:not(:last-child) { border-bottom: 1px solid var(--border); }
.list-dropdown-item:hover { background: var(--surface); color: var(--text); }
.list-dropdown-item.active {
  color: var(--gold-hi);
  font-weight: 600;
}

.info-text {
  text-align: center;
  font-size: 0.82rem;
  color: var(--dim);
  margin-top: 14px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--r);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 15px 20px;
  width: 100%;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; }

@keyframes btn-flash {
  0%   { box-shadow: 0 0 0 0   rgba(212,168,83,0.9); }
  40%  { box-shadow: 0 0 0 2px rgba(212,168,83,0.5); }
  100% { box-shadow: 0 0 0 3px rgba(212,168,83,0);   }
}
.btn.btn-flash { animation: btn-flash 0.4s ease-out forwards; }

.btn-primary { background: var(--gold); color: #000; }
.btn-primary:not(:disabled):active { background: var(--gold-hi); }
.btn-main { padding: 30px 20px; font-size: 1.05rem; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: none;
  color: var(--dim);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  padding: 10px 16px;
  width: auto;
  border-radius: 8px;
}

.btn-large {
  padding: 18px 20px;
  font-size: 1.05rem;
  border-radius: var(--r-lg);
  margin-top: 8px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  line-height: 1;
  font-family: inherit;
}

/* ── Piece list ──────────────────────────────────────────────── */
.piece-list {
  width: 100%;
  margin-top: 16px;
  overflow-y: auto;
  max-height: 80vh;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  margin-bottom: 24px;
}

.piece-list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.piece-list-master-label {
  font-size: 0.82rem;
  color: var(--dim);
  cursor: pointer;
}

.piece-checkbox {
  width: 18px; height: 18px;
  flex-shrink: 0;
  accent-color: var(--gold);
  cursor: pointer;
}

.piece-item {
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.piece-item:last-child { border-bottom: none; }

.piece-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px 6px;
}
.piece-num {
  font-size: 0.75rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  padding-top: 2px;
  flex-shrink: 0;
}
.piece-info    { display: flex; flex-direction: column; gap: 2px; }
.piece-composer { font-size: 0.82rem; color: var(--gold); font-weight: 600; }
.piece-title    { font-size: 0.9rem;  color: var(--text); }

.piece-info-clickable {
  cursor: pointer;
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 6px;
  transition: background 0.1s;
}
.piece-info-clickable:active { background: var(--surface2); }
.piece-subtitle { display: block; font-size: 0.95rem; color: var(--text); font-style: italic; margin-top: 6px; }

.piece-performers { padding: 0 16px 8px 42px; display: flex; flex-direction: column; gap: 2px; }

.performer-row {
  font-size: 0.85rem;
  color: var(--dim);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.performer-row::after { content: ' ▶'; font-size: 0.7rem; opacity: 0.5; }
.performer-row:active { background: var(--surface2); color: var(--text); }

.performer-group  { margin-bottom: 4px; }
.performer-name   { font-size: 0.82rem; color: var(--dim); padding: 3px 0; }

.movement-row {
  font-size: 0.83rem;
  color: var(--text);
  padding: 4px 8px 4px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.movement-row::after { content: ' ▶'; font-size: 0.7rem; color: var(--dim); }
.movement-row:active { background: var(--surface2); }

.ans-movement  { font-size: 0.95rem; color: var(--text); margin-bottom: 8px; font-style: italic; }
.ans-subtitle  { display: block; font-size: 0.95rem; color: var(--text); font-style: italic; margin-top: 8px; }

/* ── QUIZ ────────────────────────────────────────────────────── */
.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: max(env(safe-area-inset-top, 0px), 16px);
  padding-bottom: 8px;
}
.counter { font-size: 0.88rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.spacer { width: 36px; }

.quiz-mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 0;
}

/* Playing area */
.playing-area {
  text-align: center;
  padding: 48px 0;
}
.note-icon {
  font-size: 5rem;
  line-height: 1;
  margin-bottom: 20px;
  display: inline-block;
}
.note-icon.pulsing { animation: pulse 1.8s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.5; transform: scale(0.93); }
}

.status-msg { color: var(--dim); font-size: 0.9rem; text-align: center; margin-top: 12px; }

/* Answer card */
.answer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px 24px;
  text-align: center;
}
.ans-composer {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold-hi);
  margin-bottom: 10px;
}
.ans-title {
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 12px;
}
.ans-meta { font-size: 0.82rem; color: var(--dim); margin-bottom: 6px; }
.ans-performer { font-size: 0.82rem; color: var(--dim); font-style: italic; }

/* Controls */
.quiz-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-bottom: env(safe-area-inset-bottom, 48px);
  margin-bottom: 24px;
}
.browse-nav { display: flex; gap: 10px; width: 100%; }
.browse-nav .btn { flex: 1; }
.controls { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.seek-row  { display: flex; gap: 6px; width: 100%; }
.seek-row .btn { flex: 1; width: auto; padding: 10px 6px; font-size: 0.82rem; }

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding-top: 4px;
}
.time-label {
  font-size: 0.75rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#seek-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
#seek-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
}
#seek-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: none;
  cursor: pointer;
}

/* ── TEST MODE ───────────────────────────────────────────────── */
.num-input {
  width: 80px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  text-align: center;
  cursor: ns-resize;    /* scroll / swipe to adjust */
  touch-action: none;
}
.select-input {
  max-width: 58%;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
}
#test-options .setting-row:first-child { border-top: 1px solid var(--border); }

/* Visual + interaction unity across the three test-option controls: all
   three carry the same "scroll/swipe to adjust" affordance and gesture. */
.scrub-wrap { position: relative; display: inline-flex; align-items: center; max-width: 58%; }
.scrub-wrap .scrub-control { padding-right: 26px; }
select.scrub-control {
  width: 100%;
  max-width: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: ns-resize;
  touch-action: none;
}
.scrub-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.15rem;
  line-height: 1;
  color: var(--gold);
  opacity: 0.8;
  pointer-events: none;
}

.test-answer-row { width: 100%; }
.test-answer-row select {
  width: 100%;
  max-width: 100%;
  padding: 14px 12px;
  font-size: 0.9rem;
  border-radius: var(--r);
}

/* ── TEST RESULTS ────────────────────────────────────────────── */
.results-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: max(env(safe-area-inset-top, 0px), 32px);
  padding-bottom: 32px;
}
.results-body h2 { text-align: center; font-size: 1.6rem; }
.test-score {
  text-align: center;
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
}
.review-hint { font-size: 0.78rem; color: var(--dim); margin-bottom: 4px; }

.test-mistakes {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow-y: auto;
  max-height: 50vh;
}
.mistake-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.mistake-row:last-child { border-bottom: none; }
.mistake-row:active     { background: var(--surface2); }
.mistake-mark    { font-weight: 600; }
.mistake-mark-ok  { color: var(--green); }
.mistake-mark-bad { color: var(--red); }
.mistake-correct { font-size: 0.88rem; color: var(--text); }
.mistake-yours   { color: var(--dim); font-size: 0.8rem; margin-top: 2px; }
.mistake-yours-clickable { cursor: pointer; }
.mistake-yours-clickable:active { color: var(--text); }
.all-correct     { text-align: center; color: var(--green); font-size: 0.95rem; padding: 12px 14px; }

/* ── COMPLETE ────────────────────────────────────────────────── */
.complete-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 40px 0;
}
.trophy { font-size: 5rem; }
.complete-body h2 { font-size: 1.8rem; font-weight: 700; }

.legal-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--dim);
  margin-top: 24px;
  padding-bottom: 16px;
}
.legal-footer a { color: var(--dim); text-decoration: underline; }
