:root {
  --ink: #241e16;
  --paper: #f6f1e4;
  --brass: #e2c27a;
  --brass-deep: #c6a15b;
  --desk: #14110e;
  --cream: #f4efe6;
  --muted: #b5aa9a;
  --line: rgba(243, 234, 220, 0.16);
  --good: #1d7a43;
  --bad: #a33b32;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(900px 420px at 50% -80px, rgba(226, 194, 122, 0.16), transparent 60%),
    var(--desk);
  user-select: none;
}

input, .gradebook, .save-state { user-select: text; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

::selection { background: var(--brass); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 22px 36px;
  min-height: 100vh;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--brass);
}

.logo { width: 28px; height: 28px; flex: none; }

h1, h2 {
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

h1 { font-size: 1.7rem; color: var(--cream); }
h2 { font-size: 2rem; }

.save-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.lead {
  margin: 0 0 16px;
  max-width: 62ch;
  color: #ddd4c6;
  line-height: 1.45;
}

.banner {
  background: #5c2a24;
  color: #f8e8e2;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin: 0 0 16px;
}

.stage-home { height: min(300px, 38vh); min-height: 210px; }
.stage-play { height: min(520px, calc(100vh - 290px)); min-height: 280px; }

.paper {
  position: relative;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0) 90px),
    var(--paper);
  border-radius: 18px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55) inset,
    0 22px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.paper svg {
  display: block;
  width: 100%;
  height: 100%;
}

.paper.flash-good { box-shadow: 0 0 0 3px var(--good), 0 22px 50px rgba(0, 0, 0, 0.35); }
.paper.flash-bad { box-shadow: 0 0 0 3px var(--bad), 0 22px 50px rgba(0, 0, 0, 0.35); }

.setup {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 22px;
  margin: 22px 0 8px;
}

.field-wide { grid-column: 1 / -1; }
.field-wide .hint { min-height: 0; }

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
  min-height: 2.5em;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper button,
.choice-btn,
.btn,
.text-btn,
.begin,
.key {
  border: 1px solid var(--line);
  background: transparent;
}

.stepper button {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--cream);
  font-size: 1.2rem;
}

.stepper button:hover,
.choice-btn:hover,
.btn:hover,
.key:hover { background: rgba(243, 234, 220, 0.08); }

#target-input {
  width: 4.5ch;
  padding: 0 0 2px;
  border: none;
  border-bottom: 2px solid var(--brass-deep);
  background: transparent;
  text-align: center;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

#target-input::-webkit-outer-spin-button,
#target-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#target-input { -moz-appearance: textfield; appearance: textfield; }

.choice { display: flex; flex-wrap: wrap; gap: 8px; }

.choice-btn, .btn {
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
}

.choice-btn[aria-pressed="true"] {
  background: var(--cream);
  color: var(--ink);
  border-color: var(--cream);
}

.begin {
  background: var(--brass);
  color: var(--ink);
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.5rem;
  font-size: 1.2rem;
  font-weight: 680;
}

.begin:hover { background: #f0d7a0; }
.begin:disabled { opacity: 0.7; cursor: wait; }

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

kbd {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0 0.35em;
  border: 1px solid currentColor;
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.72em;
  line-height: 1.4;
  opacity: 0.8;
}

.timer-block { text-align: center; margin-bottom: 8px; }

.timer-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.72rem;
  color: var(--muted);
}

.timer-readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.12em;
  margin: 0;
  font-size: clamp(4.4rem, 11vw, 7.4rem);
  font-weight: 640;
  letter-spacing: -0.045em;
  line-height: 0.86;
  color: #f3e2b0;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.timer-readout.mid { color: #f0b429; }
.timer-readout.slow { color: #e07a5f; }

.timer-unit {
  font-size: 0.28em;
  letter-spacing: 0;
  color: var(--brass-deep);
}

.timer-sub {
  margin: 6px 0 0;
  color: #ddd4c6;
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 4px;
  margin: 12px 0 14px;
  background: rgba(243, 234, 220, 0.12);
  border-radius: 99px;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brass);
}

.feedback {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 34%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.mark-wrap { text-align: center; opacity: 0; }

.mark-svg { width: min(190px, 28vh); height: auto; display: block; margin: 0 auto; }

.mark-svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 12;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.feedback.good.show .mark-wrap { animation: tick-pop 0.72s ease forwards; }
.feedback.bad.show .mark-wrap { animation: cross-pop 0.5s ease forwards; }

@keyframes tick-pop {
  0% { opacity: 0; transform: rotate(-8deg) scale(0.55); }
  16% { opacity: 1; transform: rotate(-8deg) scale(1.06); }
  28% { opacity: 1; transform: rotate(-8deg) scale(1); }
  74% { opacity: 1; transform: rotate(-8deg) scale(1); }
  100% { opacity: 0; transform: rotate(-8deg) scale(1); }
}

@keyframes cross-pop {
  0% { opacity: 0; transform: rotate(7deg) scale(0.55); }
  20% { opacity: 1; transform: rotate(7deg) scale(1); }
  70% { opacity: 1; transform: rotate(7deg) scale(1); }
  100% { opacity: 0; transform: rotate(7deg) scale(1); }
}

#mark-time, #mark-name { margin: 0; font-weight: 680; }
#mark-time { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
#mark-name {
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.45rem;
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 18px;
  align-items: center;
  margin-top: 14px;
}

