:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #16201c;
  --muted: #5f6d66;
  --line: #d9e2dc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #dcefed;
  --warn: #a85514;
  --warn-soft: #fff1df;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --good: #177245;
  --good-soft: #e2f4e8;
  --body-text: #2e3934;
  --secondary-text: #394640;
  --shadow: rgba(38, 57, 47, 0.11);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0d1412;
  --surface: #111c19;
  --surface-2: #182622;
  --ink: #edf7f3;
  --muted: #a9bbb4;
  --line: #2a3d37;
  --accent: #2dd4bf;
  --accent-strong: #8ee9dd;
  --accent-soft: #123a35;
  --warn: #f3a952;
  --warn-soft: #3a2815;
  --bad: #ff8b82;
  --bad-soft: #3a1d1b;
  --good: #7ee0a5;
  --good-soft: #123321;
  --body-text: #d4e2dc;
  --secondary-text: #c0d0c8;
  --shadow: rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.06), transparent 290px),
    var(--bg);
}

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

button,
select,
input[type="text"],
input[type="password"],
textarea {
  border-radius: 8px;
}

button {
  border: 0;
  cursor: pointer;
  font-weight: 750;
}

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

.app-shell {
  min-height: 100vh;
}

.phase-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.wizard-card,
.quiz-card,
.formula-card {
  width: min(100%, 1120px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 42px var(--shadow);
}

.wizard-card {
  padding: clamp(20px, 3vw, 34px);
}

.quiz-card {
  max-width: 980px;
  padding: clamp(18px, 2.5vw, 30px);
  position: relative;
}

.formula-card {
  padding: clamp(20px, 3vw, 34px);
  position: relative;
}

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

.wizard-header h1,
.quiz-header h1,
.formula-header h1 {
  margin: 0;
  font-size: clamp(1.65rem, 3vw, 2.55rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.formula-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}

.formula-card .formula-header {
  padding-right: 56px;
}

.formula-back-icon {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 40;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 36%, var(--line));
  border-radius: 999px;
  box-shadow: 0 8px 20px var(--shadow);
}

.formula-back-icon svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.home-title-row,
.label-with-action {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.label-with-action {
  justify-content: flex-start;
}

.theme-control {
  display: grid;
  grid-template-columns: auto minmax(130px, 160px);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.theme-control select {
  min-height: 36px;
  padding: 7px 9px;
  font-size: 0.84rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.wizard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.wizard-panel,
.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.wizard-panel {
  padding: 18px;
}

.panel-title-row,
.topbar-actions,
.question-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.wizard-panel h2,
.type-panel h3 {
  margin: 0 0 14px;
  font-size: 1rem;
}

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

.advanced-settings {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.advanced-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  cursor: pointer;
  font-weight: 900;
  list-style: none;
}

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

.advanced-settings summary strong {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: right;
}

.advanced-settings .settings-grid {
  padding: 0 14px 14px;
}

.topic-filter-block {
  display: grid;
  grid-column: 1 / -1;
  gap: 10px;
}

.topic-filter-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.topic-filter-header h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.topic-filter-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.topic-filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topic-checklist {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 3px;
  align-items: start;
}

.topic-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
}

.topic-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 850;
  line-height: 1.3;
  min-height: 44px;
}

.topic-group summary strong {
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
  line-height: 1.25;
}

.topic-category-switch {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  margin: 0 10px 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 850;
}

.topic-category-switch input {
  width: 18px;
  height: 18px;
}

.topic-category-switch em {
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-style: normal;
  white-space: nowrap;
}

.topic-options {
  display: grid;
  gap: 6px;
  padding: 0 10px 10px;
}

.topic-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px;
  color: var(--ink);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.84rem;
  line-height: 1.3;
}

.topic-option input {
  width: 17px;
  height: 17px;
}

.topic-option em {
  color: var(--muted);
  font-style: normal;
  font-weight: 850;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

select,
input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

textarea {
  min-height: 128px;
  resize: vertical;
  line-height: 1.45;
}

.primary-button,
.secondary-button,
.ghost-button,
.segment {
  min-height: 42px;
  padding: 9px 13px;
}

.info-icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid #badbd6;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 950;
}

.info-icon-button.small {
  width: 24px;
  height: 24px;
  min-height: 24px;
  font-size: 0.78rem;
}

.info-icon-button svg,
.status-popover summary svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.info-icon-button.small svg {
  width: 14px;
  height: 14px;
}

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

:root[data-theme="dark"] .primary-button {
  color: #06201d;
}

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

.secondary-button {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.ghost-button {
  color: var(--ink);
  background: var(--surface-2);
}

.compact-button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.84rem;
}

.danger-button {
  color: var(--bad);
  background: var(--bad-soft);
}

.full-width,
.start-button {
  width: 100%;
}

.start-button {
  margin-top: 0;
}

.home-start-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px;
  margin-bottom: 18px;
}

