:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #65716d;
  --paper: #f5f2e9;
  --surface: #fffdf8;
  --surface-2: #ece8dc;
  --line: #d9d5c9;
  --green: #174f43;
  --green-2: #236c5b;
  --mint: #dcebe3;
  --amber: #e0a236;
  --amber-soft: #f7e8c9;
  --red: #a94736;
  --red-soft: #fae7e2;
  --shadow: 0 18px 44px rgba(35, 43, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  min-width: 320px;
}

button,
input { font: inherit; }

button { color: inherit; }

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(224, 162, 54, 0.42);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.library {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #f8f6ed;
  background:
    radial-gradient(circle at 5% -5%, rgba(224, 162, 54, 0.22), transparent 28%),
    var(--green);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 20;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 26px 22px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  color: #183d35;
  background: var(--amber-soft);
  font-family: Georgia, serif;
  font-weight: 700;
  letter-spacing: -0.06em;
}

.brand-block h1,
.topbar h2,
.section-heading h3,
.model-essay h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

.brand-block h1 { font-size: 1.3rem; }

.eyebrow,
.hero-label {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand-block .eyebrow { color: rgba(255, 255, 255, 0.58); }

.close-library,
.menu-button { display: none; }

.library-scrim[hidden] { display: none; }

.library-tools { padding: 18px 16px 12px; }

.search-box {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
}

.search-box input {
  width: 100%;
  color: #fff;
  background: transparent;
  border: 0;
  outline: 0;
}

.search-box input::placeholder { color: rgba(255, 255, 255, 0.5); }

.library-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.75rem;
}

.text-button {
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.essay-list {
  overflow-y: auto;
  padding: 4px 10px 28px;
  scrollbar-color: rgba(255, 255, 255, 0.26) transparent;
}

.essay-link {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 18px;
  align-items: start;
  gap: 10px;
  padding: 12px 10px;
  color: rgba(255, 255, 255, 0.72);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.essay-link:hover { background: rgba(255, 255, 255, 0.07); }

.essay-link.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.13);
}

.essay-number {
  padding-top: 2px;
  color: rgba(255, 255, 255, 0.42);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.essay-link strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.81rem;
  font-weight: 560;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.essay-status {
  width: 9px;
  height: 9px;
  margin-top: 4px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
}

.essay-status.started { border-color: var(--amber); background: var(--amber); }
.essay-status.complete { border-color: #8ed0b7; background: #8ed0b7; }

.workspace {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 0 46px 36px;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}

.topbar-title { min-width: 0; flex: 1; }
.topbar h2 { overflow: hidden; font-size: 1.5rem; text-overflow: ellipsis; white-space: nowrap; }

.progress-cluster { width: 190px; }

.progress-copy {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
}

.progress-copy strong { color: var(--green); }

.progress-track {
  height: 5px;
  margin-top: 7px;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 999px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--amber);
  border-radius: inherit;
  transition: width 220ms ease;
}

.lesson-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 34px;
  margin: 38px 0 28px;
  padding: 32px 34px;
  overflow: hidden;
  color: #f8f6ed;
  background: var(--green);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.lesson-hero::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -80px;
  bottom: -105px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  box-shadow: 0 0 0 28px rgba(255, 255, 255, 0.035), 0 0 0 58px rgba(255, 255, 255, 0.025);
}

.hero-label { color: #ebbd67; }

.prompt {
  max-width: 850px;
  margin: 8px 0 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.12rem, 2vw, 1.38rem);
  line-height: 1.5;
}

.hero-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; }
.source-note { color: rgba(255, 255, 255, 0.58); font-size: 0.75rem; }

.secondary-button,
.primary-button,
.answer-button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 9px;
  cursor: pointer;
}

