/*
  Responsibility: Define the visual system and responsive layout for Number Ear.
  Implementation:
  1. Use a restrained navy, blue, coral, green, and paper palette for clear scanning.
  2. Keep the practice workspace dense on desktop and comfortable on mobile.
  3. Provide visible focus, feedback, disabled, and playing states for each interaction.
*/

:root {
  --ink: #17324d;
  --ink-soft: #4b6072;
  --muted: #7f8c96;
  --paper: #f6f8f7;
  --surface: #ffffff;
  --line: #dfe7e5;
  --blue: #2674a6;
  --blue-soft: #e8f2f8;
  --coral: #ee785f;
  --green: #27936f;
  --green-soft: #e7f5ef;
  --orange: #d98c3b;
  --shadow: 0 18px 45px rgba(23, 50, 77, 0.09);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(38, 116, 166, 0.28);
  outline-offset: 2px;
}

.app-shell { max-width: 1180px; margin: 0 auto; padding: 26px 34px 22px; }
.topbar, .intro-row, .practice-header, .after-answer, .stats-row, .footer-note { display: flex; align-items: center; }
.topbar { justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: #fff; background: var(--coral); font-weight: 800; font-size: 20px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: 0; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: 0; text-transform: uppercase; }
.topbar-meta { color: var(--ink-soft); font-size: 12px; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--green); }

