:root {
  color-scheme: light;
  --bg: #e9f0ec;
  --surface: #fbfcf8;
  --surface-2: #e5eeea;
  --ink: #21302c;
  --muted: #5f6e68;
  --line: #bac9c1;
  --brown: #3f665c;
  --brown-2: #29483f;
  --gold: #b77a3f;
  --gold-2: #f0e2c9;
  --amber: #b56c22;
  --red: #9f3d2e;
  --blue: #286f9b;
  --gray: #66706a;
  --shadow: 0 18px 50px rgba(42, 69, 61, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  isolation: isolate;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: -2;
  background: url("./assets/ezhou-landscape-bg.jpg") center bottom / cover no-repeat;
}

body::after {
  z-index: -1;
  background: rgba(242, 247, 243, 0.56);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brown);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 42px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
}

.status-pill,
.difficulty {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--brown);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 310px minmax(380px, 1fr) 420px;
  gap: 16px;
  align-items: start;
}

.materials-panel,
.practice-panel,
.result-panel,
.notes > div {
  background: rgba(252, 253, 249, 0.93);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.materials-panel,
.result-panel {
  padding: 18px;
}

.practice-panel {
  padding: 22px;
}

.panel-heading,
.selected-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.materials-toggle {
  display: none;
  min-height: 34px;
  padding: 0 12px;
}

.result-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-2);
}

.tab {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(24, 43, 35, 0.08);
}

.material-list {
  display: grid;
  gap: 10px;
}

.material-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.material-item.active {
  border-color: var(--brown);
  background: var(--gold-2);
}

.material-select {
  min-height: 62px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.material-select strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.material-select span {
  color: var(--muted);
  font-size: 13px;
}

.material-toolbar {
  margin: 10px 0;
}

.small-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.material-actions {
  display: flex;
  gap: 4px;
}

.material-action {
  min-height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

.material-action.danger {
  color: var(--red);
}

.material-empty {
  margin: 8px 0 0;
  line-height: 1.6;
}

.reading-card {
  min-height: 220px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 252, 248, 0.88);
  padding: 28px;
}

.reading-card p {
  margin: 0;
  max-width: 760px;
  font-size: 30px;
  line-height: 1.75;
  text-align: center;
}

.meter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 70px;
  margin: 14px 0;
}

.meter span {
  width: 8px;
  height: 18px;
  border-radius: 999px;
  background: var(--gold);
  opacity: 0.26;
  transition: height 0.18s ease, opacity 0.18s ease;
}

.meter.recording span {
  animation: pulse 0.9s infinite ease-in-out;
  opacity: 0.75;
}

.meter.recording span:nth-child(2n) {
  animation-delay: 0.12s;
}

.meter.recording span:nth-child(3n) {
  animation-delay: 0.24s;
}

@keyframes pulse {
  0%,
  100% {
    height: 18px;
  }
  50% {
    height: 54px;
  }
}

.recorder {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--brown);
  color: #fff;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.text-button {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--brown);
}

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