.secondary-button {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.secondary-button:hover { background: rgba(255, 255, 255, 0.14); }

.lesson-score {
  position: relative;
  z-index: 1;
  min-width: 94px;
  align-self: center;
  text-align: center;
}

.lesson-score strong {
  display: block;
  color: #f0c977;
  font-family: Georgia, serif;
  font-size: 2.7rem;
  line-height: 1;
}

.lesson-score span { color: rgba(255, 255, 255, 0.62); font-size: 0.7rem; text-transform: uppercase; }

.model-essay {
  margin-bottom: 28px;
  padding: 28px 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.essay-text { max-width: 820px; }
.essay-text p { margin: 0 0 1.05em; font-family: Georgia, serif; font-size: 1.03rem; line-height: 1.72; }
.essay-text p:last-child { margin-bottom: 0; }

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

.criterion-tab {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: 62px;
  padding: 10px 12px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.criterion-tab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: transparent;
}

.criterion-tab.active { color: var(--green); }
.criterion-tab.active::after { background: var(--green); }
.tab-index { color: var(--amber); font-size: 0.67rem; font-weight: 800; }
.criterion-tab > span:nth-child(2) { font-size: 0.8rem; font-weight: 680; }
.criterion-tab small { color: var(--muted); font-size: 0.65rem; }

.activity-stage { padding-bottom: 38px; }

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

.section-heading.compact { align-items: center; }
.section-heading h3 { font-size: 1.65rem; }
.section-heading p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 0.88rem; }

.activity-pager { display: flex; align-items: center; gap: 8px; }
.activity-pager span { min-width: 48px; color: var(--muted); font-size: 0.75rem; text-align: center; }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--green);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.icon-button:hover { border-color: #a9b0a9; }
.icon-button:disabled { opacity: 0.38; cursor: default; }

.activity-card {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 26px rgba(35, 43, 39, 0.045);
}

.activity-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 22px;
}

.activity-type {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--green-2);
  font-size: 0.68rem;
  font-weight: 780;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.activity-header h4 { margin: 0; font-size: 1rem; }

.completion-badge {
  padding: 5px 9px;
  color: var(--green);
  background: var(--mint);
  border-radius: 999px;
  font-size: 0.67rem;
  font-weight: 700;
}

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

.sentence-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 12px;
  background: #faf8f1;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: grab;
  transition: border 140ms ease, transform 140ms ease, background 140ms ease;
}