.intro-row { justify-content: space-between; gap: 28px; padding: 44px 0 34px; }
.eyebrow, .section-kicker { margin: 0; color: var(--coral); font-size: 11px; font-weight: 800; letter-spacing: 0; }
h1, h2, p { margin-top: 0; }
h1 { max-width: 620px; margin-bottom: 12px; font-size: 48px; line-height: 1.08; letter-spacing: 0; }
.intro-copy { max-width: 560px; margin-bottom: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.7; }
.streak-panel { min-width: 154px; padding: 17px 21px; border: 1px solid #f2d5ce; background: #fff9f7; }
.streak-panel span, .streak-panel small { color: var(--coral); font-size: 12px; }
.streak-panel strong { margin: 0 3px 0 8px; font-size: 38px; line-height: 1; }

.mode-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.mode-tab { padding: 10px 14px; border: 1px solid transparent; border-radius: 4px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 800; }
.mode-tab:hover { color: var(--blue); background: var(--blue-soft); }
.mode-tab.is-active { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }

.workspace { display: grid; grid-template-columns: 278px minmax(0, 1fr); min-height: 540px; box-shadow: var(--shadow); background: var(--surface); }
.control-panel { padding: 27px 24px; border-right: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 20px; }
h2 { margin: 6px 0 0; font-size: 20px; }
.text-button, .reset-button { padding: 0; border: 0; color: var(--blue); background: none; font-size: 12px; }
.type-list { display: grid; gap: 8px; }
.type-option { display: flex; align-items: center; gap: 10px; min-height: 39px; padding: 8px 10px; border: 1px solid transparent; color: var(--ink-soft); font-size: 13px; cursor: pointer; }
.type-option:hover { border-color: var(--line); background: #fbfcfc; }
.type-option input { accent-color: var(--blue); }
.type-option .type-count { margin-left: auto; color: var(--muted); font-size: 11px; }
.setting-group { margin-top: 25px; }
.setting-group label { display: block; margin-bottom: 8px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.select-wrap { position: relative; }
.select-wrap::after { position: absolute; right: 11px; top: 9px; color: var(--muted); content: "⌄"; pointer-events: none; }
select { width: 100%; padding: 10px 28px 10px 11px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: #fff; appearance: none; font-size: 12px; }
.custom-length-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.custom-length-row[hidden] { display: none; }
.custom-length-row label { margin: 0; }
.custom-length-row span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.custom-length-row input { width: 100%; padding: 10px 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: #fff; font-size: 12px; }
.setting-note { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.wide-button { width: 100%; margin-top: 28px; }
.secondary-button, .primary-button, .submit-button { border: 0; border-radius: 4px; font-weight: 700; }
.secondary-button { padding: 11px 14px; color: var(--blue); background: var(--blue-soft); }
.secondary-button:hover { background: #d9ebf5; }

.practice-panel { display: flex; flex-direction: column; padding: 27px 44px 25px; }
.practice-header { justify-content: space-between; align-items: end; }
.question-meta { margin-top: 8px; font-size: 14px; font-weight: 800; }
.meta-separator { margin: 0 5px; color: var(--muted); }
.play-count { color: var(--muted); font-size: 12px; }
.play-count span:first-child { color: var(--blue); font-weight: 800; }
.question-card { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; min-height: 260px; margin: 28px 0 24px; border: 1px solid var(--line); background: #fbfcfb; text-align: center; }
.question-card.is-playing { border-color: #b9d7e7; background: var(--blue-soft); }
.sound-wave { display: flex; align-items: center; gap: 4px; height: 30px; margin-bottom: 15px; }
.sound-wave span { width: 3px; height: 10px; border-radius: 3px; background: #a6c6d7; }
.question-card.is-playing .sound-wave span { animation: pulse .75s ease-in-out infinite alternate; background: var(--blue); }
.sound-wave span:nth-child(2), .sound-wave span:nth-child(6) { height: 18px; animation-delay: .1s; }
.sound-wave span:nth-child(3), .sound-wave span:nth-child(5) { height: 25px; animation-delay: .2s; }
.sound-wave span:nth-child(4) { height: 30px; animation-delay: .3s; }
@keyframes pulse { from { transform: scaleY(.45); } to { transform: scaleY(1); } }
#listen-hint { margin-bottom: 17px; color: var(--muted); font-size: 12px; }
.play-button { display: inline-flex; align-items: center; gap: 11px; padding: 14px 22px; border: 0; border-radius: 4px; color: #fff; background: var(--ink); font-size: 14px; font-weight: 800; }
.play-button:hover { background: #244967; }
.play-button:disabled { cursor: not-allowed; opacity: .58; }
.play-icon { font-size: 12px; }
.speech-preview { min-height: 18px; margin: 15px 0 0; color: var(--blue); font-size: 12px; }
.answer-form label { display: block; margin-bottom: 9px; font-size: 13px; font-weight: 800; }
.answer-line { display: flex; gap: 9px; }
.answer-line input { width: 100%; min-width: 0; padding: 13px 14px; border: 1px solid #bfcfce; border-radius: 4px; color: var(--ink); background: #fff; }
.answer-line input::placeholder { color: #aeb9bd; }
.submit-button { display: inline-flex; align-items: center; gap: 14px; padding: 0 17px; color: #fff; background: var(--coral); }
.submit-button:hover { background: #dc644e; }
.input-note { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.feedback { margin-top: 17px; padding: 12px 14px; border-left: 3px solid var(--green); color: #216b54; background: var(--green-soft); font-size: 13px; line-height: 1.5; }
.feedback.incorrect { border-color: var(--coral); color: #985044; background: #fff0ed; }
.feedback strong { display: block; margin-bottom: 4px; }
.after-answer { justify-content: space-between; gap: 15px; margin-top: 19px; }
.ghost-button { padding: 10px 0; border: 0; color: var(--blue); background: none; font-size: 12px; font-weight: 700; }
.primary-button { padding: 11px 16px; color: #fff; background: var(--blue); }
.primary-button:hover { background: #1d618d; }
.primary-button:disabled { cursor: not-allowed; opacity: .35; }

.stats-row { gap: 34px; margin-top: 25px; padding: 18px 22px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat-item { display: flex; align-items: center; gap: 10px; min-width: 130px; }
.stat-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-size: 14px; font-weight: 800; }
.stat-icon-blue { color: var(--blue); background: var(--blue-soft); }
.stat-icon-green { color: var(--green); background: var(--green-soft); }
.stat-icon-orange { color: var(--orange); background: #fff1df; }
.stat-item strong, .stat-item span { display: block; }
.stat-item strong { font-size: 16px; }
.stat-item div span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.reset-button { margin-left: auto; color: var(--muted); }
.reset-button:hover { color: var(--coral); }
.footer-note { justify-content: space-between; gap: 20px; padding-top: 16px; color: var(--muted); font-size: 11px; }

.reaction-section { min-height: 540px; padding: 32px 44px; box-shadow: var(--shadow); background: var(--surface); }
.reaction-header { display: flex; justify-content: space-between; align-items: end; gap: 28px; }
.reaction-header h2 { margin-top: 8px; font-size: 30px; }
.reaction-copy { max-width: 620px; margin: 10px 0 0; color: var(--ink-soft); font-size: 13px; line-height: 1.65; }
.reaction-actions { display: flex; align-items: center; gap: 18px; }
.reaction-grid { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 22px; margin-top: 33px; }
.reaction-card { display: flex; min-height: 355px; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--line); background: #fbfcfb; text-align: center; }
.reaction-card.is-playing { border-color: #b9d7e7; background: var(--blue-soft); }
.reaction-card.is-correct { border-color: #b9dfcc; background: var(--green-soft); }
.reaction-card.is-wrong { border-color: #f2c9c0; background: #fff0ed; }
.reaction-card #reaction-status { margin: 0 0 17px; color: var(--muted); font-size: 12px; }
.reaction-result { min-height: 60px; color: var(--ink); font-size: 56px; line-height: 1; }
.reaction-feedback { min-height: 20px; margin: 18px 0 0; color: var(--blue); font-size: 13px; font-weight: 800; }
.reaction-stats { display: flex; flex-direction: column; gap: 10px; }
.reaction-stat { display: flex; align-items: baseline; justify-content: space-between; padding: 15px 16px; border: 1px solid var(--line); background: #fff; }
.reaction-stat span { color: var(--muted); font-size: 12px; }
.reaction-stat strong { color: var(--ink); font-size: 22px; }
.reaction-tip { margin-top: auto; padding: 13px 4px; color: var(--muted); font-size: 11px; line-height: 1.6; }

@media (max-width: 760px) {
  .app-shell { padding: 19px 17px 18px; }
  .intro-row { align-items: flex-start; padding: 32px 0 24px; }
  h1 { font-size: 34px; }
  .streak-panel { min-width: 112px; padding: 13px 14px; }
  .streak-panel strong { display: block; margin: 6px 0 0; font-size: 32px; }
  .workspace { display: block; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .type-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setting-group { display: block; width: 100%; }
  .setting-group + .setting-group { margin-left: 0; }
  .wide-button { margin-top: 20px; }
  .practice-panel { padding: 24px 18px 21px; }
  .question-card { min-height: 230px; margin-top: 21px; }
  .stats-row { flex-wrap: wrap; gap: 17px 24px; }
  .stat-item { min-width: calc(50% - 12px); }
  .reset-button { width: 100%; margin-left: 0; text-align: left; }
  .footer-note { align-items: flex-start; flex-direction: column; gap: 6px; }
  .reaction-section { padding: 25px 18px; }
  .reaction-header { align-items: flex-start; flex-direction: column; gap: 20px; }
  .reaction-header h2 { font-size: 25px; }
  .reaction-grid { grid-template-columns: 1fr; }
  .reaction-card { min-height: 290px; }
  .reaction-stats { display: grid; grid-template-columns: 1fr 1fr; }
  .reaction-tip { grid-column: 1 / -1; margin-top: 0; }
}

@media (max-width: 450px) {
  .intro-row { gap: 12px; }
  .intro-copy { font-size: 13px; }
  .streak-panel { min-width: 88px; }
  .streak-panel small { display: none; }
  .type-list { grid-template-columns: 1fr; }
  .setting-group { display: block; width: 100%; }
  .setting-group + .setting-group { margin-left: 0; }
  .answer-line { display: block; }
  .submit-button { justify-content: center; width: 100%; margin-top: 9px; padding: 12px; }
  .mode-tabs { width: 100%; }
  .mode-tab { flex: 1; padding-inline: 8px; }
  .reaction-actions { width: 100%; justify-content: space-between; }
}
