:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --fg: #17202a;
  --muted: #5f6f82;
  --line: #dfe5ec;
  --line-strong: #b8c4d1;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-teal: #0f766e;
  --accent-warm: #d97706;
  --accent-soft: #eef5ff;
  --ink-soft: #334155;
  --success-bg: #eef7f0;
  --success-fg: #23613a;
  --warn-bg: #fff7e8;
  --warn-fg: #8a5a00;
  --fail-bg: #fff0f0;
  --fail-fg: #a83333;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 10px 28px rgb(15 23 42 / 0.06);
  --shadow-strong: 0 18px 48px rgb(15 23 42 / 0.12);
  --radius: 8px;
  --surface-gradient: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgb(37 99 235 / 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgb(15 118 110 / 0.04) 1px, transparent 1px),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 46%, #eef7f4 100%);
  background-size: 28px 28px, 28px 28px, auto;
  color: var(--fg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 0.95);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 34px rgb(37 99 235 / 0.07);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 20px;
}

.brand,
.site-nav,
.text-button,
.secondary-link {
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  font-weight: 800;
  min-width: 0;
}

.brand span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.brand-mark {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #17202a 0%, var(--accent) 58%, var(--accent-teal) 100%);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 8px 18px rgb(37 99 235 / 0.22);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  min-height: 40px;
  padding: 0 12px;
}

.site-nav a,
.text-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--fg);
  font-size: 0.92rem;
  font-weight: 700;
  padding: 0 12px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.site-nav a:hover,
.text-button:hover {
  border-color: var(--line-strong);
  background: var(--panel-soft);
}

.site-nav a.is-active,
.site-nav a[aria-current="page"] {
  border-color: rgb(37 99 235 / 0.34);
  background:
    linear-gradient(135deg, rgb(37 99 235 / 0.1), rgb(15 118 110 / 0.08)),
    #fff;
  color: var(--accent-dark);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.page-title {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 28px 0 20px;
  border: 1px solid rgb(191 212 255 / 0.8);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgb(255 255 255 / 0.94), rgb(239 248 246 / 0.92)),
    #fff;
  box-shadow: var(--shadow);
  padding: 22px 24px;
  overflow: hidden;
}

.page-title::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-teal), var(--accent-warm));
}

.page-title > * {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

h1,
h2 {
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

h1 {
  margin: 0 0 10px;
  font-size: 2.1rem;
  line-height: 1.15;
  font-weight: 850;
}

h2 {
  margin: 0;
}

p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.panel,
.problem-card,
.empty-state {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-gradient);
  box-shadow: var(--shadow);
}

.panel {
  padding: 24px;
}

.auth-layout {
  display: grid;
  min-height: calc(100vh - 120px);
  place-items: center;
  padding: 40px 0;
}

.auth-panel {
  display: grid;
  width: min(100%, 420px);
  gap: 18px;
}

.auth-panel h1 {
  margin: 0;
  font-size: 1.6rem;
}

.auth-error {
  width: 100%;
  max-width: none;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: var(--fail-bg);
  color: var(--fail-fg);
  font-weight: 800;
  padding: 10px 12px;
}

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

.home-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
  gap: 18px;
  margin-bottom: 24px;
}

.simple-title {
  align-items: flex-start;
  margin: 28px 0 18px;
}

.simple-title h1 {
  margin-bottom: 8px;
}

.preview-panel {
  position: sticky;
  top: 78px;
  display: grid;
  gap: 20px;
}

.section-heading {
  display: grid;
  gap: 6px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.1rem;
}

.section-heading h2::before {
  content: "";
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-teal));
  box-shadow: 0 0 0 4px rgb(37 99 235 / 0.09);
}

.notice-box {
  display: grid;
  gap: 4px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 12px;
}

.notice-box,
.panel-lite,
.advanced-details,
.mini-card,
.compact-list a,
.lesson-details,
.lecture-answer,
.solve-result,
.rendered-table,
.study-graph,
.formula-text {
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.8);
}

.notice-box strong,
.notice-box span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.generator-form {
  position: relative;
  display: grid;
  gap: 18px;
  overflow: hidden;
}

.generator-form::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-teal), var(--accent-warm));
}

.form-section {
  display: grid;
  gap: 16px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-of-type {
  padding-bottom: 0;
  border-bottom: 0;
}

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

.form-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--fg);
  font-weight: 700;
  min-width: 0;
}

