:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #667085;
  --paper: #f7f3ea;
  --surface: #fffdf7;
  --line: #d7d0c2;
  --accent: #235c7a;
  --accent-dark: #163f56;
  --coral: #b95b45;
  --green: #3b7a57;
  --shadow: 0 22px 60px rgba(33, 39, 45, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(35, 92, 122, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(185, 91, 69, 0.1), transparent 30%),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--coral);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.practice-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.panel,
.flashcard {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.92);
  box-shadow: var(--shadow);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.panel-row {
  display: grid;
  gap: 7px;
}

.panel-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  outline-color: var(--accent);
}

input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  outline-color: var(--accent);
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.top-score {
  width: min(100%, 340px);
}

.score-grid div {
  min-width: 0;
  padding: 8px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.74);
  text-align: center;
}

.score-card.flash-points {
  animation: flash-points 0.72s ease-in-out 3;
}

.score-card.flash-mistakes {
  animation: flash-mistakes 0.72s ease-in-out 3;
}

.score-card.flash-points span,
.score-card.flash-mistakes span {
  animation: flash-score-text 0.72s ease-in-out 3;
}

.score-grid strong {
  display: block;
  font-size: 1.28rem;
  line-height: 1;
}

.score-grid span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 22px;
  align-items: center;
  min-height: calc(100vh - 40px);
}

.auth-intro {
  display: grid;
  align-content: center;
  gap: 8px;
}

.auth-copy {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}

.auth-card,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.92);
  box-shadow: var(--shadow);
}

.auth-card {
  padding: 14px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.auth-tab {
  min-height: 40px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 850;
}

.auth-tab.active {
  color: #fff;
  background: var(--accent);
}

.auth-form {
  display: none;
  gap: 12px;
}

.auth-form.active {
  display: grid;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 850;
}

.auth-message {
  margin-top: 12px;
}

.user-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -6px 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.user-strip div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-strip a,
.link-button {
  color: var(--accent-dark);
  font-weight: 850;
  text-decoration: none;
}

.link-button {
  padding: 0;
  background: transparent;
}

.mini-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: auto;
}

.mini-stats div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mini-stats strong,
.mini-stats span {
  display: block;
}

.mini-stats strong {
  font-size: 1.2rem;
}

.mini-stats span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
}

.quiet-button {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-dark);
  background: #fff;
  font-weight: 800;
}

.flashcard {
  min-height: 690px;
  padding: 18px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 850;
}

.staff-stage {
  display: grid;
  place-items: center;
  min-height: 330px;
  margin: 18px 0 10px;
  border: 1px solid #e8e0d2;
  border-radius: 8px;
  background:
    radial-gradient(circle at 18% 20%, rgba(35, 92, 122, 0.08), transparent 25%),
    #fff;
  overflow: hidden;
}

.staff-stage svg {
  width: min(100%, 760px);
  height: auto;
  display: block;
}

.staff-line,
.ledger-line {
  stroke: #1d2430;
  stroke-width: 2.3;
  stroke-linecap: round;
}

.ledger-line {
  stroke-width: 2;
}

.note-head {
  fill: #1d2430;
}

.note-stem {
  stroke: #1d2430;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.clef-mark {
  fill: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 88px;
  font-weight: 700;
}

.answer-panel {
  display: grid;
  gap: 14px;
}

.choice-group {
  display: grid;
  gap: 8px;
}

.choice-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 850;
}

.choice-grid {
  display: grid;
  gap: 8px;
}

.note-grid {
  grid-template-columns: repeat(7, minmax(44px, 1fr));
}

.octave-grid {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}

.choice-button {
  min-height: 48px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 850;
}

.choice-button:hover,
.choice-button.active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.choice-button.correct {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.choice-button.correct-preview {
  opacity: 1;
  animation: flash-correct-choice 0.58s ease-in-out 3;
  box-shadow: 0 0 0 3px rgba(59, 122, 87, 0.18);
}

.choice-button.wrong {
  border-color: var(--coral);
  color: #fff;
  background: var(--coral);
}

.choice-button.wrong:disabled,
.choice-button.correct-preview:disabled {
  opacity: 1;
}

.feedback {
  display: grid;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-weight: 800;
}

.feedback.good {
  border-color: rgba(59, 122, 87, 0.36);
  color: var(--green);
  background: rgba(59, 122, 87, 0.08);
}

.feedback.bad {
  border-color: rgba(185, 91, 69, 0.36);
  color: var(--coral);
  background: rgba(185, 91, 69, 0.08);
}

.primary-button,
.secondary-button,
.success-button,
.icon-button {
  min-height: 48px;
  border-radius: 8px;
  font-weight: 850;
}

.primary-button {
  min-width: min(100%, 260px);
  padding: 0 20px;
  color: #fff;
  background: var(--accent);
}

.primary-button:hover,
.choice-button.active:hover {
  background: var(--accent-dark);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 56px;
  gap: 10px;
  margin-top: 20px;
}

.quiz-actions {
  grid-template-columns: 1fr;
}

.secondary-button {
  color: #fff;
  background: var(--coral);
}

.success-button {
  color: #fff;
  background: var(--green);
}

.icon-button {
  display: grid;
  place-items: center;
  color: var(--ink);
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.7rem;
}

.admin-shell {
  max-width: 1180px;
}

.admin-topbar {
  align-items: center;
}

.admin-back {
  text-decoration: none;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 16px;
}

.admin-card {
  min-width: 0;
  padding: 16px;
}

.admin-card h2,
.admin-card h3 {
  margin: 0;
}

.admin-card h2 {
  font-size: 1.15rem;
}

.admin-card h3 {
  margin-top: 16px;
  font-size: 0.98rem;
}

.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.admin-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.admin-table tbody tr {
  cursor: pointer;
}

.admin-table tbody tr:hover,
.admin-table tbody tr.active {
  background: rgba(35, 92, 122, 0.08);
}

.admin-table td span,
.admin-user-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.admin-details {
  color: var(--muted);
  font-weight: 750;
}

.admin-user-title {
  margin-bottom: 12px;
  color: var(--ink);
}

.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.admin-stat-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-stat-grid strong,
.admin-stat-grid span {
  display: block;
}

.admin-stat-grid span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

.admin-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.chart-card,
.breakdown-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chart-card strong,
.breakdown-card > strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.86rem;
}