.start-validation-message {
  margin: -4px 0 16px;
  padding: 10px 12px;
  color: var(--bad);
  background: var(--bad-soft);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 850;
}

.home-start-panel .start-button {
  min-height: 54px;
  font-size: 1.05rem;
}

.home-panel-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.home-panel-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.88rem;
}

.home-panel-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.home-panel-button.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--surface-2);
  border-radius: 10px;
}

.segment {
  color: var(--muted);
  background: transparent;
  border-radius: 8px;
}

.segment.active {
  color: var(--accent-strong);
  background: var(--surface);
  box-shadow: 0 1px 4px var(--shadow);
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.helper-text {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.auth-message {
  min-height: 22px;
  margin-top: 10px;
  font-size: 0.9rem;
  font-weight: 750;
}

.auth-message.good {
  color: var(--good);
}

.auth-message.bad {
  color: var(--bad);
}

.attempt-stats {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.attempt-card {
  padding: 10px;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.4;
}

.attempt-empty {
  padding: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.4;
}

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

.stat-tile {
  min-width: 0;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 8px;
}

.stat-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-tile strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
}

.attempt-history {
  display: grid;
  gap: 6px;
}

.attempt-history-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.82rem;
}

.attempt-history-row strong {
  color: var(--ink);
}

.session-chip,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 11px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 850;
  white-space: nowrap;
}

.type-panel {
  margin-top: 18px;
}

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

.type-pill {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.84rem;
}

.type-pill span:last-child {
  color: var(--muted);
  font-weight: 850;
}

.formula-list {
  display: grid;
  gap: 16px;
}

.formula-module {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.formula-module header span {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.formula-module h2 {
  margin: 5px 0 0;
  font-size: 1.15rem;
}

.formula-items {
  display: grid;
  gap: 9px;
}

.formula-item {
  display: grid;
  gap: 5px;
  padding: 12px;
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
}

.formula-item strong {
  font-size: 1.05rem;
}

.formula-item p {
  margin: 0;
  color: var(--secondary-text);
  font-size: 0.9rem;
  line-height: 1.45;
}

.info-step-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.info-step-grid div {
  display: grid;
  gap: 5px;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 8px;
}

.info-step-grid strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.info-step-grid span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

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

.status-popover {
  position: relative;
}

.status-popover summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  min-height: 42px;
  padding: 0;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  list-style: none;
}

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

.status-popover .status-strip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(480px, calc(100vw - 32px));
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 34px var(--shadow);
}

.status-popover:not([open]) .status-strip {
  display: none;
}

