:root {
  --paper: #f6f1e8;
  --paper-2: #fffdf8;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #e7e0d4;
  --accent: #c2410c;
  --accent-dark: #9a3412;
  --card: #ffffff;
  --shadow: 0 20px 50px rgba(28, 25, 23, 0.08);
  --radius: 20px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: "Outfit", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body::before {
  content: "";
  display: block;
  flex: 0 0 8px;
  height: 8px;
  background: linear-gradient(90deg, var(--accent), #ea580c 55%, #1c1917);
}

a {
  color: var(--accent-dark);
  text-underline-offset: 0.18em;
}

.site-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
}

.cover-container {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 32px;
}

.masthead {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.masthead-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 18px 0 16px;
}

.masthead-brand {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.55rem;
  margin: 0;
  font-size: 2.15rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.masthead-product {
  margin: 0;
  font-size: 1em;
  font-weight: 650;
  line-height: 1.15;
  color: var(--muted);
  letter-spacing: -0.03em;
}

.masthead-brand a {
  color: var(--ink);
  text-decoration: none;
}

.masthead-brand a:hover {
  color: var(--accent);
}

.masthead-nav {
  margin: 0;
  padding: 0;
  list-style: none;
}

.masthead-nav > li {
  display: inline-block;
}

.masthead-nav > li + li {
  margin-left: 18px;
}

.masthead-nav a {
  padding: 4px 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  text-decoration: none;
}

.masthead-nav a:hover,
.masthead-nav a.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.kicker {
  margin: 12px 0 10px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.08;
}

.lead {
  margin: 0 0 22px;
  max-width: 42rem;
  color: var(--muted);
  font-size: 1.08rem;
}

.intro-row,
.matrix-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.intro-row {
  margin: 0 0 8px;
}

.matrix-toolbar {
  margin: 0 0 14px;
}

#directions,
#play-hint,
#about {
  max-width: none;
  margin: 0;
  flex: 1 1 18rem;
}

#about {
  margin: 0 0 12px;
  flex: none;
}

.matrix-caption {
  caption-side: top;
  text-align: left;
  padding: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--muted);
}

.accidental-form,
.toolbar-actions {
  flex: 0 0 auto;
}

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

.btn-random {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  font: inherit;
  font-weight: 700;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn-random:hover,
.btn-random:focus {
  background: var(--accent);
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.segmented label {
  position: relative;
  margin: 0;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--ink);
  color: #fff;
}

.segmented input:focus-visible + span {
  outline: 3px solid rgba(194, 65, 12, 0.35);
  outline-offset: 2px;
}

.matrix-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  overflow-x: auto;
}

.range-controls {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.range-label {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.range-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.range-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.note-pills,
.octave-pills,
.timesig-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.range-random,
.note-pill,
.octave-pill,
.timesig-pill {
  appearance: none;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.range-random {
  padding: 8px 16px;
}

.note-pill,
.octave-pill,
.timesig-pill {
  min-width: 2.4rem;
  padding: 8px 10px;
}

.timesig-pill {
  min-width: 2.8rem;
}

.range-random.is-active,
.note-pill.is-active,
.octave-pill.is-active,
.timesig-pill.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.range-random:hover,
.note-pill:hover,
.octave-pill:hover,
.timesig-pill:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.range-random.is-active:hover,
.note-pill.is-active:hover,
.octave-pill.is-active:hover,
.timesig-pill.is-active:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.range-caption {
  margin-right: 4px;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
}

.range-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.range-controls.is-random .note-pills,
.range-controls.is-random .octave-pill {
  opacity: 0.55;
}

#matrix {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  table-layout: fixed;
}

#matrix td {
  width: calc(100% / 14);
  height: 2.6rem;
  padding: 0;
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--line);
  background: var(--paper-2);
  font-weight: 650;
  font-size: 0.95rem;
}

#matrix tr:first-child td,
#matrix tr:last-child td,
#matrix td:first-child,
#matrix td:last-child {
  background: #f3eee4;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#matrix tr:first-child td:not(:first-child):not(:last-child),
