:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-strong: #fdfdfb;
  --ink: #182025;
  --muted: #66727a;
  --line: #d9dee2;
  --line-strong: #bac3c9;
  --red: #b62935;
  --theme: #b62935;
  --theme-hover: #941f28;
  --theme-soft: #fff8f8;
  --theme-border: #e8c9ce;
  --theme-focus: rgba(182, 41, 53, 0.2);
  --theme-wash: rgba(182, 41, 53, 0.08);
  --theme-rule: rgba(182, 41, 53, 0.12);
  --teal: #167a76;
  --gold: #bf812d;
  --green: #27825a;
  --shadow: 0 18px 50px rgba(17, 28, 35, 0.09);
  --chinese-font:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    sans-serif;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(245, 246, 247, 0.96)),
    repeating-linear-gradient(90deg, rgba(22, 122, 118, 0.06) 0 1px, transparent 1px 72px);
  color: var(--ink);
  min-width: 320px;
}

body[data-mode="reading"] {
  --theme: #2b7043;
  --theme-hover: #205936;
  --theme-soft: #f4fbf6;
  --theme-border: #bdd9c5;
  --theme-focus: rgba(43, 112, 67, 0.2);
  --theme-wash: rgba(43, 112, 67, 0.08);
  --theme-rule: rgba(43, 112, 67, 0.12);
}

body[data-mode="writing"] {
  --theme: #1f669f;
  --theme-hover: #18517f;
  --theme-soft: #f4f9fd;
  --theme-border: #bed2e6;
  --theme-focus: rgba(31, 102, 159, 0.2);
  --theme-wash: rgba(31, 102, 159, 0.08);
  --theme-rule: rgba(31, 102, 159, 0.12);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.noscript-message {
  margin: 12px auto 0;
  width: min(960px, calc(100% - 24px));
  border: 1px solid var(--theme-border);
  border-radius: 8px;
  background: var(--theme-soft);
  color: var(--ink);
  padding: 12px 14px;
  font-weight: 800;
}

.topbar,
.global-options,
.workspace-panel,
.results-table-wrap {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 92px;
  padding: 16px;
  border-radius: 8px 8px 0 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 236px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border: 1px solid var(--theme-border);
  background: var(--theme-soft);
  color: var(--theme);
  border-radius: 8px;
  font-size: 31px;
  font-weight: 800;
  line-height: 1;
}

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

.brand h1 {
  font-size: 21px;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.mode-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(104px, 1fr));
  gap: 8px;
  width: min(520px, 100%);
}

.mode-tab,
.primary-btn,
.secondary-btn,
.ghost-btn,
.icon-btn {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
  transition:
    background 140ms ease,
    color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

.mode-tab:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  border-color: var(--theme);
  transform: translateY(-1px);
}

.mode-tab.active {
  border-color: var(--theme);
  background: var(--theme);
  color: white;
}

.global-options {
  padding: 0;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 12px 35px rgba(17, 28, 35, 0.06);
  overflow: hidden;
}

.options-summary {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  list-style: none;
  text-transform: uppercase;
}

.options-summary::-webkit-details-marker {
  display: none;
}

.options-summary::after {
  content: "";
  display: block;
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--theme);
  border-bottom: 2px solid var(--theme);
  transform: rotate(45deg);
  transition: transform 140ms ease;
}

.global-options[open] .options-summary::after {
  transform: rotate(225deg);
}

.options-body {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px;
  align-items: center;
  gap: 14px;
  padding: 0 16px 14px;
}

.option-group,
.field {
  display: grid;
  gap: 7px;
}

.option-label,
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.level-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.level-check input {
  accent-color: var(--theme);
}

select {
  width: 100%;
}

select {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  padding: 0 10px;
  background: white;
  color: var(--ink);
}

.workspace {
  padding: 22px 0 0;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 18px;
}

.workspace-panel {
  border-radius: 8px;
  padding: 20px;
}

.mode-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.mode-heading h2 {
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

.mode-heading p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.session-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfbfb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.task-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 20px;
}