.status-block {
  display: grid;
  gap: 5px;
  padding: 11px 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.status-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-block strong {
  font-size: 1.05rem;
}

.progress-rail {
  height: 9px;
  margin-bottom: 14px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.question-card {
  padding: clamp(18px, 2.2vw, 26px);
}

.question-card.question-enter {
  animation: question-enter 220ms ease-out;
}

@keyframes question-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.question-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.question-card h2 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.question-prompt {
  max-width: 78ch;
  margin: 14px 0 18px;
  color: var(--body-text);
  line-height: 1.55;
}

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

.answer-form.answer-locked {
  opacity: 0.98;
}

.answer-form.answer-locked button,
.answer-form.answer-locked input,
.answer-form.answer-locked textarea,
.answer-form.answer-locked .option-row,
.answer-form.answer-locked .choice-option,
.answer-form.answer-locked .order-item,
.answer-form.answer-locked .group-card,
.answer-form.answer-locked .group-target-badge {
  cursor: default;
}

.answer-form.answer-locked button:disabled,
.answer-form.answer-locked input:disabled,
.answer-form.answer-locked textarea:disabled {
  opacity: 1;
}

.math sub,
.math sup {
  font-size: 0.72em;
  line-height: 0;
}

.math sub {
  vertical-align: sub;
}

.math sup {
  vertical-align: super;
}

.option-row,
.select-row,
.input-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.option-row:hover,
.select-row:hover,
.input-row:hover {
  border-color: #abc9c4;
}

.option-row.answer-correct,
.choice-option.answer-correct,
.order-item.answer-correct,
.group-card.answer-correct {
  background: var(--good-soft);
  border-color: var(--good);
}

.option-row.answer-wrong,
.choice-option.answer-wrong,
.order-item.answer-wrong,
.group-card.answer-wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}

.option-row.answer-correct span,
.choice-option.answer-correct span,
.order-item.answer-correct .order-text,
.group-card.answer-correct span {
  color: var(--good);
}

.option-row.answer-wrong span,
.choice-option.answer-wrong span,
.order-item.answer-wrong .order-text,
.group-card.answer-wrong span {
  color: var(--bad);
}

.option-row input {
  width: 18px;
  height: 18px;
}

.choice-field {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.choice-field:hover {
  border-color: #abc9c4;
}

.choice-field legend {
  padding: 0 4px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1.35;
}

.choice-options {
  display: grid;
  gap: 7px;
}

.compact-choice-options {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.choice-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 8px 9px;
  color: var(--ink);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 750;
  line-height: 1.35;
}

.choice-option input {
  width: 17px;
  height: 17px;
}

.group-task {
  display: grid;
  gap: 12px;
}

.group-instruction {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
  line-height: 1.35;
}

.group-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 9px;
}

.group-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  min-height: 88px;
  padding: 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
}

.group-card:hover {
  border-color: #abc9c4;
}

.group-card.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 42%, transparent);
}

.group-card span {
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1.35;
}

.group-card em {
  align-self: end;
  justify-self: start;
  max-width: 100%;
  padding: 5px 8px;
  overflow-wrap: anywhere;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 0.75rem;
  font-style: normal;
  font-weight: 850;
}

.group-card.assigned em {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

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

.group-target-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 10px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 36%, var(--line));
  border-radius: 999px;
  font-size: 0.86rem;
}

.group-target-badge strong {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  color: var(--surface);
  background: var(--accent);
  border-radius: 999px;
  font-size: 0.72rem;
}

.select-row,
.input-row {
  grid-template-columns: minmax(0, 1fr) minmax(170px, 260px);
}

.order-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.order-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 64px 42px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: default;
  touch-action: auto;
  user-select: none;
}

.order-item:hover {
  border-color: #abc9c4;
}

.order-item.dragging {
  border-color: var(--accent);
  box-shadow: 0 12px 26px var(--shadow);
  cursor: grabbing;
}

.order-rank {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 850;
}

.order-text {
  min-width: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.35;
}

.order-drag-handle {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  background: var(--surface-2);
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
}

.order-move-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.order-move-button {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 0.9rem;
}

.order-drag-handle span,
.order-drag-handle span::before,
.order-drag-handle span::after {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--muted);
  border-radius: 999px;
}

.order-drag-handle span {
  position: relative;
}

.order-drag-handle span::before,
.order-drag-handle span::after {
  content: "";
  position: absolute;
  left: 0;
}

.order-drag-handle span::before {
  top: -6px;
}

.order-drag-handle span::after {
  top: 6px;
}

body.order-dragging {
  cursor: grabbing;
}

.unit {
  color: var(--muted);
  font-weight: 750;
}

