:root {
  --ink: #24170f;
  --muted: #6f5a45;
  --paper: #fff4dd;
  --card: rgba(255, 250, 238, 0.88);
  --line: #2d2017;
  --accent: #dd6c31;
  --accent-dark: #9a3f1f;
  --mint: #7ab99b;
  --gold: #f2b84b;
  --rose: #e96d6d;
  --shadow: 0 28px 80px rgba(69, 39, 15, 0.2);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 18%, rgba(242, 184, 75, 0.38), transparent 28rem),
    radial-gradient(circle at 84% 12%, rgba(122, 185, 155, 0.4), transparent 24rem),
    linear-gradient(135deg, #fff7e8 0%, #f6dfbd 55%, #edc79f 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(36, 23, 15, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(36, 23, 15, 0.045) 1px, transparent 1px);
  background-size: 36px 36px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: stretch;
  margin-bottom: 24px;
  transition: grid-template-columns 220ms ease, margin-bottom 220ms ease;
}

.hero__copy,
.setup-card,
.quiz-card {
  border: 1px solid rgba(36, 23, 15, 0.12);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.hero__copy {
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 5vw, 54px);
  transition: max-height 220ms ease, opacity 180ms ease, padding 220ms ease;
}

.hero__copy::after {
  position: absolute;
  right: -20px;
  bottom: -54px;
  color: rgba(221, 108, 49, 0.16);
  font-size: 11rem;
  font-weight: 900;
  content: "\266A";
  transform: rotate(-12deg);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 0.95;
}

h1 {
  max-width: 760px;
  font-size: clamp(2.5rem, 7vw, 5.8rem);
  letter-spacing: -0.06em;
}

h2 {
  font-size: clamp(2rem, 5vw, 3.6rem);
}

.hero__copy p:last-child {
  max-width: 620px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.6;
}

.setup-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 26px;
}

.setup-card__label {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 900;
}

.round-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.round-button,
.secondary-button {
  border: 1px solid rgba(36, 23, 15, 0.16);
  border-radius: 16px;
  background: #fff8ea;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.round-button {
  min-height: 54px;
}

.round-button.is-active {
  border-color: transparent;
  background: var(--ink);
  color: var(--paper);
}

.primary-button,
.secondary-button {
  min-height: 56px;
  padding: 0 22px;
}

.primary-button {
  border: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff9ef;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(154, 63, 31, 0.28);
}

.primary-button[data-mode="stop"] {
  background: linear-gradient(135deg, #8f3226, #4c1c18);
}

body.is-playing .app-shell {
  padding-top: 12px;
}

body.is-playing .hero {
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

body.is-playing .hero__copy {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
}

.quiz-card {
  padding: clamp(18px, 3vw, 30px);
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.stats-bar article {
  border-radius: 20px;
  padding: 14px 16px;
  background: rgba(255, 244, 221, 0.76);
}

.stats-bar span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stats-bar strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.35rem, 3vw, 2.05rem);
  line-height: 1;
}

.staff-wrap {
  overflow: hidden;
  border-radius: 24px;
  position: relative;
  /* Ensure a neutral white background for the pentagram for better contrast
     when served from different hosts (Cloudflare Pages, etc.) */
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfb 100%);
  border: 1px solid rgba(36, 23, 15, 0.04);
  padding: clamp(18px, 3vw, 28px);
  --staff-row-height: 18px;
}

@media (max-width: 520px) {
  .staff-wrap {
    --staff-row-height: 16px;
  }
}

.clef-wrapper {
  position: absolute;
  left: clamp(16px, 18vw, 230px);
  bottom: calc(1 * var(--staff-row-height) + 6px);
  z-index: 99995;
  pointer-events: none;
}

.clef-wrapper img {
  display: block;
  width: auto;
  height: clamp(170px, 20vw, 240px);
}

.staff-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  max-width: 760px;
  margin: 0 auto 16px;
}


.staff-heading span {
  color: var(--ink);
  font-weight: 900;
}

.staff-heading small {
  color: var(--muted);
  font-weight: 900;
}

.staff-board {
  display: grid;
  grid-template-rows: repeat(17, 18px);
  max-width: 760px;
  min-height: 306px;
  margin: 0 auto;
  padding: 12px 0;
}

.staff-row {
  position: relative;
  display: grid;
  place-items: center;
  overflow: visible;
}

.staff-row.is-line::before,
.staff-row.is-guide-line::before {
  position: absolute;
  top: 50%;
  height: 4px;
  border-radius: 999px;
  content: "";
  transform: translateY(-50%);
}

.staff-row.is-line::before {
  left: 7%;
  right: 7%;
  background: var(--line);
}

.staff-row.is-guide-line::before {
  left: 30%;
  right: 30%;
  background: rgba(36, 23, 15, 0.14);
}

.staff-cell {
  position: relative;
  display: grid;
  width: 140px;
  height: 18px;
  place-items: center;
}

.note-token {
  position: relative;
  z-index: 1;
  display: block;
  width: 72px;
  height: 18px;
}

.note-head {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 30px;
  border: 5px solid var(--ink);
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%) rotate(-14deg);
}

.feedback {
  min-height: 42px;
  margin: 18px 0 14px;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 900;
  text-align: center;
}

.feedback.is-correct {
  color: #2d7d53;
}

.feedback.is-wrong {
  color: #bd3d31;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  max-width: 820px;
  margin: 0 auto;
}

.answer-button {
  min-height: 62px;
  border: 1px solid rgba(36, 23, 15, 0.12);
  border-radius: 18px;
  background: #fff7e8;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.answer-button:hover:not(:disabled),
.answer-button:focus-visible {
  border-color: var(--accent);
  background: #fff0d2;
  transform: translateY(-2px);
}

.answer-button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.answer-button.is-correct {
  border-color: transparent;
  background: rgba(122, 185, 155, 0.42);
}

.answer-button.is-wrong {
  border-color: transparent;
  background: rgba(233, 109, 109, 0.34);
}

.result-dialog {
  max-width: min(520px, calc(100% - 32px));
  border: 0;
  border-radius: 28px;
  padding: 0;
  background: transparent;
}

.result-dialog::backdrop {
  background: rgba(36, 23, 15, 0.46);
  backdrop-filter: blur(8px);
}

.result-dialog__content {
  padding: 32px;
  border: 1px solid rgba(36, 23, 15, 0.14);
  border-radius: 28px;
  background: #fff7e8;
  box-shadow: var(--shadow);
}

.result-dialog__content p:not(.eyebrow) {
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.result-dialog__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media (max-width: 820px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .answer-grid {
    grid-template-columns: repeat(4, minmax(82px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 10px 0 20px;
  }

  .hero__copy,
  .setup-card,
  .quiz-card {
    border-radius: 22px;
  }

  .stats-bar {
    gap: 8px;
  }

  .stats-bar article {
    padding: 12px;
  }

  .staff-heading {
    display: block;
  }

  .staff-heading small {
    display: block;
    margin-top: 4px;
  }

  .staff-board {
    grid-template-rows: repeat(17, 16px);
    min-height: 272px;
  }

  .result-dialog__actions {
    flex-direction: column-reverse;
  }
}