.sentence-card:hover { border-color: #aab4ae; }
.sentence-card.dragging { opacity: 0.58; transform: scale(0.99); }
.sentence-card.correct { border-color: #78aa94; background: #edf6f0; }
.sentence-card.incorrect { border-color: #d99a8a; background: #fff4f1; }

.drag-handle { color: #9aa29e; font-size: 1rem; letter-spacing: -0.18em; }
.sentence-card p { margin: 0; font-family: Georgia, serif; line-height: 1.55; }

.move-controls { display: flex; gap: 4px; }
.move-button {
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.gap-passage {
  margin: 4px 0 20px;
  padding: 22px;
  font-family: Georgia, serif;
  font-size: 1.12rem;
  line-height: 1.7;
  background: #faf8f1;
  border-left: 4px solid var(--amber);
  border-radius: 0 10px 10px 0;
}

.inline-gap {
  display: inline-flex;
  min-width: 130px;
  vertical-align: baseline;
}

.inline-gap input,
.correction-input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #b9b9af;
  border-radius: 7px;
}

.inline-gap input.correct,
.correction-input.correct { border-color: #5c947c; background: #f0f8f3; }
.inline-gap input.incorrect,
.correction-input.incorrect { border-color: #c66d5c; background: #fff4f1; }

.word-bank,
.option-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 0 0 20px;
}

.word-option {
  min-height: 39px;
  padding: 7px 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.word-option:hover,
.word-option.selected { color: var(--green); border-color: var(--green); background: var(--mint); }

.collocation-note {
  margin: -8px 0 18px;
  color: var(--muted);
  font-size: 0.78rem;
}

.error-sentence {
  margin: 0 0 18px;
  padding: 22px;
  font-family: Georgia, serif;
  font-size: 1.1rem;
  line-height: 2.05;
  background: #faf8f1;
  border-radius: 10px;
}

.error-token {
  margin: 0 1px;
  padding: 2px 3px;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.25;
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.error-token:hover { background: var(--amber-soft); }
.error-token.selected { color: #fff; background: var(--green-2); }
.error-token.wrong-selection { color: #fff; background: var(--red); }
.error-token.insertion-point {
  min-width: 1.35em;
  margin: 0 3px;
  color: var(--amber);
  border: 1px dashed currentColor;
}
.error-token.insertion-point.selected { color: #fff; border-color: var(--green-2); }

.correction-row {
  display: grid;
  grid-template-columns: minmax(0, 300px) auto;
  align-items: end;
  justify-content: start;
  gap: 12px;
  margin-bottom: 18px;
}

.correction-row label { display: grid; gap: 6px; color: var(--muted); font-size: 0.75rem; }

.activity-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.primary-button {
  color: #fff;
  background: var(--green);
  border: 1px solid var(--green);
  font-weight: 680;
}

.primary-button:hover { background: var(--green-2); }

.answer-button {
  color: var(--green);
  background: transparent;
  border: 1px solid var(--line);
}

.feedback {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 9px;
}

.feedback strong { display: block; margin-bottom: 3px; font-size: 0.82rem; }
.feedback p { margin: 0; font-size: 0.82rem; line-height: 1.45; }
.feedback.success { color: #285c48; background: var(--mint); }
.feedback.error { color: #823a2d; background: var(--red-soft); }
.feedback.answer { color: #75500e; background: var(--amber-soft); }

.empty-state {
  padding: 36px;
  color: var(--muted);
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.footer-note {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-top: 18px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 285px minmax(0, 1fr); }
  .workspace { padding-inline: 30px; }
  .criterion-tab { grid-template-columns: auto 1fr; }
  .criterion-tab small { display: none; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .library {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-102%);
    transition: transform 180ms ease;
  }
  .library.open { transform: translateX(0); }
  .library-scrim {
    position: fixed;
    inset: 0;
    display: block;
    background: rgba(17, 24, 22, 0.45);
    z-index: 15;
  }
  .close-library { display: grid; margin-left: auto; color: #fff; background: transparent; border-color: rgba(255, 255, 255, 0.25); }
  .menu-button { display: grid; flex: 0 0 38px; }
  .workspace { padding-inline: 22px; }
  .topbar { min-height: 80px; }
  .progress-cluster { width: 120px; }
  .lesson-hero { margin-top: 26px; }
  .criterion-tabs { grid-template-columns: repeat(2, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
  .criterion-tab { border-bottom: 1px solid var(--line); }
  .criterion-tab:nth-child(odd) { border-right: 1px solid var(--line); }
  .criterion-tab::after { display: none; }
  .criterion-tab.active { background: var(--mint); }
}

@media (max-width: 560px) {
  .workspace { padding-inline: 14px; }
  .topbar-title .eyebrow { display: none; }
  .topbar h2 { font-size: 1.1rem; }
  .progress-cluster { width: 90px; }
  .progress-copy span { display: none; }
  .lesson-hero { grid-template-columns: 1fr; padding: 25px 22px; border-radius: 14px; }
  .lesson-score { display: none; }
  .prompt { font-size: 1.06rem; }
  .model-essay { padding: 22px; }
  .criterion-tab { min-height: 56px; padding: 8px; }
  .criterion-tab > span:nth-child(2) { font-size: 0.72rem; }
  .section-heading { align-items: center; }
  .section-heading h3 { font-size: 1.32rem; }
  .section-heading p:last-child { display: none; }
  .activity-card { padding: 20px 16px; }
  .sentence-card { grid-template-columns: 20px minmax(0, 1fr); }
  .move-controls { grid-column: 2; }
  .correction-row { grid-template-columns: 1fr; }
  .footer-note { display: grid; }
}

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