:root {
  --ink: #1b1410;
  --ink-soft: #3d3228;
  --paper: #f3e6c9;
  --paper-deep: #e6d3a8;
  --rule: #2a2118;
  --gold: #c4a35a;
  --gold-bright: #e6c778;
  --walnut: #140f0c;
  --walnut-mid: #2a211b;
  --correct: #2f6b45;
  --wrong: #9a2f2f;
  --muted: #8a7b68;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Outfit, sans-serif;
  color: var(--paper);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(196, 163, 90, 0.16), transparent 50%),
    radial-gradient(900px 600px at 110% 10%, rgba(90, 40, 20, 0.35), transparent 45%),
    var(--walnut);
}

.app {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border: 1px solid rgba(196, 163, 90, 0.45);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 34px;
  color: var(--gold-bright);
  background: rgba(196, 163, 90, 0.08);
}

h1 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.home-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--gold);
  font-size: 0.82rem;
  text-decoration: none;
}

.home-link:hover {
  color: var(--gold-bright);
}

.stats {
  display: flex;
  gap: 18px;
}

.stat {
  min-width: 72px;
  text-align: right;
}

.stat-value {
  display: block;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--gold-bright);
}

.stat-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.lang-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.lang-bar button {
  font: inherit;
  cursor: pointer;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(196, 163, 90, 0.28);
  background: rgba(20, 15, 12, 0.4);
  color: var(--paper);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.lang-bar button.is-active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--ink);
}

.controls {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr auto;
  gap: 20px 28px;
  align-items: end;
  padding: 18px 20px;
  border: 1px solid rgba(196, 163, 90, 0.22);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  margin-bottom: 22px;
}