label span,
.format-fieldset legend {
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
  padding: 0 12px;
  box-shadow: inset 0 1px 0 rgb(15 23 42 / 0.03);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus,
input:focus,
textarea:focus {
  outline: 3px solid rgb(37 99 235 / 0.16);
  border-color: var(--accent);
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgb(37 99 235 / 0.22);
  outline-offset: 2px;
}

textarea {
  min-height: 112px;
  padding: 12px;
  resize: vertical;
}

.full-width {
  display: grid;
}

.format-fieldset {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

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

.mode-row label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}

.mode-row label:has(input:checked),
.check-row:has(input:checked) {
  border-color: rgb(37 99 235 / 0.42);
  background: linear-gradient(180deg, #fff 0%, #f4f8ff 100%);
  box-shadow: 0 8px 18px rgb(37 99 235 / 0.08);
}

.mode-row input {
  min-height: auto;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.format-fieldset legend {
  padding: 0 8px;
  font-weight: 800;
}

.field-help {
  font-size: 0.88rem;
}

.format-list,
.weight-grid,
.check-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.check-row {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
  padding: 8px 10px;
}

.panel-lite {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #fff 0%, var(--panel-soft) 100%);
  padding: 16px;
}

.panel-lite h3 {
  margin: 0;
  font-size: 1rem;
}

.is-disabled {
  opacity: 0.45;
}

.is-disabled span {
  color: var(--muted);
}

.bare-check {
  align-self: end;
}

.quick-exam-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid #bfd4ff;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgb(37 99 235 / 0.08), rgb(15 118 110 / 0.08)),
    #fff;
  padding: 12px;
  box-shadow: inset 0 1px 0 #fff;
}

.quick-exam-row p {
  max-width: none;
  font-size: 0.92rem;
}

.compact-check {
  display: inline-grid;
  width: auto;
  min-width: 0;
  min-height: 40px;
  padding: 7px 10px;
}

.check-row input {
  min-height: auto;
}

.with-top-space {
  align-content: end;
  padding-top: 22px;
}

.form-actions,
.action-panel,
.action-group,
.print-links,
.problem-actions,
.mini-actions,
.print-actions,
.view-toggle-panel {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-panel {
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 0.98), rgb(239 246 255 / 0.82)),
    #fff;
}

.action-group {
  flex-wrap: wrap;
}

.save-set-form,
.compact-action-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.save-set-form input,
.compact-action-form input,
.compact-action-form select,
.preset-save-field input,
.rename-form input {
  min-width: 180px;
}

.preset-save-field {
  min-width: min(220px, 100%);
}

.secondary-link,
.print-links a {
  color: var(--accent);
  font-weight: 800;
}

.inline-form {
  margin: 0;
}

button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-teal));
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  padding: 0 16px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover {
  background: linear-gradient(135deg, var(--accent-dark), #0b6f68);
}

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--fg);
}

.secondary-button:hover {
  background: var(--panel-soft);
}

.danger-button {
  border-color: #fecdca;
  background: #fff;
  color: var(--fail-fg);
}

.danger-button:hover {
  background: var(--fail-bg);
}

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

.problem-list {
  display: grid;
  gap: 16px;
  margin: 0 0 48px;
}

.problem-card,
.empty-state {
  position: relative;
  padding: 20px;
  overflow: hidden;
}

.problem-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-teal));
}

.problem-card > *,
.empty-state > * {
  position: relative;
  z-index: 1;
}

.list-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.list-card > * {
  min-width: 0;
}

