:root {
  --cell-size: 40px;
  --label-size: 30px;
  --tutorial-accent: #ffb84d;
  --tutorial-violet: #7357ff;
  --fn-root: #ffffff;
  --fn-flatthird: #ff8a3a;
  --fn-third: #ffce3a;
  --fn-fourth: #ff5252;
  --fn-fifth: #36c46b;
  --fn-sixth: #ff6fae;
  --fn-seventh: #5b9aff;
  --fn-majseventh: #28d0c0;
  --fn-ninth: #c08bff;
  --fn-eleventh: #ef6ff5;
  --fn-thirteenth: #a3d94d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #101116;
  color: var(--text, #f5f5f8);
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

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

#app-shell,
.view {
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.view {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 85% 0%, rgba(115, 87, 255, 0.16), transparent 30%),
    #101116;
}

.app-header {
  padding: max(30px, env(safe-area-inset-top)) 22px 22px;
  border-bottom: 1px solid var(--border, #2b2c35);
}

.list-app-header {
  padding-top: max(68px, calc(env(safe-area-inset-top) + 38px));
  background:
    radial-gradient(circle at 78% 14%, rgba(255, 184, 77, 0.15), transparent 38%),
    linear-gradient(160deg, rgba(115, 87, 255, 0.13), transparent 58%);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--tutorial-accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2.2rem, 10vw, 3.2rem);
  letter-spacing: -0.055em;
  line-height: 1;
}

.app-header h1 span {
  color: var(--tutorial-accent);
}

.header-copy {
  margin: 12px 0 0;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.96rem;
}

.mic-status {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--border, #2b2c35);
  border-radius: 999px;
  background: rgba(20, 21, 27, 0.88);
  color: var(--text-muted, #a3a3ad);
  font-size: 0.7rem;
  font-weight: 700;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.mic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9b9ba5;
  box-shadow: 0 0 0 3px rgba(155, 155, 165, 0.12);
}

.mic-status[data-state="listening"] .mic-dot {
  background: #35c46e;
  box-shadow: 0 0 0 3px rgba(53, 196, 110, 0.15);
}

.mic-status[data-state="calibrating"] .mic-dot,
.mic-status[data-state="requesting"] .mic-dot {
  background: var(--tutorial-accent);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

.mic-status[data-state="singing"] .mic-dot {
  background: #ff5b6e;
}

.mic-status[data-state="error"] .mic-dot,
.mic-status[data-state="needs-gesture"] .mic-dot {
  background: #ff7b58;
}

@keyframes mic-pulse {
  50% {
    opacity: 0.35;
    transform: scale(0.75);
  }
}

.list-main {
  flex: 1;
  overflow: auto;
  padding: 24px 18px 34px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 680px;
  margin: 0 auto 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.01em;
}

.count-badge {
  min-width: 24px;
  padding: 3px 8px;
  border: 1px solid var(--border, #2b2c35);
  border-radius: 999px;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.72rem;
  text-align: center;
}

.tag-list {
  display: grid;
  gap: 10px;
  max-width: 680px;
  margin: 0 auto;
}

.tag-card {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 15px;
  border: 1px solid var(--border, #2b2c35);
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025));
  color: var(--text, #f5f5f8);
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}

.tag-card:hover {
  border-color: rgba(255, 184, 77, 0.55);
  background: linear-gradient(135deg, rgba(255, 184, 77, 0.1), rgba(115, 87, 255, 0.06));
}

.tag-card:active {
  transform: scale(0.985);
}

.tag-card-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--tutorial-violet), #5139cc);
  color: #fff;
  font-family: Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(115, 87, 255, 0.23);
}

.tag-card-copy strong,
.tag-card-copy small {
  display: block;
}

.tag-card-copy strong {
  margin-bottom: 3px;
  font-size: 1.02rem;
}

.tag-card-copy small {
  color: var(--text-muted, #a3a3ad);
  font-size: 0.76rem;
}

.tag-card-chevron {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: var(--text-muted, #a3a3ad);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.prototype-note {
  max-width: 680px;
  margin: 16px auto 0;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.76rem;
  line-height: 1.45;
}

.app-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "hint version"
    "copyright copyright";
  align-items: center;
  gap: 3px 14px;
  min-height: 48px;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border, #2b2c35);
  color: var(--text-muted, #a3a3ad);
  font-size: 0.69rem;
}

.app-footer > :first-child {
  grid-area: hint;
}

.app-footer .copyright {
  grid-area: copyright;
  display: block;
  margin: 0;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.65rem;
  text-align: center;
  opacity: 0.6;
}

.version-label {
  flex: none;
  grid-area: version;
  position: static;
  top: auto;
  right: auto;
  transform: none;
  font-variant-numeric: tabular-nums;
}

body.tag-open .mic-status {
  top: auto;
  right: 14px;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 64px));
}

body.tag-open.playback-active .mic-status {
  bottom: max(98px, calc(env(safe-area-inset-bottom) + 90px));
}

.tag-header {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--border, #2b2c35);
  background: rgba(16, 17, 22, 0.94);
}

.icon-button,
.practice-button,
.exit-playback {
  border: 1px solid var(--border, #2b2c35);
  color: var(--text, #f5f5f8);
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 11px;
  background: var(--bg-surface, #1a1b22);
}

.icon-button svg,
.practice-button svg,
.exit-playback svg,
.mic-card-icon svg,
.blocker-mark svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tag-heading {
  min-width: 0;
}

.tag-heading h1 {
  overflow: hidden;
  margin: 0;
  font-size: 1.02rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-heading p {
  margin: 3px 0 0;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.72rem;
}

.practice-button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border-color: rgba(255, 184, 77, 0.45);
  border-radius: 11px;
  background: rgba(255, 184, 77, 0.1);
  color: var(--tutorial-accent);
  font-size: 0.76rem;
  font-weight: 800;
}

.practice-button svg {
  width: 16px;
  height: 16px;
}

.notation-scroll {
  flex: 1;
  overflow: auto;
  padding: 12px 12px 28px;
  scroll-behavior: smooth;
}

.notation-intro {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 12px 13px;
  border: 1px solid var(--border, #2b2c35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}

.notation-intro > p {
  margin: 0 0 9px;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.72rem;
}

.function-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 13px;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.66rem;
}

.function-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.function-legend i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.function-legend .fn-root {
  color: var(--fn-root);
}

.function-legend .fn-third {
  color: var(--fn-third);
}

.function-legend .fn-fifth {
  color: var(--fn-fifth);
}

.function-legend .fn-seventh {
  color: var(--fn-seventh);
}

.function-legend .fn-color {
  background: linear-gradient(135deg, var(--fn-ninth), var(--fn-sixth));
}

.stanzas {
  max-width: 1100px;
  margin: 0 auto;
}

.stanza {
  width: max-content;
  max-width: 100%;
  margin: 0 auto 23px;
}

.stanza-row {
  display: flex;
  min-height: 28px;
}

.row-label {
  display: flex;
  flex: 0 0 var(--label-size);
  align-items: center;
  justify-content: center;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.63rem;
  font-weight: 800;
  user-select: none;
}

.stanza-cells {
  display: flex;
}

.cell {
  position: relative;
  display: flex;
  flex: 0 0 var(--cell-size);
  align-items: center;
  justify-content: center;
  width: var(--cell-size);
  height: 28px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted, #a3a3ad);
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  white-space: nowrap;
  transition: color 100ms ease, background-color 100ms ease, border-color 100ms ease;
}

.cell.has-content {
  color: var(--text, #f5f5f8);
}

.lyrics-row {
  min-height: 25px;
}

.lyrics-row .cell {
  height: 25px;
  overflow: visible;
  color: var(--text, #f5f5f8);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.7rem;
}

.lyric-hyphen {
  margin-left: 1px;
  color: var(--text-muted, #a3a3ad);
}

.melisma-line {
  width: calc(100% + 2px);
  height: 2px;
  margin-bottom: -8px;
  background: var(--text-muted, #a3a3ad);
}

.melisma-punct {
  position: absolute;
  right: -2px;
  bottom: 1px;
}

.analysis-row {
  min-height: 24px;
  margin-top: 3px;
  border-top: 1px solid var(--border, #2b2c35);
}

.analysis-row .cell {
  height: 24px;
  overflow: visible;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.63rem;
  font-style: italic;
}

.note-row .cell.has-content {
  color: var(--text-muted, #a3a3ad);
}

.note-row .cell.note-fn-root {
  color: var(--fn-root);
}

.note-row .cell.note-fn-flatthird {
  color: var(--fn-flatthird);
}

.note-row .cell.note-fn-third {
  color: var(--fn-third);
}

.note-row .cell.note-fn-fourth {
  color: var(--fn-fourth);
}

.note-row .cell.note-fn-fifth {
  color: var(--fn-fifth);
}

.note-row .cell.note-fn-sixth {
  color: var(--fn-sixth);
}

.note-row .cell.note-fn-seventh {
  color: var(--fn-seventh);
}

.note-row .cell.note-fn-majseventh {
  color: var(--fn-majseventh);
}

.note-row .cell.note-fn-ninth {
  color: var(--fn-ninth);
}

.note-row .cell.note-fn-eleventh {
  color: var(--fn-eleventh);
}

.note-row .cell.note-fn-thirteenth {
  color: var(--fn-thirteenth);
}

.cell.playing {
  border-color: var(--tutorial-violet);
  background: var(--tutorial-violet);
  color: #fff !important;
  box-shadow: 0 0 14px rgba(115, 87, 255, 0.26);
}

.playback-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 80;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 9px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border, #2b2c35);
  background: rgba(20, 21, 27, 0.96);
  backdrop-filter: blur(14px);
}

.advance-playback {
  min-height: 61px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--tutorial-violet), #5d42e6);
  color: #fff;
  cursor: pointer;
}

.advance-playback span,
.advance-playback small {
  display: block;
}

.advance-playback span {
  font-size: 0.94rem;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.advance-playback small {
  margin-top: 3px;
  opacity: 0.78;
  font-size: 0.66rem;
}

.advance-playback:active {
  filter: brightness(0.9);
  transform: scale(0.992);
}

.exit-playback {
  display: grid;
  place-items: center;
  min-height: 61px;
  padding: 0;
  border-radius: 13px;
  background: var(--bg-surface, #1a1b22);
}

body.playback-active .notation-scroll {
  padding-bottom: 104px;
}

body.playback-active .tag-footer {
  visibility: hidden;
}

.mic-gate,
.singing-blocker {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.mic-gate {
  z-index: 120;
  background:
    radial-gradient(circle at 50% 25%, rgba(115, 87, 255, 0.2), transparent 35%),
    #101116;
}

.mic-card {
  width: min(100%, 410px);
  padding: 27px 24px;
  border: 1px solid var(--border, #2b2c35);
  border-radius: 20px;
  background: rgba(26, 27, 34, 0.96);
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.mic-card-icon,
.blocker-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  border-radius: 50%;
}

.mic-card-icon {
  background: rgba(115, 87, 255, 0.16);
  color: #a794ff;
}

.mic-card h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
}

.mic-card > p:not(.eyebrow) {
  margin: 0;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.86rem;
  line-height: 1.5;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  margin-top: 20px;
  border: 0;
  border-radius: 12px;
  background: var(--tutorial-violet);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.singing-blocker {
  z-index: 110;
  align-content: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 91, 110, 0.16), transparent 30%),
    #0c0d11;
  text-align: center;
}

.blocker-mark {
  background: rgba(255, 91, 110, 0.14);
  color: #ff6a7b;
  animation: blocker-breathe 1.3s ease-in-out infinite;
}

.blocker-mark svg {
  width: 28px;
  height: 28px;
}

@keyframes blocker-breathe {
  50% {
    box-shadow: 0 0 0 13px rgba(255, 91, 110, 0.05);
    transform: scale(1.04);
  }
}

.blocker-kicker {
  margin: 0 0 8px;
  color: #ff6a7b;
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.singing-blocker h2 {
  max-width: 480px;
  margin: 0 auto 12px;
  font-size: clamp(1.8rem, 8vw, 2.8rem);
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.singing-blocker > p:last-child {
  max-width: 390px;
  margin: 0 auto;
  color: var(--text-muted, #a3a3ad);
  font-size: 0.9rem;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

@media (min-width: 600px) {
  :root {
    --cell-size: 44px;
  }

  .notation-scroll {
    padding-right: 22px;
    padding-left: 22px;
  }

  .tag-header {
    padding-right: 20px;
    padding-left: 20px;
  }

  .playback-bar {
    right: 50%;
    left: auto;
    width: min(560px, calc(100% - 24px));
    transform: translateX(50%);
    border: 1px solid var(--border, #2b2c35);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