.question-actions {
  justify-content: flex-start;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.feedback {
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  line-height: 1.55;
}

.feedback.good {
  color: var(--good);
  background: var(--good-soft);
}

.feedback.partial {
  color: var(--warn);
  background: var(--warn-soft);
}

.feedback.bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.diagram-host {
  margin: 16px 0;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.diagram-zoom-trigger {
  display: grid;
  width: 100%;
  gap: 7px;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.diagram-host svg {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  max-height: 260px;
  display: block;
}

.diagram-hint {
  justify-self: end;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 850;
}

.diagram-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  background: rgba(11, 24, 21, 0.78);
}

.diagram-close {
  justify-self: end;
  min-height: 38px;
  padding: 8px 12px;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
}

.diagram-zoom-host {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
}

.diagram-zoom-host svg {
  width: min(96vw, 1040px);
  max-width: 100%;
  height: auto;
  max-height: 84vh;
  background: #fff;
  border-radius: 8px;
}

body.diagram-open {
  overflow: hidden;
}

body.modal-open {
  overflow: hidden;
}

.question-feedback-dialog {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(11, 24, 21, 0.62);
}

.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(11, 24, 21, 0.62);
}

.question-feedback-card {
  display: grid;
  gap: 12px;
  width: min(100%, 560px);
  max-height: min(86vh, 720px);
  overflow: auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 22px 46px var(--shadow);
}

.app-dialog-card {
  display: grid;
  gap: 12px;
  width: min(100%, 440px);
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 22px 46px var(--shadow);
}

.info-dialog-card {
  width: min(100%, 760px);
  max-height: min(88vh, 760px);
  overflow: auto;
}

.question-feedback-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.app-dialog-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.app-dialog-card p {
  margin: 0;
  color: var(--secondary-text);
  line-height: 1.5;
}

.info-dialog-card h3 {
  margin: 4px 0 0;
  font-size: 1rem;
}

.question-feedback-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.app-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.danger-confirm {
  background: var(--bad);
}

.danger-confirm:hover {
  background: #8f1c13;
}

.feedback-submit-status {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.feedback-submit-status.good {
  color: var(--good);
}

.feedback-submit-status.bad {
  color: var(--bad);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.summary-card {
  padding: 14px;
  background: var(--surface-2);
  border-radius: 8px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.5rem;
}

.module-report,
.stored-module-stats {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stored-module-stats {
  margin: 0;
  background: var(--surface-2);
}

.module-report h3,
.stored-module-stats h3 {
  margin: 0;
  font-size: 1rem;
}

.module-threshold {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.module-recommendation {
  margin: 0;
  color: var(--secondary-text);
  font-size: 0.9rem;
  line-height: 1.45;
}

.module-score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
}

.module-score-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  background: var(--surface-2);
  border-left: 4px solid var(--line);
  border-radius: 8px;
}

.module-score-card.good {
  border-color: var(--good);
}

.module-score-card.partial {
  border-color: var(--warn);
}

.module-score-card.bad {
  border-color: var(--bad);
}

.module-score-card strong {
  font-size: 0.84rem;
  line-height: 1.3;
}

.module-score-bar {
  height: 7px;
  overflow: hidden;
  background: #dfe8e2;
  border-radius: 999px;
}

.module-score-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.module-score-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.review-list {
  display: grid;
  gap: 8px;
  max-height: 42vh;
  overflow: auto;
}

.review-item {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border-left: 4px solid var(--line);
  font-size: 0.82rem;
  line-height: 1.35;
}

.review-item.good {
  border-color: var(--good);
}

.review-item.bad {
  border-color: var(--bad);
}

.review-item.partial {
  border-color: var(--warn);
}

.explanation {
  margin-top: 8px;
  color: var(--secondary-text);
}

@media (max-width: 860px) {
  .phase-screen {
    padding: 0;
    place-items: stretch;
  }

  .wizard-card,
  .quiz-card,
  .formula-card {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .wizard-grid,
  .settings-grid,
  .type-legend,
  .info-step-grid {
    grid-template-columns: 1fr;
  }

  .wizard-header,
  .quiz-header,
  .formula-header {
    align-items: stretch;
    flex-direction: column;
  }

  .home-start-panel {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .select-row,
  .input-row {
    grid-template-columns: 1fr;
  }

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

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="email"],
  input[type="search"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 520px) {
  .quiz-screen {
    overflow: hidden;
  }

  .wizard-card,
  .quiz-card,
  .formula-card {
    padding: 14px;
  }

  .quiz-card {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .quiz-header {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .quiz-header .session-chip {
    display: none;
  }

  .quiz-header h1 {
    display: none;
  }

  .topbar-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 6px;
    margin-left: auto;
    width: 100%;
  }

  .topbar-actions .primary-button,
  .topbar-actions .ghost-button,
  .topbar-actions .secondary-button,
  .status-popover summary {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 0.78rem;
  }

  .topbar-actions button {
    min-width: 0;
    white-space: normal;
    line-height: 1.08;
  }

  .status-popover summary {
    width: 34px;
    padding: 0;
  }

  .status-popover .status-strip {
    position: fixed;
    top: 58px;
    right: 8px;
    left: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: auto;
    padding: 8px;
  }

  .status-block {
    gap: 2px;
    padding: 8px;
  }

  .status-label {
    font-size: 0.66rem;
  }

  .status-block strong {
    font-size: 0.9rem;
  }

  .progress-rail {
    height: 6px;
    margin-bottom: 8px;
  }

  .question-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 14px;
  }

  .question-meta {
    flex: 0 0 auto;
    gap: 6px;
    margin-bottom: 7px;
  }

  .badge,
  .muted {
    font-size: 0.72rem;
  }

  .session-chip,
  .badge {
    min-height: 28px;
    padding: 4px 8px;
  }

  .question-card h2 {
    flex: 0 0 auto;
    font-size: 1rem;
  }

  .question-prompt {
    flex: 0 0 auto;
    max-height: 5.4em;
    margin: 7px 0 10px;
    padding: 8px 9px;
    overflow: auto;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .diagram-host {
    flex: 0 0 auto;
    margin: 6px 0;
    padding: 6px;
    max-height: 28vh;
  }

  .diagram-host svg {
    max-height: calc(28vh - 32px);
  }

  .diagram-hint {
    font-size: 0.68rem;
  }

  .answer-form {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    gap: 7px;
    margin: 0 0 8px;
    padding: 8px 2px 0 0;
    border-top: 1px solid var(--line);
  }

  .option-row,
  .select-row,
  .input-row,
  .order-item,
  .choice-field {
    gap: 8px;
    padding: 8px;
    font-size: 0.86rem;
  }

  .choice-field legend,
  .choice-option {
    font-size: 0.84rem;
  }

  .compact-choice-options {
    grid-template-columns: 1fr;
  }

  .group-card-grid {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .group-card {
    min-height: 70px;
    padding: 9px;
  }

  .group-badge-row {
    position: sticky;
    bottom: 0;
    padding-top: 7px;
    background: var(--surface);
  }

  .group-target-badge {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 0.78rem;
  }

  .order-list {
    gap: 7px;
  }

  .order-item {
    grid-template-columns: 28px minmax(0, 1fr) 56px 34px;
  }

  .order-rank {
    width: 26px;
    height: 26px;
    font-size: 0.76rem;
  }

  .order-text {
    font-size: 0.84rem;
  }

  .order-drag-handle {
    width: 32px;
    height: 32px;
    min-height: 32px;
  }

  .order-move-button {
    width: 25px;
    height: 30px;
    min-height: 30px;
  }

  select,
  input[type="text"],
  input[type="password"],
  textarea {
    min-height: 36px;
    padding: 7px 9px;
  }

  textarea {
    min-height: 112px;
  }

  .feedback {
    flex: 0 0 auto;
    max-height: 18vh;
    margin-top: 8px;
    padding: 10px;
    overflow: auto;
    font-size: 0.84rem;
    line-height: 1.35;
  }

  .question-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: 0 0 auto;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
  }

  .question-actions button {
    min-height: 34px;
    padding: 7px 6px;
    font-size: 0.76rem;
  }

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

  .module-score-grid {
    grid-template-columns: 1fr;
  }

  .question-feedback-dialog,
  .app-dialog {
    align-items: end;
    padding: 8px;
  }

  .question-feedback-card,
  .app-dialog-card {
    width: 100%;
    max-height: 88vh;
    padding: 14px;
  }

  .app-dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .advanced-settings summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .topic-filter-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topic-filter-actions {
    justify-content: stretch;
  }

      .topic-filter-actions button {
        flex: 1;
      }

  .topic-checklist {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .topic-group summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    padding: 11px 12px;
    font-size: 0.92rem;
    line-height: 1.28;
  }

  .topic-group summary span,
  .topic-group summary strong {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

      .topic-group summary strong {
        white-space: normal;
        font-size: 0.74rem;
      }

      .topic-category-switch {
        grid-template-columns: auto minmax(0, 1fr);
        margin: 0 10px 8px;
      }

      .topic-category-switch em {
        grid-column: 2;
        white-space: normal;
      }

      .topic-options {
        gap: 7px;
        padding: 0 10px 10px;
      }

  .topic-option {
    align-items: flex-start;
    gap: 8px;
    padding: 9px;
    font-size: 0.84rem;
  }

  .topic-option input {
    margin-top: 2px;
  }

  .topic-option em {
    align-self: start;
  }
}