.keystrip, .hearing { grid-column: 1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.key {
  min-width: 52px;
  height: 52px;
  border-radius: 12px;
  font-size: 1.15rem;
  font-weight: 680;
}

.key.hit { background: var(--good); border-color: var(--good); color: white; }
.key.miss { background: var(--bad); border-color: var(--bad); color: white; }
.key[aria-pressed="true"] { background: var(--brass); color: var(--ink); border-color: var(--brass); }

.hearing { color: var(--cream); }
.hearing p { margin: 0; min-width: 9rem; font-variant-numeric: tabular-nums; }

.level {
  width: 92px;
  height: 8px;
  border-radius: 99px;
  background: rgba(243, 234, 220, 0.12);
  overflow: hidden;
}

.level > span {
  display: block;
  height: 100%;
  width: calc(var(--rms, 0) * 100%);
  background: var(--brass);
}

.text-btn {
  border: none;
  color: var(--muted);
  padding: 0.4rem 0.2rem;
  background: transparent;
}

.text-btn:hover { color: var(--cream); }
.text-btn.danger:hover { color: #f0b2ab; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 8px 0 6px;
}

.stat-grid dt {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-grid dd {
  margin: 0.15rem 0 0;
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-variant-numeric: tabular-nums;
}

.scores-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.session-stats {
  width: 100%;
  margin: 0 0 18px;
  border-collapse: separate;
  border-spacing: 0;
  background: #2a241c;
  border: 1px solid rgba(243, 234, 220, 0.14);
  border-radius: 14px;
  overflow: hidden;
}

.session-stats th,
.session-stats td {
  width: 33.33%;
  text-align: left;
  font-variant-numeric: tabular-nums;
  padding: 0 16px;
}

.session-stats th {
  padding-top: 12px;
  padding-bottom: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.session-stats td {
  padding-top: 2px;
  padding-bottom: 14px;
  color: var(--cream);
  font-size: 1.7rem;
  font-weight: 600;
}

#screen-scores .choice { margin-bottom: 8px; }
#board-summary { min-height: 0; margin-bottom: 12px; }

.gradebook {
  max-height: min(560px, calc(100vh - 300px));
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.gradebook table { width: 100%; border-collapse: collapse; min-width: 640px; }

.gradebook th, .gradebook td {
  padding: 0.62rem 0.8rem;
  border-bottom: 1px solid #e4d9c4;
  text-align: left;
}

.gradebook th {
  position: sticky;
  top: 0;
  background: #efe6d4;
  z-index: 1;
}

.gradebook th button {
  border: none;
  background: transparent;
  color: #6d6458;
  padding: 0;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
}

.gradebook th button:hover { color: var(--ink); }

.gradebook td.num, .gradebook th.num { text-align: right; }
.gradebook th:nth-child(n + 3), .gradebook td:nth-child(n + 3) { text-align: right; font-variant-numeric: tabular-nums; }
.gradebook th:nth-child(n + 3) button { width: 100%; text-align: right; }

.note-name {
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.15rem;
}

.clef-name { text-transform: capitalize; }

.rate-good { color: #1c7a42; font-weight: 700; }
.rate-ok { color: #8a6a20; font-weight: 700; }
.rate-poor { color: #a33b32; font-weight: 700; }

.empty-row td { text-align: left !important; color: #6d6458; }

#reset-board { margin-top: 14px; }

.heatmap-wrap { margin-bottom: 8px; }

.heatmap-paper {
  height: auto;
  overflow: visible;
}

.heatmap-paper svg {
  width: 100%;
  height: auto;
}

.heat-note { cursor: pointer; }

#heatmap-caption { min-height: 0; margin: 8px 0 0; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.85rem;
}

.legend li { display: flex; align-items: center; gap: 7px; }

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.swatch-none { background: #e7dfd0; box-shadow: inset 0 0 0 1.5px #8d8478; }
.swatch-weak { background: #ff2d2d; }
.swatch-mid { background: #ffe14a; }
.swatch-strong { background: #2adf4f; }

.shortcuts {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.pop { animation: note-in 160ms ease-out; }

@keyframes note-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 800px) {
  .setup, .stat-grid { grid-template-columns: 1fr 1fr; }
  .answer-row { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
  .save-state { text-align: left; }
}

@media (max-width: 560px) {
  .setup, .stat-grid { grid-template-columns: 1fr; }
  .hint { min-height: 0; }
}

@media (max-height: 820px) {
  .timer-readout { font-size: 4.2rem; }
  .stage-play { height: min(420px, calc(100vh - 250px)); }
}

@media (prefers-reduced-motion: reduce) {
  .pop { animation: none; }
  .feedback.good.show .mark-wrap,
  .feedback.bad.show .mark-wrap {
    animation: none;
    opacity: 1;
  }
}