.chart-card small,
.chart-card > span,
.breakdown-card > span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.bar-chart {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 96px;
  padding-top: 6px;
}

.bar-item {
  display: flex;
  align-items: end;
  flex: 1;
  min-width: 4px;
}

.bar-item span {
  width: 100%;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
}

.line-chart {
  width: 100%;
  height: auto;
  display: block;
}

.line-chart line {
  stroke: var(--line);
  stroke-width: 2;
}

.line-chart path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.line-chart circle {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 3;
}

.admin-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.breakdown-row span {
  font-weight: 850;
}

.breakdown-row strong {
  color: var(--accent-dark);
}

.breakdown-row em {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.74rem;
  font-style: normal;
  font-weight: 750;
}

@media (max-width: 820px) {
  .auth-layout,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
  }

  .top-score {
    width: min(68vw, 310px);
  }

  .practice-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    order: 2;
  }

  .flashcard {
    min-height: auto;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100vw - 20px, 1120px);
    padding: 12px 0;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 12px;
  }

  .eyebrow {
    font-size: 0.66rem;
  }

  h1 {
    font-size: 2.1rem;
  }

  .top-score {
    flex: 1;
    width: auto;
  }

  .score-grid div {
    padding: 7px 4px;
  }

  .score-grid strong {
    font-size: 1.18rem;
  }

  .score-grid span {
    font-size: 0.62rem;
  }

  .flashcard,
  .panel,
  .admin-card {
    padding: 12px;
  }

  .user-strip {
    align-items: start;
    flex-direction: column;
  }

  .auth-layout {
    min-height: calc(100vh - 24px);
  }

  .admin-stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-grid,
  .admin-breakdown {
    grid-template-columns: 1fr;
  }

  .card-header {
    flex-direction: column;
  }

  .staff-stage {
    min-height: 240px;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .icon-button {
    min-height: 46px;
  }
}

@media (max-width: 360px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .top-score {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .note-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .octave-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-button {
    min-height: 44px;
    padding: 0 6px;
  }
}

@keyframes flash-points {
  0%,
  100% {
    border-color: var(--line);
    background: #fff;
  }

  50% {
    border-color: var(--green);
    color: #fff;
    background: var(--green);
  }
}

@keyframes flash-mistakes {
  0%,
  100% {
    border-color: var(--line);
    background: #fff;
  }

  50% {
    border-color: var(--coral);
    color: #fff;
    background: var(--coral);
  }
}

@keyframes flash-score-text {
  0%,
  100% {
    color: var(--muted);
  }

  50% {
    color: #fff;
  }
}

@keyframes flash-correct-choice {
  0%,
  100% {
    border-color: var(--green);
    color: #fff;
    background: var(--green);
    box-shadow: 0 0 0 3px rgba(59, 122, 87, 0.24);
  }

  50% {
    border-color: rgba(59, 122, 87, 0.35);
    color: var(--green);
    background: rgba(59, 122, 87, 0.1);
    box-shadow: 0 0 0 1px rgba(59, 122, 87, 0.08);
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: calc(100vw - 12px);
    padding: 8px 0 10px;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
  }

  .eyebrow {
    margin-bottom: 0;
    font-size: 0.54rem;
    line-height: 1;
  }

  h1 {
    font-size: 1.75rem;
    line-height: 0.94;
  }

  .top-score {
    width: 100%;
  }

  .score-grid {
    gap: 5px;
  }

  .score-grid div {
    min-height: 44px;
    padding: 5px 3px;
  }

  .score-grid strong {
    font-size: 1rem;
  }

  .score-grid span {
    margin-top: 2px;
    font-size: 0.55rem;
  }

  .user-strip {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 10px;
    margin: 0 0 8px;
    font-size: 0.78rem;
  }

  .user-strip div {
    gap: 8px;
  }

  .practice-layout {
    gap: 10px;
  }

  .flashcard {
    padding: 10px;
  }

  .card-header {
    flex-direction: row;
    gap: 8px;
    font-size: 0.82rem;
  }

  .staff-stage {
    min-height: 168px;
    margin: 10px 0 8px;
  }

  .staff-stage svg {
    width: 100%;
  }

  .answer-panel {
    gap: 10px;
  }

  .choice-group {
    gap: 6px;
  }

  .choice-label {
    font-size: 0.8rem;
  }

  .choice-grid {
    gap: 5px;
  }

  .note-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .octave-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-button {
    min-height: 38px;
    padding: 0 4px;
    border-radius: 7px;
    font-size: 0.92rem;
  }

  .feedback {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .action-row {
    margin-top: 10px;
  }

  .primary-button {
    min-height: 42px;
    min-width: 0;
  }

  .panel {
    padding: 10px;
  }
}
