:root {
  --primary: #1e40af;
  --primary-2: #3b82f6;
  --cta: #15803d;
  --cta-hover: #166534;
  --bg: #eff6ff;
  --surface: #ffffff;
  --text: #1e3a8a;
  --muted: #475569;
  --line: #dbeafe;
  --danger: #b91c1c;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(30, 64, 175, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, a.btn { cursor: pointer; }
:focus-visible { outline: 3px solid var(--primary-2); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: -999px;
}
.skip-link:focus { left: 1rem; top: 1rem; background: #fff; padding: 0.5rem; }

.wrap { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  gap: 1rem;
}
.logo { font-weight: 700; font-size: 1.2rem; color: var(--primary); text-decoration: none; }
.nav { display: flex; gap: 0.9rem; align-items: center; flex-wrap: wrap; }
.nav a { color: var(--text); font-weight: 500; text-decoration: none; }
.nav a:hover { color: var(--primary-2); }
.inline { display: inline; margin: 0; }
.linkish {
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  padding: 0;
}
.linkish:hover { color: var(--primary-2); text-decoration: underline; }

.hero, .card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.hero h1 { margin-top: 0; }
.muted { color: var(--muted); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: var(--primary);
  transition: background 180ms ease, transform 180ms ease;
}
.btn:hover { background: #1d4ed8; text-decoration: none; }
.btn-cta { background: var(--cta); color: #fff; }
.btn-cta:hover { background: var(--cta-hover); }
.btn-ghost {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.9rem; }

label { display: block; font-weight: 600; margin: 0.8rem 0 0.3rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"],
input[type="date"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  background: #fff;
  color: #0f172a;
}
textarea { min-height: 110px; }
.help { color: var(--muted); font-size: 0.9rem; }
.errorlist { color: var(--danger); padding-left: 1.1rem; }
.guide-text {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  font-size: 0.88rem;
  line-height: 1.45;
  max-height: 70vh;
  overflow: auto;
  margin: 1rem 0 0;
}

.messages { list-style: none; padding: 0; }
.msg { padding: 0.75rem 1rem; border-radius: 10px; margin: 1rem 0; }
.msg.success { background: #dcfce7; color: #14532d; }
.msg.error { background: #fee2e2; color: #7f1d1d; }
.msg.info, .msg.warning { background: #fef3c7; color: #78350f; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.7rem; border-bottom: 1px solid var(--line); }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: #dbeafe;
  color: var(--primary);
}
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.bad { background: #fee2e2; color: var(--danger); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.muted { background: #f1f5f9; color: var(--muted); }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }
.block-card { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin: 1rem 0; }
.block-card.task { border-color: #93c5fd; }
.block-card.correct { border-color: var(--ok); background: #f0fdf4; }
.block-card.incorrect { border-color: var(--danger); background: #fef2f2; }
.block-card.skipped { border-color: #cbd5e1; background: #f8fafc; }
.block-card.choice-block,
.block-card.choice-block.task,
.block-card.choice-block.correct,
.block-card.choice-block.incorrect,
.block-card.choice-block.skipped {
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 0.12rem 0;
  margin: 0;
}

.player {
  display: block;
  margin: 1.5rem 0;
}
.player-flow {
  width: min(42rem, 100%);
  margin: 0 auto;
}
.lesson-flow {
  margin: 2rem 0 2.75rem;
}
.lesson-flow > h2 {
  font-size: 1.1rem;
  margin: 0 0 1rem;
}
.toc { position: sticky; top: 84px; align-self: start; }
.toc a { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.35rem 0; color: inherit; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.dot.correct { background: var(--ok); }
.dot.incorrect { background: var(--danger); }
.dot.skipped { background: #94a3b8; }
.dot.awaiting_review, .dot.reviewed { background: var(--warn); }

.option {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  margin: 0.4rem 0;
}
.choice-select,
.open-input {
  width: 100%;
  max-width: 28rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  margin: 0.4rem 0;
}
.choice-prompt {
  margin: 0;
  font-size: 1rem;
  line-height: 1.65;
}
.choice-gap {
  display: inline-flex;
  align-items: baseline;
  vertical-align: baseline;
  margin: 0 0.12em;
  padding: 0 0.12em 0 0.28em;
  border: 1px solid var(--line);
  border-left: 2px dashed #93c5fd;
  border-radius: 6px;
  background: #fff;
}
.choice-gap.preview-answer {
  padding: 0.02em 0.5em 0.04em 0.55em;
  flex-wrap: wrap;
  max-width: 100%;
  font-weight: 400;
}
.choice-gap.preview-answer .preview-option.is-correct,
.choice-gap.preview-answer strong {
  font-weight: 700;
}
.choice-pair {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.1rem;
  margin-top: 0.2rem;
}
.gap-cluster .choice-pair { margin-top: 0; }
.choice-or {
  color: var(--muted);
  font-weight: 500;
  margin: 0 0.2em;
}
.choice-token {
  display: inline-flex;
  align-items: baseline;
  margin: 0;
  padding: 0 0.2em;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
}
.choice-token:hover { border-color: var(--line); }
.choice-token input,
.choice-gap input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.choice-select-gap {
  width: auto;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  display: inline;
  margin: 0;
  padding: 0 1.05em 0 0.15em;
  vertical-align: baseline;
  font: inherit;
  font-weight: 600;
  color: inherit;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23475569' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.1em center;
  background-size: 0.65em;
  appearance: none;
  cursor: pointer;
}
.choice-select-gap:disabled {
  opacity: 1;
  color: inherit;
  cursor: default;
  background-image: none;
  padding-right: 0.1em;
}
.choice-select-gap:focus {
  outline: none;
}
input.open-input-gap {
  width: auto;
  max-width: 100%;
  min-width: 8ch;
  min-height: 0;
  height: 1.35em;
  line-height: 1.35;
  display: inline;
  margin: 0;
  padding: 0 0.1em;
  border: 0;
  border-radius: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: inherit;
}
input.open-input-gap:disabled {
  opacity: 1;
  color: inherit;
}
input.open-input-gap:focus {
  outline: none;
}
input.open-input-gap::placeholder {
  color: #94a3b8;
  font-weight: 600;
  opacity: 1;
}
.choice-gap:focus-within {
  border-left-style: solid;
  border-color: var(--primary-2);
}
.choice-gap.is-ok:focus-within { border-left-color: var(--ok); }
.choice-gap.is-bad:focus-within { border-left-color: var(--danger); }
.cloze-passage { line-height: 1.9; }
.cloze-passage .js-choice,
.cloze-passage .js-open,
.cloze-passage .task-main { display: contents; }
.cloze-answer { margin-left: 0.25em; font-size: 0.9em; }
.gap-cluster {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  vertical-align: middle;
  margin: 0 0.08em;
}
.choice-prompt + .gap-cluster,
.gap-cluster-block {
  display: flex;
  align-items: flex-start;
  margin: 0.35rem 0 0.15rem;
}
.attempt-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.gap-cluster .attempt-dots {
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.attempt-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1.5px solid #93c5fd;
  background: transparent;
}
.attempt-dot.is-ok { background: var(--ok); border-color: var(--ok); }
.attempt-dot.is-bad { background: var(--danger); border-color: var(--danger); }
.note-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 180ms ease, background 180ms ease;
}
.note-btn:hover { color: var(--primary); background: #eff6ff; }
.note-btn.has-note { color: var(--primary); }
.note-btn svg { width: 14px; height: 14px; display: block; }
.note-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  width: min(26rem, calc(100% - 2rem));
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.note-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}
.note-dialog h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}
.note-dialog .muted { margin: 0 0 0.7rem; }
.note-dialog textarea { min-height: 7rem; }
.review-answer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.attempt-list { margin: 0.35rem 0 0.6rem; padding-left: 1.2rem; }
.word-bank {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
}
.block-card.choice-block.meaning-item,
.block-card.choice-block.task.meaning-item,
.block-card.choice-block.correct.meaning-item,
.block-card.choice-block.incorrect.meaning-item,
.block-card.choice-block.skipped.meaning-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.9rem 1rem 0.8rem;
  margin: 1.15rem 0;
}
.block-card.choice-block.correct.meaning-item {
  border-color: #86efac;
  background: #f0fdf4;
}
.block-card.choice-block.incorrect.meaning-item {
  border-color: #fca5a5;
  background: #fef2f2;
}
.meaning-item .choice-prompt { margin-bottom: 0.15rem; }
.meaning-item .gap-cluster,
.meaning-item .choice-prompt + .gap-cluster {
  margin-top: 0.55rem;
}
.meaning-pair { margin: 0; }
.meaning-pair p { margin: 0.12rem 0; }
.student-note { margin-top: 0.5rem; }
.invite { font-family: ui-monospace, monospace; font-size: 1.1rem; }

.folder-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.view-toggle { display: inline-flex; gap: 0.35rem; }
.tag-filter { margin-top: 0.5rem; }
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.4rem 0;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  background: #f8fafc;
  cursor: pointer;
}
.tag-chip input { width: auto; margin: 0; }
.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}
.folder-tile {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 180ms ease, box-shadow 180ms ease;
  cursor: pointer;
}
.folder-tile:hover {
  text-decoration: none;
  border-color: #93c5fd;
  box-shadow: 0 10px 28px rgba(30, 64, 175, 0.12);
}
.folder-cover,
.folder-cover.placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: linear-gradient(135deg, #dbeafe, #eff6ff);
}
.folder-cover-sm {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.folder-cover-preview {
  max-width: 240px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.folder-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.folder-row-main {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}
.option.correct-answer {
  border-color: var(--ok);
  background: #f0fdf4;
}
.block-card.tutor-only {
  border-style: dashed;
  background: #fffbeb;
}
.lesson-cover {
  background: linear-gradient(135deg, #e2e8f0, #f8fafc) !important;
}
.assign-tree {
  list-style: none;
  padding: 0;
  margin: 0;
}
.assign-tree ul {
  list-style: none;
  padding-left: 1.25rem;
  margin: 0.25rem 0;
}
.assign-tree li {
  margin: 0.35rem 0;
}
.assign-tree .muted-row {
  opacity: 0.55;
}

@media (max-width: 800px) {
  .player { grid-template-columns: 1fr; }
  .toc { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