.play-btn {
  font: inherit;
  cursor: pointer;
  min-width: 132px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  padding: 0 22px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.play-btn:hover {
  background: var(--gold-bright);
}

.play-btn.is-running {
  background: #7d2a2a;
  color: #fff5f5;
}

.play-btn.is-running:hover {
  background: #9a2f2f;
}

.play-icon {
  font-size: 0.78rem;
  line-height: 1;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend,
.tempo-heading {
  display: block;
  margin-bottom: 10px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tempo-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.tempo-heading strong {
  color: var(--gold-bright);
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 600;
}

.segmented {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.seg-btn,
.note-btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid rgba(196, 163, 90, 0.28);
  background: rgba(20, 15, 12, 0.4);
  color: var(--paper);
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.seg-btn.is-active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--ink);
}

.seg-glyph {
  font-size: 1.15rem;
  line-height: 1;
}

.tempo-field {
  display: block;
}

.tempo-stepper {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 8px;
  align-items: center;
}

.tempo-stepper button {
  font: inherit;
  cursor: pointer;
  height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(196, 163, 90, 0.28);
  background: rgba(20, 15, 12, 0.4);
  color: var(--paper);
  font-size: 1.4rem;
  line-height: 1;
}

.tempo-stepper button:hover {
  border-color: var(--gold);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.tempo-hints {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

.stage {
  display: grid;
  gap: 18px;
}

.manuscript {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 28%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(90, 60, 20, 0.03) 2px,
      rgba(90, 60, 20, 0.03) 3px
    ),
    var(--paper);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 10px 8px 0;
  overflow: hidden;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: rgba(243, 230, 201, 0.78);
  color: var(--ink);
  text-align: center;
}

.start-overlay.is-hidden {
  display: none;
}

.overlay-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 8px 20px;
}

.overlay-panel.is-hidden {
  display: none;
}

.start-overlay p {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.35rem;
}

.result-kicker {
  font-family: Outfit, sans-serif !important;
  font-size: 0.78rem !important;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.result-grade {
  font-size: clamp(4.2rem, 12vw, 7rem);
  line-height: 0.9;
  font-weight: 700;
  color: var(--ink);
}

.result-label {
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.result-summary {
  font-family: Outfit, sans-serif !important;
  font-size: 1.05rem !important;
  color: var(--ink-soft);
}

.start-btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.start-btn:hover {
  background: #2c2118;
}

.staff {
  display: block;
  width: 100%;
  height: auto;
}

.note-head {
  animation: note-in 0.35s ease;
}

@keyframes note-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.timer {
  padding: 0 22px 16px;
}

.timer-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(27, 20, 16, 0.12);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9a2f2f, var(--gold));
  transform-origin: left center;
  transform: scaleX(1);
}

.guesses {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.note-btn {
  min-height: 56px;
  border-radius: 14px;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.35rem;
  font-weight: 600;
  transition: transform 0.15s, background 0.2s, border-color 0.2s;
}

.note-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.note-btn:disabled {
  cursor: default;
}

.note-btn.is-picked {
  border-color: var(--gold-bright);
  background: rgba(196, 163, 90, 0.16);
}

.note-btn.is-correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #f4fff6;
}

.note-btn.is-wrong {
  background: var(--wrong);
  border-color: var(--wrong);
  color: #fff5f5;
}

.solution {
  min-height: 96px;
  padding: 16px 20px;
  border-radius: 18px;
  background: var(--walnut-mid);
  border: 1px solid rgba(196, 163, 90, 0.16);
}

.solution.is-revealed {
  border-color: rgba(196, 163, 90, 0.5);
  background: #32271e;
}

.solution-kicker {
  margin: 0 0 6px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.solution-body {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 600;
  color: #d8c7a4;
}

.solution.is-revealed .solution-body {
  color: var(--gold-bright);
}

.solution.is-correct {
  border-color: rgba(47, 107, 69, 0.7);
}

.solution.is-missed {
  border-color: rgba(154, 47, 47, 0.55);
}

@media (max-width: 720px) {
  .topbar,
  .controls {
    grid-template-columns: 1fr;
    display: grid;
  }

  .play-btn {
    width: 100%;
  }

  .topbar {
    align-items: start;
  }

  .stats {
    justify-content: space-between;
  }

  .stat {
    text-align: left;
  }

  .guesses {
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
  }

  .note-btn {
    min-height: 48px;
    font-size: 1.05rem;
    padding: 0 2px;
  }
}

html.is-tv,
html.is-tv body {
  width: 1920px;
  height: 1080px;
  overflow: hidden;
}

html.is-tv body {
  cursor: none;
}

html.is-tv .app {
  display: flex;
  flex-direction: column;
  width: 1840px;
  height: 1080px;
  padding: 18px 40px 16px;
  box-sizing: border-box;
}

html.is-tv .topbar {
  margin-bottom: 10px;
  align-items: center;
}

html.is-tv .tagline,
html.is-tv .tempo-hints,
html.is-tv .home-link {
  display: none;
}

html.is-tv .brand-mark {
  width: 44px;
  height: 44px;
  font-size: 26px;
}

html.is-tv h1 {
  font-size: 2rem;
}

html.is-tv .stats {
  gap: 14px;
}

html.is-tv .stat {
  min-width: 64px;
}

html.is-tv .stat-value {
  font-size: 1.6rem;
}

html.is-tv .lang-bar {
  margin-bottom: 10px;
}

html.is-tv .lang-bar button {
  min-height: 40px;
  padding: 4px 12px;
  font-size: 0.9rem;
}

html.is-tv .controls {
  margin-bottom: 10px;
  padding: 10px 16px;
  gap: 12px 20px;
}

html.is-tv legend,
html.is-tv .tempo-heading {
  margin-bottom: 6px;
}

html.is-tv .seg-btn {
  min-height: 48px;
  padding: 8px 16px;
  font-size: 1rem;
}

html.is-tv .play-btn,
html.is-tv .start-btn {
  min-height: 48px;
  min-width: 160px;
  height: 48px;
  font-size: 1.05rem;
}

html.is-tv .tempo-stepper {
  grid-template-columns: 48px 1fr 48px;
}

html.is-tv .tempo-stepper button {
  height: 48px;
  font-size: 1.4rem;
}

html.is-tv .tempo-field input {
  height: 22px;
  pointer-events: none;
}

html.is-tv .stage {
  flex: 1;
  min-height: 0;
  gap: 6px;
}

html.is-tv .manuscript {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 4px;
}

html.is-tv .staff {
  flex: 1;
  min-height: 0;
  width: auto;
  max-height: 520px;
  margin: 0 auto;
}

html.is-tv .timer {
  padding: 0 16px 4px;
}

html.is-tv .timer-track {
  height: 4px;
}

html.is-tv .note-btn {
  min-height: 64px;
  font-size: 2rem;
  border-radius: 10px;
}

html.is-tv .solution {
  min-height: 0;
  padding: 4px 12px;
  border-radius: 10px;
}

html.is-tv .solution-kicker {
  display: none;
}

html.is-tv .solution-body {
  font-size: 1rem;
  line-height: 1.2;
}

html.is-tv .result-kicker {
  font-size: 1rem !important;
}

html.is-tv .result-grade {
  font-size: 7.5rem;
}

html.is-tv .result-label {
  font-size: 2.4rem;
}

html.is-tv .result-summary {
  font-size: 1.35rem !important;
}

html.is-tv button:focus,
html.is-tv input:focus {
  outline: 3px solid var(--gold-bright);
  outline-offset: 4px;
  box-shadow: 0 0 0 6px rgba(230, 199, 120, 0.2);
}

@media (prefers-reduced-motion: reduce) {
  .note-head,
  .timer-fill,
  .note-btn {
    animation: none;
    transition: none;
  }
}