.preview-cell {
  min-height: 116px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(251, 252, 252, 0.95)),
    repeating-linear-gradient(0deg, transparent 0 27px, var(--theme-rule) 27px 28px);
}

.preview-cell strong {
  display: block;
  color: var(--theme);
  font-size: 34px;
  line-height: 1;
}

.preview-cell span {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.primary-btn {
  border-color: var(--theme);
  background: var(--theme);
  color: white;
  font-weight: 800;
  padding: 0 18px;
}

.primary-btn:hover {
  background: var(--theme-hover);
}

.secondary-btn,
.ghost-btn,
.icon-btn {
  padding: 0 14px;
  font-weight: 800;
}

.secondary-btn {
  background: var(--theme-soft);
  color: var(--theme);
  border-color: var(--theme-border);
}

.ghost-btn {
  background: transparent;
  box-shadow: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.session-shell {
  display: grid;
  gap: 16px;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}

.progress-track {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef1f2;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--theme), var(--gold));
}

.progress-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.sentence-card {
  display: grid;
  gap: 14px;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.sentence-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.sentence-text {
  font-size: 25px;
  line-height: 1.42;
  word-break: break-word;
}

.sentence-text.zh {
  line-height: 1.45;
}

.audio-sentence {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.shortcut-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.shortcut-hint {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
}

.shortcut-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
  color: currentColor;
  font-family: inherit;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.shortcut-separator,
.shortcut-plus {
  color: currentColor;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  opacity: 0.82;
}

.shortcut-plus {
  font-size: 12px;
  margin-left: 1px;
}

.secondary-btn .shortcut-hint kbd {
  border-color: var(--theme-border);
  background: rgba(255, 255, 255, 0.72);
}

.sound-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--theme-border);
  border-radius: 8px;
  background: var(--theme-soft);
  color: var(--theme);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.sound-indicator.active {
  display: inline-flex;
}

.audio-warning {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid #e2c2b5;
  border-radius: 8px;
  background: #fff8f4;
  color: #8f3d20;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.sound-bars {
  display: inline-flex;
  align-items: end;
  gap: 2px;
  height: 15px;
}

.sound-bars span {
  width: 3px;
  height: 7px;
  border-radius: 999px;
  background: var(--theme);
  animation: sound-pulse 680ms ease-in-out infinite;
}

.sound-bars span:nth-child(2) {
  animation-delay: 120ms;
}

.sound-bars span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes sound-pulse {
  0%,
  100% {
    height: 5px;
    opacity: 0.65;
  }

  50% {
    height: 15px;
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.answer-form {
  display: grid;
  gap: 12px;
}

textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: white;
  line-height: 1.5;
}

.chinese-text,
textarea[lang="zh-CN"] {
  font-family: var(--chinese-font);
  font-size: 25px;
  font-weight: 400;
}

textarea:focus,
select:focus,
button:focus-visible {
  outline: 3px solid var(--theme-focus);
  outline-offset: 2px;
}

.form-actions,
.result-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.feedback {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.feedback.good {
  border-color: #a8d6bf;
  background: #f5fbf7;
}

.feedback.review {
  border-color: #e2c2b5;
  background: #fff8f4;
}

.feedback-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 12px;
}

.answer-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.answer-box {
  min-height: 84px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.answer-box-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.answer-text,
.answer-box p {
  line-height: 1.45;
  word-break: break-word;
}

.annotated-chinese {
  display: grid;
  gap: 3px;
  overflow: visible;
}

.annotated-hanzi-line,
.annotated-pinyin-line {
  display: block;
  margin: 0;
  word-break: break-word;
}

.annotated-hanzi-line {
  overflow: visible;
  line-height: 1.45;
}

.annotated-pinyin-line {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

.annotated-word {
  position: relative;
  display: inline;
  margin: 0;
  padding: 0;
  border-radius: 5px;
  color: var(--ink);
  cursor: default;
  outline: none;
  text-decoration-color: transparent;
  text-decoration-line: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

.annotated-word.has-gloss {
  cursor: help;
}

.annotated-word.has-gloss:hover,
.annotated-word.has-gloss:focus-visible {
  background: linear-gradient(transparent 68%, var(--theme-soft) 68%);
  text-decoration-color: var(--theme);
}

.annotated-word.has-gloss::after {
  position: absolute;
  left: 50%;
  right: auto;
  bottom: calc(100% + 7px);
  z-index: 20;
  width: max-content;
  max-width: min(260px, calc(100vw - 24px));
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: 0 10px 24px rgba(31, 36, 42, 0.18);
  content: attr(data-gloss);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translate(-50%, 4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  white-space: normal;
}

.annotated-word.has-gloss[data-tooltip-align="left"]::after {
  left: 0;
  right: auto;
  transform: translate(0, 4px);
}

.annotated-word.has-gloss[data-tooltip-align="right"]::after {
  left: auto;
  right: 0;
  transform: translate(0, 4px);
}

.annotated-word.has-gloss:hover::after,
.annotated-word.has-gloss:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.annotated-word.has-gloss[data-tooltip-align="left"]:hover::after,
.annotated-word.has-gloss[data-tooltip-align="left"]:focus-visible::after,
.annotated-word.has-gloss[data-tooltip-align="right"]:hover::after,
.annotated-word.has-gloss[data-tooltip-align="right"]:focus-visible::after {
  transform: translate(0, 0);
}

.gloss-tooltip-measurer {
  position: fixed;
  top: -9999px;
  left: 0;
  z-index: -1;
  width: max-content;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  pointer-events: none;
  visibility: hidden;
  white-space: normal;
}

.annotation-punctuation {
  display: inline;
}

.annotation-pinyin-word,
.annotation-pinyin-punctuation {
  display: inline;
}

.annotation-pinyin-word + .annotation-pinyin-word::before,
.annotation-pinyin-punctuation + .annotation-pinyin-word::before,
.annotation-pinyin-word + .annotation-pinyin-punctuation::before {
  content: " ";
}

.side-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

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

.stat.wide {
  grid-column: 1 / -1;
}

.stat {
  min-height: 90px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fff;
}

.stat strong {
  display: block;
  font-size: 26px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.stat span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.level-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.level-counts span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 0;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfb;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-transform: none;
}

.script-board {
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--theme-wash), transparent 36%),
    linear-gradient(315deg, var(--theme-rule), transparent 44%),
    #fff;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
}

.script-board span {
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 1px solid rgba(24, 32, 37, 0.08);
  color: rgba(24, 32, 37, 0.72);
  font-size: 40px;
  font-weight: 800;
}

.results-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.results-header h2 {
  font-size: 28px;
  line-height: 1.15;
}

.results-header p {
  margin-top: 7px;
  color: var(--muted);
}

.results-header + .stat-grid {
  margin-bottom: 18px;
}

.results-table-wrap {
  border-radius: 8px;
  overflow: auto;
  max-height: 58vh;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
}

th {
  position: sticky;
  top: 0;
  background: #f8faf9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td.status-good {
  color: var(--green);
  font-weight: 900;
}

td.status-review {
  color: var(--red);
  font-weight: 900;
}

.empty-note {
  padding: 18px;
  border-radius: 8px;
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
}

@media (max-width: 980px) {
  .topbar,
  .global-options,
  .workspace-grid,
  .results-header {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-nav {
    width: 100%;
  }

  .options-body {
    display: grid;
    grid-template-columns: 1fr;
  }

  .mode-heading {
    display: grid;
  }

  .session-meta {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .workspace-panel {
    padding: 14px;
  }

  .options-summary {
    padding: 14px;
  }

  .options-body {
    padding: 0 14px 14px;
  }

  .mode-nav {
    grid-template-columns: 1fr;
  }

  .task-preview,
  .answer-pair,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .sentence-text {
    font-size: 21px;
  }

  .chinese-text {
    font-size: 23px;
  }
}
