:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --rail: #eef4f2;
  --ink: #182328;
  --muted: #66757c;
  --line: #d9e2e7;
  --accent: #14785f;
  --accent-soft: #e5f4ef;
  --blue: #25679a;
  --blue-soft: #e8f2fa;
  --amber: #936113;
  --amber-soft: #fff4dd;
  --red: #b24a3c;
  --red-soft: #fde8e3;
  --shadow: 0 18px 38px rgba(32, 47, 56, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  min-height: 68px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand {
  font-size: 21px;
  font-weight: 750;
  letter-spacing: 0;
}

.subbrand {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 11px;
  font-weight: 720;
}

.history-menu {
  position: relative;
}

.history-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  max-height: min(520px, calc(100vh - 92px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(23, 38, 45, 0.16);
  padding: 8px;
  z-index: 35;
}

.top-actions {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.top-actions.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.status-chip {
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.status-chip.ok {
  color: #17664c;
  border-color: #bad8ca;
  background: var(--accent-soft);
}

.status-chip.bad {
  color: var(--red);
  border-color: #edbeb5;
  background: var(--red-soft);
}

.app {
  display: block;
  min-height: calc(100vh - 68px);
}

.left-rail {
  border-right: 1px solid var(--line);
  background: var(--rail);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-zone {
  border: 1px dashed #aebdc5;
  border-radius: 8px;
  padding: 18px;
  background: #f8fafc;
}

.upload-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-title {
  font-weight: 750;
  font-size: 17px;
}

.upload-copy {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 8px 0 16px;
}

.file-button,
.primary-button,
.secondary-button,
.small-button,
.submit-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  font-weight: 650;
  text-decoration: none;
}

.file-button,
.primary-button,
.submit-button {
  background: var(--accent);
  color: #fff;
}

.file-button {
  width: 100%;
  margin-bottom: 9px;
}

.compact-file {
  width: auto;
  min-height: 32px;
  margin: 0;
  padding: 6px 11px;
  white-space: nowrap;
}

.file-button input {
  display: none;
}

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

.secondary-button {
  width: 100%;
}

.compact-action {
  width: auto;
  min-height: 32px;
  padding: 6px 10px;
  white-space: nowrap;
}

.small-button {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 12px;
}

.small-button.active {
  background: var(--blue-soft);
  border-color: #a9c7dc;
  color: var(--blue);
}

.small-button:disabled {
  cursor: not-allowed;
  color: #95a1a7;
  background: #eef2f4;
  border-color: #dce5e9;
}

.submit-button {
  width: 100%;
  margin: 12px 0 8px;
}

.rail-heading {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 750;
  margin-bottom: 10px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  padding: 9px 10px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px 34px;
  gap: 6px;
  align-items: stretch;
}

.history-export,
.history-delete {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.history-export {
  font-size: 12px;
  font-weight: 760;
}

.history-export:hover {
  color: var(--blue);
  border-color: #aacce2;
  background: var(--blue-soft);
}

.history-delete {
  font-size: 18px;
}

.history-delete:hover {
  color: var(--red);
  border-color: #e6b8af;
  background: var(--red-soft);
}

.history-title {
  font-weight: 680;
  font-size: 13px;
  line-height: 1.3;
}

.history-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.main-stage {
  min-width: 0;
  padding: 14px;
}

.empty-state {
  min-height: calc(100vh - 108px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.empty-title {
  font-size: 28px;
  font-weight: 780;
}

.empty-copy {
  margin-top: 10px;
  max-width: 560px;
  color: var(--muted);
  line-height: 1.7;
}

.empty-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.empty-actions .secondary-button {
  width: auto;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr);
  gap: 14px;
  min-height: calc(100vh - 96px);
}

.hidden {
  display: none !important;
}

.reader-pane,
.coach-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  min-width: 0;
}

.reader-pane {
  display: flex;
  flex-direction: column;
}

.pane-toolbar {
  min-height: 62px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.doc-title {
  font-size: 18px;
  font-weight: 780;
}

.doc-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

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

.article-view {
  padding: 16px clamp(18px, 3vw, 34px) 30px;
  overflow: auto;
  max-height: calc(100vh - 162px);
}

.section-block + .section-block {
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.section-title {
  font-weight: 780;
  font-size: 18px;
  margin-bottom: 12px;
}

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

.paragraph {
  position: relative;
  border-radius: 8px;
  padding: 14px 14px 12px;
  margin: 10px -14px;
  border: 1px solid transparent;
  transition:
    background 0.16s ease,
    opacity 0.16s ease,
    border-color 0.16s ease;
}

.paragraph:hover {
  background: #f8fbfc;
  border-color: #e2eaee;
}

.paragraph.selected {
  background: var(--accent-soft);
  border-color: #c3dfd1;
}

.paragraph.evidence {
  background: var(--amber-soft);
  border-color: #e8c17b;
}

.paragraph.word-focus {
  background: #edf7f4;
  border-color: #8cc9b7;
}

.spotlight .paragraph:not(.selected):not(.evidence) {
  opacity: 0.34;
}

.paragraph-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.para-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.paragraph-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  line-height: 1.9;
  letter-spacing: 0;
}

.word {
  border-bottom: 1px dotted #8ca4ad;
  cursor: help;
  border-radius: 2px;
}

.word:hover {
  background: var(--blue-soft);
}

.word.highlighted-word {
  background: #d5f0e6;
  border-bottom-color: var(--accent);
  box-shadow: inset 0 -0.32em 0 #bfe7d9;
}

.blank-button {
  min-width: 56px;
  min-height: 34px;
  margin: 0 4px;
  padding: 2px 10px;
  border-radius: 8px;
  border: 1px solid #b7d1c3;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  vertical-align: baseline;
}

.blank-button.answered {
  background: #d8ecf7;
  border-color: #9fc8df;
  color: var(--blue);
}

.coach-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #f7f3ea;
  color: var(--muted);
  font-weight: 700;
}

.tab:last-child {
  border-right: 0;
}

.tab.active {
  background: var(--surface-strong);
  color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.coach-content {
  padding: 16px;
  overflow: auto;
  max-height: calc(100vh - 154px);
}

.question-list,
.guide-list,
.vocab-list,
.review-list {
  display: grid;
  gap: 12px;
}

.question-card,
.guide-card,
.vocab-card,
.report-card,
.ocr-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.question-card.active {
  border-color: #9fc8df;
  background: var(--blue-soft);
}

.question-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.question-title {
  font-weight: 770;
}

.skill-badge {
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1px solid #dec18b;
  color: var(--amber);
  background: var(--amber-soft);
  font-size: 12px;
  padding: 3px 7px;
  max-width: 116px;
  overflow-wrap: anywhere;
}

.question-stem {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 10px;
}

.option-grid {
  display: grid;
  gap: 8px;
}

.option-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 32px;
  gap: 7px;
  align-items: stretch;
}

.option-key,
.eliminate-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  font-weight: 740;
}

.option-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  text-align: left;
  padding: 7px 10px;
  overflow-wrap: anywhere;
}

.option-button.selected {
  background: var(--accent-soft);
  border-color: #9bc9b8;
  color: var(--accent);
  font-weight: 720;
}

.option-row.eliminated .option-button,
.option-row.eliminated .option-key {
  color: #8f9699;
  text-decoration: line-through;
  background: #f0efeb;
}

.option-row.correct .option-button,
.option-row.correct .option-key {
  border-color: #8bbf9c;
  background: #e3f4e7;
}

.option-row.wrong .option-button,
.option-row.wrong .option-key {
  border-color: #e3aaa0;
  background: var(--red-soft);
}

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

.hint-box,
.evidence-box,
.feedback-box,
.word-result {
  margin-top: 10px;
  border-radius: 8px;
  padding: 10px;
  line-height: 1.6;
  font-size: 14px;
}

.assist-panel {
  border: 1px solid transparent;
}

.assist-title {
  font-weight: 820;
  color: var(--ink);
  margin-bottom: 4px;
}

.hint-box {
  background: var(--blue-soft);
  color: #214e68;
}

.evidence-box {
  background: var(--amber-soft);
  color: #604313;
}

.feedback-box {
  background: #edf4ed;
  color: #244a31;
}

.word-result {
  background: var(--blue-soft);
}

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

.guide-title,
.vocab-word,
.report-title {
  font-weight: 770;
}

.vocab-phonetic {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.vocab-audio {
  margin-top: 6px;
}

.guide-text,
.vocab-meaning,
.report-text {
  margin-top: 6px;
  line-height: 1.65;
  color: var(--muted);
}

.chunk-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.chunk {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 8px 10px;
  border-radius: 0 8px 8px 0;
}

.chunk:nth-child(2n) {
  border-left-color: var(--blue);
  background: var(--blue-soft);
}

.chunk-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 750;
}

.chunk-text {
  margin-top: 3px;
  line-height: 1.55;
}

.vocab-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  text-align: left;
}

.list-section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 4px 0 -4px;
}

.vocab-tag {
  font-size: 12px;
  border-radius: 8px;
  padding: 3px 7px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.score {
  font-size: 30px;
  font-weight: 800;
}

.score-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.weakness-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.weakness-tag {
  border-radius: 8px;
  padding: 5px 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 12px;
}

.wrong-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.wrong-pill {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 6px 9px;
  font-size: 12px;
}

.wrong-pill:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.ocr-pre {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  color: #39464a;
  font-size: 13px;
}

.lookup-popover,
.selection-popover {
  position: fixed;
  z-index: 45;
  width: min(310px, calc(100vw - 24px));
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  border: 1px solid #cfdbe2;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(23, 38, 45, 0.18);
  padding: 12px;
}

.selection-popover {
  width: min(360px, calc(100vw - 24px));
}

.lookup-popover::before,
.selection-popover::before {
  content: "";
  position: absolute;
  top: -7px;
  left: var(--arrow-left, 22px);
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-left: 1px solid #cfdbe2;
  border-top: 1px solid #cfdbe2;
  transform: rotate(45deg);
}

.lookup-popover.above-anchor::before,
.selection-popover.above-anchor::before {
  top: auto;
  bottom: -7px;
  border-top: 0;
  border-left: 0;
  border-right: 1px solid #cfdbe2;
  border-bottom: 1px solid #cfdbe2;
}

.popover-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
}

.popover-word {
  font-size: 20px;
  font-weight: 820;
}

.popover-line {
  margin-top: 3px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}

.popover-meaning {
  margin-top: 8px;
  color: var(--ink);
  line-height: 1.65;
}

.popover-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.popover-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.audio-button {
  min-height: 30px;
  border: 1px solid #c9d8de;
  border-radius: 8px;
  background: #f8fbfc;
  color: var(--blue);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 760;
}

.audio-button:hover {
  border-color: #9fc8df;
  background: var(--blue-soft);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  background: #1f2a2e;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-width: min(560px, calc(100vw - 32px));
}

.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(246, 248, 251, 0.72);
  display: grid;
  place-items: center;
  backdrop-filter: blur(8px);
}