.view-toggle-panel {
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.problem-actions {
  flex-wrap: wrap;
  align-items: stretch;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.problem-help-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.problem-card h2,
.empty-state h2 {
  margin: 12px 0;
  font-size: 1.12rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.question-text,
.answer-text,
.explanation-text {
  max-width: none;
  color: var(--fg);
  font-size: 1rem;
  line-height: 1.7;
}

.problem-card h2 a {
  text-decoration: none;
}

.problem-card h2 a:hover {
  color: var(--accent);
}

.rendered-asset {
  max-width: 100%;
  margin: 14px 0;
  overflow-x: auto;
}

.rendered-asset img {
  display: block;
  max-width: min(100%, 560px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rendered-table {
  border-collapse: collapse;
  min-width: 280px;
  background: #fff;
}

.rendered-table th,
.rendered-table td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: center;
}

.rendered-table th {
  background: #edf2f7;
}

.problem-meta {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  gap: 8px;
}

.problem-meta span,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgb(255 255 255 / 0.92);
  font-size: 0.8rem;
  font-weight: 800;
  max-width: 100%;
  min-width: 0;
  line-height: 1.25;
  overflow-wrap: anywhere;
  white-space: normal;
}

.problem-meta span:first-child {
  border-color: rgb(37 99 235 / 0.2);
  color: var(--ink-soft);
}

.status-generated,
.status-auto_validated,
.status-rendered,
.status-success {
  border-color: #b7e4c7;
  background: var(--success-bg);
  color: var(--success-fg);
}

.status-generating,
.status-pending_validation,
.status-needs_review,
.status-manual_review_required {
  border-color: #fedf89;
  background: var(--warn-bg);
  color: var(--warn-fg);
}

.status-failed,
.status-partially_failed,
.status-generation_failed,
.status-validation_failed,
.status-validation_error,
.status-render_failed,
.status-provider_error,
.status-response_error,
.status-rate_limited,
.status-network_error,
.status-configuration_error {
  border-color: #fecdca;
  background: var(--fail-bg);
  color: var(--fail-fg);
}

details {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.option-details {
  margin-top: 2px;
}

summary {
  cursor: pointer;
  min-height: 40px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.option-body {
  display: grid;
  gap: 14px;
  padding-top: 14px;
}

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

.simple-check {
  min-height: 44px;
  align-self: end;
}

.advanced-details {
  margin-top: 0;
  border: 1px solid #d5e2f2;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
  padding: 0;
}

.advanced-details summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
}

.advanced-details summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

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

.advanced-details[open] summary {
  border-bottom: 1px solid var(--line);
}

.advanced-option-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.preset-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.plan-box {
  display: grid;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.plan-box button {
  justify-self: start;
}

.recent-panel {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  scrollbar-gutter: stable;
}

.saved-preset-list {
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.saved-preset-list h3 {
  margin: 0;
  font-size: 0.95rem;
}

.saved-preset-list button {
  justify-content: start;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: left;
}

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

.option-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.option-list-item strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.page-note {
  max-width: none;
  margin: 0 0 42px;
  color: var(--muted);
  font-size: 0.9rem;
}

.warning-text {
  margin-top: 12px;
  color: var(--warn-fg);
  font-weight: 700;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 8px;
}

.filter-panel {
  margin-bottom: 16px;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 0.96), rgb(248 250 252 / 0.9)),
    #fff;
}

.filter-form {
  display: grid;
  grid-template-columns: minmax(0, 160px) minmax(0, 160px) minmax(0, 260px) auto;
  align-items: end;
  gap: 12px;
}

.plan-preview {
  display: grid;
  gap: 12px;
}

.token-meter {
  position: fixed;
  top: 76px;
  right: max(14px, calc((100vw - 1120px) / 2));
  z-index: 8;
  display: grid;
  width: min(260px, calc(100vw - 28px));
  gap: 8px;
  border: 1px solid rgb(37 99 235 / 0.22);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 0.96), rgb(239 246 255 / 0.94)),
    #fff;
  box-shadow: 0 16px 42px rgb(15 23 42 / 0.12);
  backdrop-filter: blur(14px);
  padding: 12px;
}

.token-meter-head,
.token-meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.token-meter-head span,
.token-meter-row span {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.token-meter-head strong {
  color: var(--accent);
  font-size: 1rem;
  font-weight: 900;
  white-space: nowrap;
}

.token-meter-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(15 23 42 / 0.08);
}

.token-meter-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-teal), var(--accent), var(--accent-warm));
  transition: width 0.18s ease;
}

.token-meter-row strong {
  color: var(--fg);
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.quick-panel {
  display: grid;
  gap: 14px;
}

.preset-list,
.compact-list,
.library-grid,
.status-grid {
  display: grid;
  gap: 12px;
}

.mini-card {
  display: grid;
  min-width: 0;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.mini-card h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.mini-card form,
.rename-form {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  gap: 8px;
}

.mini-actions {
  flex-wrap: wrap;
}

.compact-list a {
  display: grid;
  min-width: 0;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 0.9);
  color: var(--fg);
  text-decoration: none;
  padding: 10px 12px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.compact-list a:hover {
  border-color: rgb(37 99 235 / 0.34);
  background: #fff;
  box-shadow: 0 10px 24px rgb(37 99 235 / 0.08);
  transform: translateY(-1px);
}

.compact-list strong,
.compact-list span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.compact-list span,
.muted-text {
  color: var(--muted);
  font-size: 0.9rem;
}

.with-space {
  margin-top: 14px;
}

.full-button {
  width: 100%;
}

.library-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  margin-bottom: 48px;
}

.solve-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  gap: 18px;
  margin-bottom: 48px;
}

.solve-panel {
  display: grid;
  min-width: 0;
  gap: 16px;
}

.solve-summary {
  position: sticky;
  top: 78px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: rgb(37 99 235 / 0.24);
}

.solve-summary h2 {
  font-size: 1rem;
}