#matrix tr:last-child td:not(:first-child):not(:last-child),
#matrix tr:not(:first-child):not(:last-child) td:first-child,
#matrix tr:not(:first-child):not(:last-child) td:last-child {
  user-select: none;
}

#matrix.matrix-ready tr:first-child td:not(:first-child):not(:last-child),
#matrix.matrix-ready tr:last-child td:not(:first-child):not(:last-child),
#matrix.matrix-ready tr:not(:first-child):not(:last-child) td:first-child,
#matrix.matrix-ready tr:not(:first-child):not(:last-child) td:last-child {
  cursor: pointer;
}

#matrix:not(.matrix-ready) tr:first-child td:not(:first-child):not(:last-child),
#matrix:not(.matrix-ready) tr:last-child td:not(:first-child):not(:last-child),
#matrix:not(.matrix-ready) tr:not(:first-child):not(:last-child) td:first-child,
#matrix:not(.matrix-ready) tr:not(:first-child):not(:last-child) td:last-child {
  cursor: default;
  opacity: 0.4;
  pointer-events: none;
}

#matrix.matrix-ready tr:first-child td:not(:first-child):not(:last-child):hover,
#matrix.matrix-ready tr:last-child td:not(:first-child):not(:last-child):hover,
#matrix.matrix-ready tr:not(:first-child):not(:last-child) td:first-child:hover,
#matrix.matrix-ready tr:not(:first-child):not(:last-child) td:last-child:hover {
  background: #fff7ed;
  color: var(--accent-dark);
}

.play-all-cell {
  padding: 0 !important;
}

.play-all {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 2.6rem;
  color: var(--ink);
  cursor: pointer;
}

.play-all svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.play-all .icon-stop {
  display: none;
}

.play-all.is-playing .icon-play {
  display: none;
}

.play-all.is-playing .icon-stop {
  display: block;
}

.play-all.is-disabled {
  cursor: default;
  opacity: 0.35;
}

.play-all:not(.is-disabled):hover {
  background: #fff7ed;
  color: var(--accent);
}

.play-all.is-playing,
.play-all.is-playing:hover {
  background: var(--ink);
  color: #fff;
}

#matrix td.tone-playing {
  background: #fff7ed !important;
}

#matrix td.tone-now {
  background: #ffedd5 !important;
  color: var(--accent-dark);
}

#matrix #r1 td:nth-child(n+2):nth-child(-n+13) {
  background: #fff;
}

#matrix input {
  width: 100%;
  height: 2.6rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-align: center;
  outline: none;
}

#matrix input:focus {
  background: #fff7ed;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.pitch-menu {
  position: fixed;
  z-index: 40;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  max-height: min(240px, 50vh);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.pitch-menu li {
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 700;
  text-align: center;
}

.pitch-menu li:hover,
.pitch-menu li.active {
  background: #fff7ed;
  color: var(--accent-dark);
}

.site-footer {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--muted);
}

.btn-random:disabled {
  opacity: 0.4;
  cursor: default;
  background: var(--ink);
}

.score-sheet {
  display: none;
}

@media print {
  body::before {
    display: none !important;
  }

  .site-wrapper {
    display: none !important;
  }

  .score-sheet {
    display: block !important;
    color: #111;
  }

  .score-sheet h1 {
    margin: 0 0 4px;
    font-size: 1.4rem;
  }

  .score-sheet .score-meta {
    margin: 0 0 12px;
    font-size: 0.85rem;
  }

  .score-sheet svg {
    width: 100%;
    height: auto;
    page-break-inside: avoid;
  }
}

@media (max-width: 720px) {
  .cover-container {
    width: min(1120px, calc(100% - 20px));
  }

  .masthead-brand {
    font-size: 1.7rem;
  }

  .matrix-card {
    padding: 10px;
  }

  #matrix td,
  #matrix input,
  .play-all {
    height: 2.15rem;
    font-size: 0.85rem;
  }
}
