:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-strong: #162326;
  --text: #172126;
  --muted: #64727a;
  --line: #dde4e8;
  --accent: #187b68;
  --accent-strong: #0d5f50;
  --coral: #f06f4f;
  --sun: #f3bf42;
  --blue: #336fbd;
  --ok: #148a56;
  --warn: #bb6a13;
  --bad: #ba3731;
  --shadow: 0 18px 55px rgba(19, 35, 44, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(120deg, rgba(24, 123, 104, 0.08), transparent 32%),
    radial-gradient(circle at 92% 8%, rgba(240, 111, 79, 0.16), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  width: min(1180px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
}

.control-panel,
.practice-stage {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--sun);
}

.brand-mark svg {
  width: 34px;
  height: 34px;
}

.brand-mark svg path:first-child {
  fill: currentColor;
  stroke: none;
}

.brand-mark svg path:not(:first-child) {
  color: var(--panel-strong);
  stroke-width: 2.5;
}

.brand-lockup h1,
.brand-lockup p,
.stage-header h2,
.stage-header p {
  margin: 0;
}

.brand-lockup h1 {
  font-size: 1.35rem;
  line-height: 1.1;
}

.brand-lockup p,
.stage-meta,
.field-label,
.section-heading,
.feedback-label,
.score-strip small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.source-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbfc;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--muted);
}

.status-dot.is-loading {
  background: var(--sun);
  box-shadow: 0 0 0 4px rgba(243, 191, 66, 0.18);
}

.status-dot.is-ready {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(20, 138, 86, 0.14);
}

.status-dot.is-error {
  background: var(--bad);
  box-shadow: 0 0 0 4px rgba(186, 55, 49, 0.14);
}

.field-label,
.section-heading {
  display: block;
  margin-bottom: 8px;
  letter-spacing: 0;
}

.select-control,
.typed-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}

.select-control {
  padding: 0 12px;
}

.typed-form input {
  padding: 0 14px;
  font-size: 1rem;
}

.select-control:focus,
.typed-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(24, 123, 104, 0.12);
}

.panel-section {
  padding-top: 2px;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.lesson-chip,
.segment,
.ghost-button,
.text-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
}

.lesson-chip.is-active,
.segment.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.lesson-chip.is-empty {
  display: none;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.setting-stack {
  display: grid;
  gap: 12px;
}

.toggle-row,
.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 750;
}

.toggle-row {
  justify-content: flex-start;
}

.range-row {
  justify-content: space-between;
}

.toggle-row input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
}

.range-row input {
  width: 140px;
  accent-color: var(--accent);
}

.practice-stage {
  display: flex;
  flex-direction: column;
  align-self: start;
  gap: 18px;
  min-width: 0;
  padding: 22px;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.stage-header h2 {
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1.04;
  letter-spacing: 0;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(2, 74px);
  gap: 8px;
}

.score-strip div {
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbfc;
  text-align: center;
}

.score-strip span {
  display: block;
  color: var(--accent-strong);
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef2;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--coral));
  transition: width 180ms ease;
}

.feedback-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 78px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--blue);
  border-radius: var(--radius);
  background: #fff;
}

.feedback-card.is-good {
  border-left-color: var(--ok);
  background: #f3fbf6;
}

.feedback-card.is-close {
  border-left-color: var(--warn);
  background: #fff8ec;
}

.feedback-card.is-miss {
  border-left-color: var(--bad);
  background: #fff4f2;
}

.feedback-label,
.transcript-text {
  margin: 0;
}

.transcript-text {
  margin-top: 3px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 850;
}

#feedbackText {
  flex: 0 0 auto;
  color: var(--panel-strong);
  font-size: 1.1rem;
}

.typing-grid {
  display: grid;
  grid-template-columns: 52px minmax(140px, 180px) minmax(0, 1fr) 52px;
  gap: 10px;
  align-items: end;
}

.icon-button,
.sound-button {
  min-height: 54px;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 900;
}

.icon-button {
  display: grid;
  place-items: center;
  background: var(--panel-strong);
}

.icon-button svg {
  width: 25px;
  height: 25px;
}

.sound-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(24, 123, 104, 0.2);
}

.sound-button svg {
  width: 21px;
  height: 21px;
}

.typed-form {
  display: grid;
  gap: 8px;
}

.typed-form > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 8px;
}

.ghost-button {
  padding: 0 14px;
}

.queue-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}

.text-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100vw - 22px, 720px);
    margin: 11px auto;
  }

  .control-panel {
    gap: 14px;
  }

  .lesson-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .practice-stage {
    padding: 16px;
  }
}

@media (max-width: 620px) {
  .stage-header,
  .feedback-card {
    align-items: stretch;
    flex-direction: column;
  }

  .score-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .typing-grid {
    grid-template-columns: 48px 1fr 48px;
  }

  .sound-button {
    grid-column: 2;
  }

  .typed-form {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #nextBtn {
    grid-column: 3;
    grid-row: 1;
  }

  .lesson-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