.progress-panel {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(23, 38, 45, 0.18);
  padding: 18px;
}

.progress-title {
  font-size: 18px;
  font-weight: 820;
}

.progress-text {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

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

.progress-bar {
  width: 12%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}

.progress-bar.failed {
  background: var(--red);
}

.progress-steps {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress-step.active {
  color: var(--accent);
  font-weight: 780;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd8de;
}

.progress-step.active .progress-dot {
  background: var(--accent);
}

.loading {
  opacity: 0.72;
  pointer-events: none;
}

@media (max-width: 1080px) {
  .app {
    display: block;
  }

  .left-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: block;
  }
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .history-dropdown {
    position: fixed;
    top: 82px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - 94px);
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .coach-content,
  .article-view {
    max-height: none;
  }

  .paragraph-text {
    font-size: 18px;
    line-height: 1.85;
  }
}

@media (max-width: 560px) {
  .main-stage,
  .left-rail {
    padding: 12px;
  }

  .header-right,
  .top-actions {
    width: 100%;
  }

  .history-dropdown {
    top: 118px;
    max-height: calc(100vh - 130px);
  }

  .top-actions {
    justify-content: stretch;
  }

  .compact-file,
  .compact-action {
    flex: 1;
  }

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

  .tab {
    border-bottom: 1px solid var(--line);
  }

  .option-row {
    grid-template-columns: 30px minmax(0, 1fr) 30px;
  }
}
