:root {
  --paper: #eef2f6;
  --card: #ffffff;
  --ink: #17203a;
  --muted: #5d6882;
  --rule: #c7d0de;
  --focus: #2f6bff;

  /* one hue per scale degree, shown only when the answer is revealed */
  --n1: #d6453d;
  --n2: #e3842b;
  --n3: #c9a311;
  --n4: #3c9a52;
  --n5: #2a8fb8;
  --n6: #4f5bd5;
  --n7: #9a4cc4;

  --digit: "Bitter", Georgia, serif;
  --body: "Noto Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
}

kbd {
  font-family: var(--body);
  font-size: 0.85em;
  padding: 0.05em 0.45em;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card);
}

.top {
  padding: 28px 24px 0;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}
.top h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.top h1 .brand { font-family: var(--digit); font-weight: 800; letter-spacing: 0.01em; }
.top h1 .tagline { font-weight: 400; color: var(--muted); margin-left: 0.3em; }

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.lang {
  position: relative;
  display: flex;
  align-items: center;
  color: var(--muted);
}
.lang svg { position: absolute; left: 10px; pointer-events: none; }
.lang select {
  appearance: none;
  height: 38px;
  padding: 0 32px 0 34px;
  border-radius: 10px;
  border: 1.5px solid var(--rule);
  background: var(--card)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235d6882' stroke-width='1.6'/%3E%3C/svg%3E")
    no-repeat right 11px center / 11px 8px;
  color: var(--ink);
  font: 500 0.9rem var(--body);
  cursor: pointer;
}
.lang select:hover { border-color: var(--ink); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }

main {
  flex: 1;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- stage: the jianpu "bar" ---------- */
.stage {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 1px 0 var(--rule), 0 12px 32px -18px rgba(23, 32, 58, 0.35);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px 16px;
  cursor: pointer;
  user-select: none;
}

.stage-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 3vw, 32px);
  width: 100%;
}

.nav {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--rule);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, opacity 0.15s;
}
.nav:hover:not(:disabled) { color: var(--ink); border-color: var(--ink); }
.nav:disabled { opacity: 0.35; cursor: default; }

.staff {
  display: flex;
  align-items: flex-start;
  gap: clamp(14px, 4vw, 40px);
  padding: 0 clamp(14px, 4vw, 36px);
  /* bar lines on both ends, like a measure in numbered notation */
  border-left: 3px solid var(--ink);
  border-right: 3px solid var(--ink);
  min-height: 9rem;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 12px;
}

.note {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: clamp(54px, 13vw, 96px);
  animation: drop 0.28s ease-out both;
}
.note:nth-child(2) { animation-delay: 0.04s; }
.note:nth-child(3) { animation-delay: 0.08s; }
.note:nth-child(4) { animation-delay: 0.12s; }
.note:nth-child(5) { animation-delay: 0.16s; }
.note:nth-child(6) { animation-delay: 0.20s; }

.digit {
  font-family: var(--digit);
  font-weight: 800;
  font-size: clamp(3.6rem, 14vw, 6.5rem);
  line-height: 1;
  transition: color 0.2s;
}

.syllable {
  margin-top: 10px;
  height: 2.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s;
}
.syllable .en {
  font-family: var(--digit);
  font-weight: 600;
  font-size: clamp(1.15rem, 4vw, 1.6rem);
  letter-spacing: 0.02em;
}

.revealed .syllable { opacity: 1; transform: none; }
.revealed .note.playing .digit { transform: translateY(-4px); }
.revealed .note .digit { transition: color 0.2s, transform 0.12s; }

.n1 { --c: var(--n1); } .n2 { --c: var(--n2); } .n3 { --c: var(--n3); }
.n4 { --c: var(--n4); } .n5 { --c: var(--n5); } .n6 { --c: var(--n6); }
.n7 { --c: var(--n7); }
.revealed .note .digit,
.revealed .note .en { color: var(--c); }

.prompt { margin: 0; color: var(--muted); font-size: 0.95rem; }

@keyframes drop {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- controls ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 28px;
  padding: 4px 4px;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 0.85rem; font-weight: 500; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1.5px solid var(--rule);
  background: var(--card);
  color: var(--muted);
  font-family: var(--digit);
  font-weight: 800;
  font-size: 1.35rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.chip:hover { border-color: var(--ink); }

.range { display: flex; align-items: center; gap: 10px; }
.range input {
  width: 64px;
  height: 46px;
  border-radius: 12px;
  border: 1.5px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  font: 600 1.15rem var(--body);
  text-align: center;
}

.segmented {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  gap: 3px;
  border-radius: 12px;
  border: 1.5px solid var(--rule);
  background: var(--card);
}
.segmented button {
  min-width: 58px;
  height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: 600 1.15rem var(--digit);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented button[aria-checked="true"] { background: var(--ink); color: #fff; }
.segmented button:not([aria-checked="true"]):hover { color: var(--ink); }

.toggles { gap: 10px; justify-content: center; }
.toggles label { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; cursor: pointer; }
.toggles input { width: 18px; height: 18px; accent-color: var(--ink); }

.stats { margin: 0; align-self: center; color: var(--muted); font-size: 0.95rem; }

.about { border-top: 1px solid var(--rule); padding-top: 16px; color: var(--muted); max-width: 64ch; }
.about h2 { margin: 0 0 6px; font-size: 1rem; color: var(--ink); }
.about p { margin: 0; line-height: 1.6; font-size: 0.95rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.foot {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 24px 28px;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .top { padding: 20px 16px 0; }
  main { padding: 16px; }
  .controls { grid-template-columns: 1fr; }
  .stage { min-height: 260px; padding: 24px 10px; }
  .stage-row { gap: 4px; }
  .nav { width: 36px; height: 36px; }
  .staff { gap: 8px; padding: 0 8px; }
  .note { width: 44px; }
  .digit { font-size: 3.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
