:root {
  --bg: #111;
  --fg: #eee;
  --accent: #4caf50;
  --key-white: #fafafa;
  --key-black: #222;
  --key-selected: #4caf50;
  --line: #ccc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, sans-serif;
  display: flex;
  justify-content: center;
  /* Disable double-tap-to-zoom (and the tap delay) while keeping pinch-zoom. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: 100%;
  max-width: 760px;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.top h1 { margin: 0; font-size: 1.8rem; }
#feedback { min-height: 1.4em; margin: 6px 0 0; }
#feedback.correct { color: var(--accent); font-weight: 600; }

.staff-wrap { background: #1b1b1b; border-radius: 8px; padding: 12px; }
.staff { width: 100%; max-width: 240px; height: auto; display: block; margin: 0 auto; }
.staff-line { stroke: var(--line); stroke-width: 1; }
.notehead { fill: var(--fg); }
.accidental { fill: var(--fg); font-size: 14px; }

.play-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 2.8em;
}
.recent-levels { display: flex; align-items: center; gap: 10px; }
.recent-levels:not(:empty) { padding-right: 12px; border-right: 1px solid #333; cursor: pointer; }
.levels-label { font-size: 0.95rem; color: #777; white-space: nowrap; cursor: pointer; user-select: none; }
.levels-label:hover { color: #aaa; }
.levels-label::after { content: ' ▸'; }
.recent-levels:hover .levels-label::after,
.recent-levels.pinned .levels-label::after { content: ' ▾'; }
/* Chips are hidden until the region is hovered or the trail is pinned open. */
.level-chip { font-size: 0.95rem; color: #9ad; white-space: nowrap; display: none; }
.recent-levels:hover .level-chip,
.recent-levels.pinned .level-chip { display: inline; }

/* --- Progression mode: the sequence of chords with the current step marked. --- */
.progression {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0;
}
.progression .step {
  min-width: 2.4em;
  padding: 4px 8px;
  border: 1px solid #444;
  border-radius: 6px;
  font-size: 1.1rem;
  text-align: center;
  color: var(--fg);
}
.progression .step.done { opacity: 0.4; }
.progression .step.current { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.progression .step.upcoming { opacity: 0.75; }

.current-chord {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #9ad;
  font-variant-numeric: tabular-nums;
}
.current-chord .note {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.current-chord .note-name { font-size: 1.2rem; }
.current-chord .note-degree { font-size: 0.8rem; color: #6a8; }
.current-chord .chord-name { font-size: 1.05rem; }

.controls { display: flex; align-items: center; gap: 16px; }
button {
  background: #2a2a2a; color: var(--fg); border: 1px solid #444;
  border-radius: 6px; padding: 8px 12px; cursor: pointer; font-size: 0.95rem;
  touch-action: manipulation;
}
button:hover { border-color: var(--accent); }

.piano {
  position: relative;
  display: flex;
  height: 170px;
  user-select: none;
}
.key {
  border: 1px solid #000;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}
.key.white {
  flex: 1 1 0;
  background: var(--key-white);
  height: 100%;
  border-radius: 0 0 4px 4px;
  z-index: 1;
}
.key.black {
  flex: 0 0 auto;
  width: 4%;
  height: 62%;
  margin: 0 -2%;
  background: var(--key-black);
  border-radius: 0 0 3px 3px;
  z-index: 2;
}
.key.white.selected { background: var(--key-selected); }
.key.black.selected { background: #2e7d32; }
/* Transient highlight while the mouse button is held over a key. */
.key.white.pressed { background: #bcd6ff; }
.key.black.pressed { background: #34507a; }

/* Outside the octave window: greyed out and not interactive. */
.key.disabled { pointer-events: none; cursor: default; }
.key.white.disabled { background: #555; }
.key.black.disabled { background: #555; border: 2px solid #000; }

.hint-btn { border-color: #555; color: #aaa; }
.hint-btn:hover { border-color: #aaa; color: var(--fg); }

.reveal-btn { border-color: #b03030; color: #e06666; }
.reveal-btn:hover { border-color: #e06666; color: #ff8a8a; }
.reveal-btn.continue { border-color: #c9a227; color: #e6c34d; }
.reveal-btn.continue:hover { border-color: #e6c34d; color: #ffd83a; }

.sync-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.sync-code { font-family: monospace; font-size: 1.3rem; letter-spacing: 2px; color: var(--accent); }
.sync-input { width: 6ch; text-transform: uppercase; letter-spacing: 2px;
  background: #1b1b1b; color: var(--fg); border: 1px solid #444; border-radius: 6px;
  padding: 8px; font-family: monospace; font-size: 1.1rem; }
.sync-status { display: block; margin-top: 6px; color: #9ad; font-size: 0.9rem; }

.settings-panel { border-top: 1px solid #333; padding-top: 12px; }
.settings-panel summary { cursor: pointer; margin-bottom: 8px; }
fieldset { border: 1px solid #333; border-radius: 6px; margin: 8px 0; padding: 8px 12px; }
legend { padding: 0 6px; }
.setting-toggle { margin: 8px 0 0; }
#settings select {
  background: #2a2a2a; color: var(--fg); border: 1px solid #444;
  border-radius: 6px; padding: 8px 10px; font-size: 0.95rem;
}
button.test-sound { margin-left: 8px; }
.settings-panel input[type="checkbox"] { margin-right: 5px; cursor: pointer; vertical-align: middle; }
.settings-panel label { margin-right: 16px; cursor: pointer; vertical-align: middle; }

/* --- Top bar / page navigation --- */
.topbar { display: flex; align-items: center; justify-content: space-between; }
.page-title { font-size: 1rem; font-weight: 600; color: #9ad; }
.nav-link {
  display: inline-block; text-decoration: none; color: var(--fg);
  background: #2a2a2a; border: 1px solid #444; border-radius: 6px;
  padding: 8px 12px; font-size: 0.95rem;
}
.nav-link:hover { border-color: var(--accent); }

/* --- Progress page --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-card { background: #1b1b1b; border-radius: 8px; padding: 12px 16px; text-align: center; }
.stat-value { font-size: 1.6rem; font-weight: 600; color: var(--accent); }
.stat-label { font-size: 0.85rem; color: #9ad; margin-top: 2px; }
.chart-section { display: flex; flex-direction: column; gap: 6px; }
.chart-section h2 { font-size: 1.02rem; margin: 0; font-weight: 600; }
.chart-wrap { background: #1b1b1b; border-radius: 8px; padding: 12px; }
.chart { width: 100%; max-width: 440px; height: auto; display: block; margin: 0 auto; }
.chart-empty { margin: 0; color: #888; font-size: 0.9rem; }
.bar { fill: var(--accent); }
.line { stroke: var(--accent); stroke-width: 2; }
.axis { stroke: #444; stroke-width: 1; }
.chart-label { fill: #9ad; font-size: 9px; }
.chart-value { fill: #cde; font-size: 8px; }

/* --- Mobile: fill the viewport and let the piano take the leftover height so
   it stays usable without scrolling. Triggers on narrow (portrait) or short
   (landscape) screens; desktop is unaffected. --- */
@media (max-width: 768px), (max-height: 560px) {
  .app {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 14px 10px;
    gap: 12px;
  }
  .top h1 { font-size: 1.35rem; }
  .controls { flex-wrap: wrap; }
  .piano {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: 340px;
  }
  /* Bigger touch targets for the bottom controls. */
  button { padding: 10px 14px; }
}

/* --- Short screens (landscape phones): compress the vertical chrome further so
   the staff, readout and piano all fit at once. --- */
@media (max-height: 480px) {
  .app { padding: 6px 12px; gap: 6px; }
  .top h1 { font-size: 1rem; }
  #feedback { min-height: 0.9em; margin: 1px 0 0; font-size: 0.8rem; }
  .staff-wrap { padding: 4px; }
  .staff { max-height: 64px; }
  .current-chord { min-height: 1.8em; gap: 8px; }
  .current-chord .note-name { font-size: 1rem; }
  .current-chord .note-degree { font-size: 0.7rem; }
  .controls { gap: 10px; }
  .piano { min-height: 70px; max-height: none; }
}

/* --- Accessibility --- */
.nav-links { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --- Feedback --- */
.feedback { display: flex; flex-direction: column; gap: 10px; }
.feedback h2 { font-size: 1.1rem; margin: 0; color: #9ad; }
.feedback-hint { margin: 0; color: #888; font-size: 0.9rem; }
.feedback form { display: flex; flex-direction: column; gap: 10px; }
.feedback input,
.feedback textarea {
  width: 100%; background: #1b1b1b; color: var(--fg); border: 1px solid #444;
  border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 0.95rem;
}
.feedback textarea { resize: vertical; }
.feedback input:focus,
.feedback textarea:focus { outline: none; border-color: var(--accent); }
.feedback button { align-self: flex-start; }
#feedback-status { min-height: 1.2em; margin: 0; }
#feedback-status.correct { color: var(--accent); font-weight: 600; }
#feedback-status.error { color: #e57373; }

/* Comments wall */
.comments-section { display: flex; flex-direction: column; gap: 10px; }
.comments-section h2 { font-size: 1.1rem; margin: 0; color: #9ad; }
.comments { display: flex; flex-direction: column; gap: 10px; }
.comments-empty { color: #888; font-size: 0.9rem; margin: 0; }
.comment { background: #1b1b1b; border: 1px solid #333; border-radius: 8px; padding: 10px 14px; }
.comment-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.comment-name { font-weight: 600; color: #9ad; }
.comment-date { color: #888; font-size: 0.8rem; white-space: nowrap; }
.comment-body { margin: 6px 0 10px; white-space: pre-wrap; word-break: break-word; }
.comment-like {
  padding: 4px 10px; font-size: 0.9rem; background: #2a2a2a; color: #e57373;
  border: 1px solid #444; border-radius: 6px; cursor: pointer;
}
.comment-like:hover { border-color: var(--accent); }
.comment-like.liked { color: #e57373; border-color: #e57373; cursor: default; }

/* Statement page */
.statement { line-height: 1.6; }
.statement h2 { font-size: 1.1rem; margin: 20px 0 6px; color: #9ad; }
.statement p { margin: 6px 0; }
.statement ul { margin: 6px 0; padding-left: 20px; }
.statement li { margin: 4px 0; }
.statement .contact { list-style: none; padding-left: 0; }
.statement-updated { color: #888; font-size: 0.9rem; margin-top: 20px; }

/* Accessibility menu widget: hidden by default with only a muted trigger label
   showing. The panel opens and closes only when the trigger is clicked (the
   .pinned class). */
.a11y-widget { position: fixed; left: 16px; bottom: 16px; z-index: 1000; }
.a11y-trigger {
  background: #2a2a2a; color: #9ad; border: 1px solid #444; border-radius: 6px;
  padding: 6px 10px; font-size: 0.9rem; cursor: pointer; user-select: none;
}
.a11y-trigger:hover { border-color: var(--accent); }
.a11y-trigger::after { content: ' ▸'; }
.a11y-widget.pinned .a11y-trigger::after { content: ' ▾'; }
/* Icon-only mode: collapse the trigger to just the ♿ glyph. */
.a11y-compact .a11y-trigger-label { display: none; }
.a11y-compact .a11y-trigger::after { content: none; }
.a11y-compact .a11y-trigger { padding: 6px 9px; font-size: 1.1rem; }
.a11y-panel {
  position: absolute; left: 0; bottom: 100%; margin-bottom: 8px; width: 240px;
  background: #1b1b1b; border: 1px solid #444; border-radius: 8px;
  padding: 12px 14px; display: none; flex-direction: column; gap: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
.a11y-widget.pinned .a11y-panel { display: flex; }
.a11y-panel h2 { margin: 0; font-size: 1.05rem; color: #9ad; }
.a11y-row { display: flex; align-items: center; gap: 8px; }
.a11y-row label { cursor: pointer; }
.a11y-row .a11y-value { margin-left: auto; color: #9ad; font-variant-numeric: tabular-nums; }
.a11y-row button { padding: 4px 10px; }
.a11y-reset { align-self: flex-start; }
.a11y-statement-link { color: #9ad; font-size: 0.9rem; }
/* Close button (× in the panel corner) and the restore handle shown once hidden. */
.a11y-close {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px;
  padding: 0; line-height: 1; font-size: 1.1rem; background: transparent;
  color: #9ad; border: 1px solid #444; border-radius: 6px; cursor: pointer;
}
.a11y-close:hover { border-color: var(--accent); }
.a11y-restore {
  display: none; background: #2a2a2a; color: #9ad; border: 1px solid #444;
  border-radius: 6px; padding: 4px 8px; font-size: 1rem; cursor: pointer; opacity: 0.6;
}
.a11y-restore:hover { opacity: 1; border-color: var(--accent); }
.a11y-widget.a11y-hidden .a11y-trigger,
.a11y-widget.a11y-hidden .a11y-panel { display: none; }
.a11y-widget.a11y-hidden .a11y-restore { display: block; }

/* High-contrast mode: black background, white text, yellow accents, and solid
   borders on the surfaces that are otherwise distinguished only by shade. */
.a11y-contrast {
  --bg: #000; --fg: #fff; --accent: #ff0; --line: #fff;
  --key-white: #fff; --key-black: #000; --key-selected: #ff0;
}
.a11y-contrast body { background: #000; color: #fff; }
.a11y-contrast .stat-card,
.a11y-contrast .chart-wrap,
.a11y-contrast .staff-wrap,
.a11y-contrast .a11y-panel,
.a11y-contrast fieldset,
.a11y-contrast .nav-link,
.a11y-contrast button,
.a11y-contrast #settings select,
.a11y-contrast .a11y-trigger { background: #000; color: #fff; border-color: #fff; }
.a11y-contrast .page-title,
.a11y-contrast .stat-label,
.a11y-contrast .chart-label,
.a11y-contrast .statement h2,
.a11y-contrast .a11y-panel h2 { color: #fff; }
.a11y-contrast .key.black { border: 1px solid #fff; }

.a11y-underline a { text-decoration: underline; }

.a11y-no-motion *,
.a11y-no-motion *::before,
.a11y-no-motion *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
}