audio {
  width: 100%;
  margin-top: 14px;
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.score-card {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 14px;
}

.score-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.score-card strong {
  font-size: 34px;
}

.score-card.strong {
  background: var(--brown);
  color: #fff;
}

.score-card.strong span {
  color: rgba(255, 255, 255, 0.75);
}

.validation-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.validation-panel.ok {
  border-color: rgba(75, 99, 67, 0.42);
}

.validation-panel.warning {
  border-color: rgba(181, 108, 34, 0.5);
  background: #fff7eb;
}

.validation-panel.fail {
  border-color: rgba(159, 61, 46, 0.5);
  background: #fff0ef;
}

.validation-main span,
.validation-metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.validation-main strong {
  display: block;
  margin-top: 5px;
  line-height: 1.5;
}

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

.validation-metrics div {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.validation-metrics strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.analysis-block {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

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

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
}

.legend-dot.ok {
  background: var(--surface);
}

.legend-dot.warning {
  border-color: rgba(181, 108, 34, 0.45);
  background: #fff4e8;
}

.legend-dot.error,
.legend-dot.missed {
  border-color: rgba(181, 67, 67, 0.45);
  background: #ffecec;
}

.legend-dot.repeated {
  border-color: rgba(40, 111, 155, 0.45);
  background: #eaf6ff;
}

.legend-dot.rejected {
  border-color: rgba(102, 112, 106, 0.45);
  background: #eff1ee;
}

.char-result {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.char-chip {
  min-width: 36px;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  position: relative;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: default;
  appearance: none;
  padding: 0 8px;
}

.char-chip[data-message] {
  cursor: pointer;
}

.char-chip:focus-visible {
  outline: 3px solid rgba(40, 111, 155, 0.3);
  outline-offset: 2px;
}

.char-chip.warning {
  border-color: rgba(181, 108, 34, 0.45);
  background: #fff4e8;
  color: var(--amber);
}

.char-chip.error {
  border-color: rgba(181, 67, 67, 0.45);
  background: #ffecec;
  color: var(--red);
}

.char-chip.missed {
  border-color: rgba(181, 67, 67, 0.65);
  border-style: dashed;
  background: #fff3f1;
  color: var(--red);
}

.char-chip.repeated,
.char-chip.extra {
  border-color: rgba(40, 111, 155, 0.45);
  background: #eaf6ff;
  color: var(--blue);
}

.char-chip.rejected {
  border-color: rgba(102, 112, 106, 0.45);
  background: #eff1ee;
  color: var(--gray);
}

.char-chip.ok {
  color: var(--brown);
}

.char-chip[data-message]::after {
  content: attr(data-message);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 220px;
  padding: 7px 9px;
  border-radius: 6px;
  background: #1f2924;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

.char-chip:hover::after,
.char-chip:focus-visible::after,
.char-chip.is-open::after {
  opacity: 1;
}

.char-detail {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--blue);
  background: #eef7fb;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
}

.empty {
  color: var(--muted);
}

.suggestions {
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
}

.suggestions li + li {
  margin-top: 8px;
}

.teacher-note {
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid rgba(75, 99, 67, 0.28);
  border-radius: 8px;
  background: #f3f8ee;
  color: var(--ink);
  line-height: 1.6;
  font-weight: 700;
}

.material-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(28, 34, 31, 0.24);
}

.material-dialog::backdrop {
  background: rgba(24, 32, 28, 0.38);
}

.material-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 20px;
}

.material-form label {
  display: grid;
  gap: 6px;
}

.material-form label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.material-form input,
.material-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
}

.material-form textarea {
  resize: vertical;
  line-height: 1.7;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.notes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.notes > div {
  padding: 18px;
}

.notes p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .practice-panel {
    order: 1;
  }

  .materials-panel {
    order: 2;
  }

  .result-panel {
    order: 3;
  }

  .materials-toggle {
    display: inline-flex;
    align-items: center;
  }

  .result-panel {
    max-height: none;
    overflow: visible;
  }
}

@media (min-width: 1181px) {
  .result-panel {
    position: sticky;
    top: 16px;
    max-height: max(480px, calc(100vh - 140px));
    overflow-y: auto;
  }
}

@media (max-width: 700px) {
  body::before {
    background-position: 18% bottom;
  }

  body::after {
    background: rgba(242, 247, 243, 0.64);
  }

  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 14px;
  }

  .topbar,
  .selected-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar .status-pill {
    white-space: normal;
  }

  .panel-heading {
    align-items: center;
  }

  h1 {
    font-size: 34px;
  }

  .reading-card {
    min-height: 180px;
    padding: 18px;
  }

  .reading-card p {
    font-size: 24px;
  }

  .material-item {
    grid-template-columns: 1fr;
  }

  .material-actions {
    justify-content: flex-end;
  }

  .score-grid,
  .notes {
    grid-template-columns: 1fr;
  }

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

  .score-card {
    min-height: 78px;
    padding: 12px;
  }

  .score-card strong {
    font-size: 30px;
  }

  .recorder > button {
    flex: 1 1 100%;
  }

  .char-chip[data-message]::after {
    display: none;
  }
}
