:root {
  color-scheme: light;
  --bg: #eef2f3;
  --panel: #ffffff;
  --panel-soft: #f7f9fa;
  --ink: #182026;
  --muted: #64717d;
  --line: #dbe2e6;
  --accent: #1f7a6d;
  --accent-strong: #155f55;
  --accent-soft: #dff1ed;
  --warn: #b84d26;
  --warn-soft: #fff0e8;
  --ok: #247443;
  --shadow: 0 18px 45px rgba(22, 34, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 122, 109, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(184, 77, 38, 0.1), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
}

button,
select,
input {
  font: inherit;
  touch-action: manipulation;
}

button,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

button {
  min-height: 42px;
  padding: 0 15px;
  cursor: pointer;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

button:hover {
  border-color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

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

select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar h1,
.free-toolbar h2,
.couplet-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(28px, 4vw, 44px);
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.ready {
  background: var(--accent-soft);
  border-color: rgba(31, 122, 109, 0.3);
  color: var(--accent-strong);
}

.status-pill.warn {
  background: var(--warn-soft);
  border-color: rgba(184, 77, 38, 0.32);
  color: var(--warn);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tab-button {
  min-height: 46px;
  background: rgba(255, 255, 255, 0.76);
  font-weight: 700;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

#practicePanel {
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
}

#practicePanel.active {
  display: grid;
}

.sidebar,
.couplet-card,
.result-card,
.history-panel,
.free-main {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 226, 230, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  align-self: start;
  padding: 18px;
}

.section-title {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.practice-count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 14px 0 8px;
}

.practice-count strong {
  font-size: 40px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e5eaed;
  margin-bottom: 18px;
}

#progressFill {
  width: 0%;
  height: 100%;
  background: var(--accent);
}

.field-label {
  display: block;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.practice-main {
  display: grid;
  gap: 14px;
}

.couplet-card {
  padding: 20px;
}

.card-head,
.free-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.couplet-lines {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 18px 0;
}

.line-row {
  padding: 16px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.line-row.prompt-row {
  border-left: 4px solid #4c7ab8;
}

.line-row.target-row {
  border-left: 4px solid var(--accent);
  background: #f4fbf9;
}

.line-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.line-row span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.line-row p {
  margin: 14px 0 0;
  font-size: clamp(21px, 2.6vw, 30px);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: 0;
}

.line-row .line-explanation {
  margin-top: 10px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.55;
}

.line-read-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--accent-strong);
  background: #fff;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.target-box {
  min-height: 120px;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid rgba(31, 122, 109, 0.28);
  background: var(--accent-soft);
}

.target-text {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  font-size: clamp(22px, 3.1vw, 34px);
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: 0;
}

.target-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1em;
  min-height: 1.25em;
  border-radius: 8px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.72);
}

.target-char.match {
  background: rgba(36, 116, 67, 0.16);
  color: var(--ok);
}

.target-char.miss,
.target-char.sub {
  background: var(--warn-soft);
  color: var(--warn);
  outline: 1px solid rgba(184, 77, 38, 0.35);
}

.target-char.close {
  background: #fff7d6;
  color: #7a5a00;
  outline: 1px solid rgba(161, 119, 0, 0.35);
}

.target-space {
  width: 0.7em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.actions.compact {
  margin-top: 0;
}

.voice-hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.primary.listening {
  background: var(--warn);
  border-color: var(--warn);
}

.result-card {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 18px;
}

.score-ring {
  width: 116px;
  height: 116px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  border: 10px solid var(--line);
  background: #fff;
}

.score-ring.pass {
  border-color: rgba(36, 116, 67, 0.42);
}

.score-ring.fail {
  border-color: rgba(184, 77, 38, 0.45);
}

.score-ring span {
  font-size: 34px;
  font-weight: 900;
}

.score-ring small {
  color: var(--muted);
}

.heard-text {
  min-height: 32px;
  margin: 8px 0 10px;
  font-size: 22px;
  font-weight: 800;
  word-break: break-word;
}

.feedback {
  min-height: 28px;
  color: var(--muted);
  line-height: 1.55;
}

.word-issues {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.issue-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--warn-soft);
  border: 1px solid rgba(184, 77, 38, 0.28);
  color: var(--warn);
  font-weight: 700;
}

.history-panel {
  padding: 18px;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
  margin-top: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.history-item strong {
  color: var(--accent-strong);
}

.history-item p {
  margin: 0;
  color: var(--muted);
  word-break: break-word;
}

.free-main {
  padding: 20px;
  min-height: 640px;
}

.free-toolbar h2 {
  font-size: 28px;
}

.free-prompt {
  margin: 18px 0 14px;
  padding: 15px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid rgba(31, 122, 109, 0.25);
  font-size: 20px;
  font-weight: 800;
}

.chat-list {
  display: grid;
  gap: 12px;
  max-height: 480px;
  overflow: auto;
  padding-right: 4px;
}

.chat-bubble {
  width: min(720px, 88%);
  padding: 13px 15px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.chat-bubble.user {
  justify-self: end;
  background: #f2f6f7;
}

.chat-bubble.system {
  justify-self: start;
  background: var(--accent-soft);
  border-color: rgba(31, 122, 109, 0.25);
}

.chat-bubble span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chat-bubble p {
  margin: 0;
  font-size: 20px;
  line-height: 1.5;
  word-break: break-word;
}

@media (max-width: 860px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  button,
  select,
  input {
    font-size: 16px;
  }

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

  .topbar,
  .card-head,
  .free-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  #practicePanel.active,
  .couplet-lines,
  .result-card {
    grid-template-columns: 1fr;
  }

  .result-card {
    align-items: start;
  }

  .score-ring {
    width: 104px;
    height: 104px;
  }

  .actions,
  .actions.compact {
    display: grid;
    grid-template-columns: 1fr;
  }

  .chat-bubble {
    width: 96%;
  }
}