.solve-card {
  display: grid;
  gap: 14px;
}

.lesson-details {
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #fff 0%, var(--panel-soft) 100%);
  padding: 12px;
}

.lesson-details summary {
  min-height: auto;
}

.lesson-copy {
  padding-top: 10px;
}

.lesson-copy p,
.lecture-block p,
.lecture-answer p,
.solve-result p {
  max-width: none;
  color: var(--fg);
}

.choice-fieldset {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-fieldset legend {
  margin-bottom: 4px;
  color: var(--fg);
  font-weight: 800;
}

.answer-input textarea {
  min-height: 116px;
}

.solve-result {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-weight: 700;
}

.result-correct {
  border-color: #b7e4c7;
  background: var(--success-bg);
}

.result-incorrect,
.result-blank {
  border-color: #fecdca;
  background: var(--fail-bg);
}

.result-needs_review {
  border-color: #fedf89;
  background: var(--warn-bg);
}

.lecture-panel {
  position: sticky;
  top: 78px;
  display: grid;
  gap: 18px;
  border-color: rgb(15 118 110 / 0.22);
}

.lecture-block,
.lecture-ask {
  display: grid;
  gap: 10px;
}

.lecture-block h3,
.lecture-ask h3 {
  margin: 0;
  font-size: 1rem;
}

.lecture-block ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.lecture-answer {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.status-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.metric-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.metric-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.metric-list dt,
.metric-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric-list dt {
  color: var(--muted);
  font-weight: 700;
}

.metric-list dd {
  font-weight: 900;
}

.print-actions {
  flex-wrap: wrap;
  margin-top: 16px;
}

.exam-header {
  border: 2px solid var(--fg);
  background:
    linear-gradient(135deg, #fff 0%, #f8fafc 100%);
}

.exam-card {
  min-height: 260px;
}

.exam-score {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.exam-instructions {
  max-width: none;
  margin-top: 8px;
  color: var(--fg);
  font-weight: 700;
}

.study-guide {
  display: grid;
  gap: 14px;
}

.study-guide-body {
  display: grid;
  gap: 10px;
}

.study-guide h3 {
  margin: 0;
  font-size: 1rem;
}

.study-guide ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: var(--fg);
}

.formula-text {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 800;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}

.study-graph {
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.study-graph svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.slot-list,
.warning-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.slot-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.slot-list strong,
.slot-list span {
  display: block;
}

.slot-list span {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.warning-list {
  color: var(--warn-fg);
  font-weight: 700;
}

.log-panel {
  margin-bottom: 16px;
}

.log-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.log-list article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.82);
  padding: 12px;
}

.log-list article:first-child {
  border-top: 1px solid var(--line);
}

@media (prefers-reduced-motion: no-preference) {
  .panel,
  .problem-card,
  .empty-state,
  .compact-list a,
  button,
  .text-button,
  .site-nav a {
    transition:
      background 0.15s ease,
      border-color 0.15s ease,
      box-shadow 0.15s ease,
      color 0.15s ease,
      transform 0.15s ease;
  }

  .problem-card:hover,
  .mini-card:hover {
    border-color: rgb(37 99 235 / 0.28);
    box-shadow: var(--shadow-strong);
  }
}

.answer-space {
  min-height: 96px;
  margin-top: 18px;
  border-bottom: 1px solid var(--line);
}

.large-answer-space {
  min-height: 150px;
}

@media (max-width: 920px) {
  .workspace-grid,
  .home-layout,
  .solve-layout {
    grid-template-columns: 1fr;
  }

  .library-grid,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .preview-panel,
  .lecture-panel,
  .solve-summary {
    position: static;
    top: auto;
    align-self: stretch;
  }

  .form-grid,
  .format-list,
  .weight-grid,
  .check-grid,
  .mode-row,
  .simple-option-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .site-header {
    position: static;
  }

  body {
    background-size: 34px 34px, 34px 34px, auto;
  }

  .container {
    width: min(100% - 20px, 1120px);
  }

  .token-meter {
    position: static;
    width: 100%;
    margin: -4px 0 14px;
  }

  .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand logout"
      "nav nav";
    align-items: center;
    min-height: auto;
    padding: 6px 0;
    gap: 8px;
  }

  .page-title,
  .action-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .brand {
    grid-area: brand;
    justify-content: flex-start;
    gap: 8px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    font-size: 0.82rem;
  }

  .site-nav {
    grid-area: nav;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    overflow: visible;
    padding-bottom: 0;
  }

  .site-nav a {
    min-height: 40px;
    padding: 0 8px;
    text-align: center;
  }

  .logout-form {
    grid-area: logout;
  }

  .logout-form button {
    min-height: 40px;
    white-space: nowrap;
    padding: 0 10px;
  }

  .page-title {
    gap: 14px;
    margin: 18px 0 14px;
    padding: 18px 16px;
  }

  .page-title .text-button,
  .form-actions button,
  .form-actions label,
  .action-group .text-button,
  .action-group .inline-form,
  .action-panel > form,
  .action-panel button,
  .problem-actions .text-button,
  .problem-actions .inline-form,
  .problem-actions button,
  .filter-form button,
  .list-card > form,
  .list-card > form button {
    width: 100%;
  }

  .form-grid,
  .format-list,
  .weight-grid,
  .check-grid,
  .mode-row,
  .simple-option-grid,
  .quick-exam-row,
  .preset-row,
  .filter-form {
    grid-template-columns: 1fr;
  }

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

  .mode-row,
  .format-list,
  .check-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-help {
    display: none;
  }

  .form-grid.compact label:nth-child(3),
  .form-grid.compact label:nth-child(7) {
    grid-column: 1 / -1;
  }

  .quick-exam-row p {
    display: none;
  }

  .list-card,
  .option-list-item,
  .problem-actions,
  .problem-help-actions,
  .mini-actions,
  .print-actions,
  .view-toggle-panel,
  .save-set-form,
  .compact-action-form {
    align-items: stretch;
    flex-direction: column;
  }

  .action-panel .action-group,
  .view-toggle-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .action-panel .save-set-form {
    grid-column: 1 / -1;
  }

  .action-panel .inline-form,
  .action-panel .text-button,
  .view-toggle-panel button {
    width: 100%;
  }

  .form-actions,
  .print-links,
  .preset-row {
    align-items: stretch;
    flex-direction: column;
  }

  .preset-row button,
  .plan-box button {
    width: 100%;
  }

  .panel {
    padding: 16px;
  }

  .recent-panel {
    max-height: none;
    overflow: visible;
  }

  .filter-form {
    align-items: stretch;
  }

  .list-card > div {
    width: 100%;
  }

  .save-set-form input,
  .compact-action-form input,
  .compact-action-form select,
  .preset-save-field input,
  .rename-form input {
    min-width: 0;
  }

  .problem-card,
  .empty-state {
    padding: 18px;
  }
}

@media (max-width: 420px) {
  .container {
    width: calc(100% - 20px);
  }

  .header-inner {
    gap: 8px;
  }

  .brand {
    justify-content: flex-start;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .site-nav {
    gap: 6px;
  }

  .site-nav a,
  .text-button,
  button,
  select,
  input,
  textarea {
    min-height: 44px;
  }

  .site-nav a,
  .logout-form button {
    min-height: 40px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.05rem;
  }

  .section-heading h2,
  .problem-card h2,
  .empty-state h2 {
    font-size: 1rem;
  }

  .page-title {
    margin: 20px 0 14px;
    padding: 16px 14px;
  }

  .simple-title {
    margin-top: 18px;
  }

  .panel,
  .problem-card,
  .empty-state {
    padding: 14px;
  }

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

  .form-grid.compact label:nth-child(3),
  .form-grid.compact label:nth-child(7) {
    grid-column: 1 / -1;
  }

  .generator-form {
    gap: 14px;
  }

  .form-section {
    gap: 14px;
    padding-bottom: 18px;
  }

  .format-fieldset {
    padding: 12px;
  }

  .quick-exam-row {
    padding: 10px;
  }

  .mode-row label,
  .check-row {
    grid-template-columns: 22px minmax(0, 1fr);
    min-height: 48px;
    padding: 12px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    min-height: 20px;
  }

  .formula-text {
    display: block;
    width: 100%;
  }

  .study-graph,
  .study-graph svg {
    width: 100%;
  }

  .rendered-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    font-size: 0.88rem;
  }

  .rendered-table th,
  .rendered-table td {
    padding: 6px;
    overflow-wrap: anywhere;
  }

  .problem-meta {
    gap: 6px;
  }

  .problem-meta span,
  .status-badge {
    min-height: 28px;
    padding: 4px 8px;
  }

  .action-panel,
  .action-group,
  .form-actions,
  .print-links,
  .problem-actions,
  .mini-actions,
  .print-actions,
  .view-toggle-panel {
    gap: 8px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .site-header,
  .no-print,
  .token-meter,
  .inline-form,
  .print-links,
  .print-actions {
    display: none;
  }

  .container {
    width: 100%;
  }

  .panel,
  .problem-card,
  .empty-state {
    border: 0;
    padding: 0;
    box-shadow: none;
  }

  .print-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
