:root {
  color-scheme: light;
  --ink-950: #0b1729;
  --ink-900: #101f36;
  --ink-800: #1b304e;
  --ink-700: #304a68;
  --ink-600: #526a84;
  --ink-500: #6f8297;
  --paper: #f7f9fc;
  --white: #ffffff;
  --line: #d7e0ea;
  --line-strong: #b9c8d8;
  --cyan: #00a9b8;
  --cyan-dark: #007a88;
  --cyan-pale: #e3f8f8;
  --coral: #ef6b5d;
  --coral-dark: #b63d35;
  --coral-pale: #fff0ed;
  --gold: #e9b64d;
  --violet: #6757d9;
  --violet-pale: #efedff;
  --success: #19754c;
  --success-pale: #e8f6ef;
  --danger: #b52d38;
  --danger-pale: #fff0f1;
  --focus: #ffb627;
  --shadow-sm: 0 4px 14px rgba(11, 23, 41, 0.08);
  --shadow-md: 0 20px 55px rgba(11, 23, 41, 0.16);
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --font-utility: "JetBrains Mono", ui-monospace, monospace;
}

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

html { min-height: 100%; background: var(--paper); scroll-behavior: smooth; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink-900);
  background:
    linear-gradient(rgba(27, 48, 78, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(27, 48, 78, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font: 400 16px/1.5 var(--font-body);
  -webkit-tap-highlight-color: rgba(0, 169, 184, 0.18);
}

button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.56; }
a { color: var(--cyan-dark); text-underline-offset: 0.18em; }
a:hover { color: var(--ink-900); }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 0.75rem;
  left: 0.75rem;
  min-height: 44px;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  color: var(--white);
  background: var(--ink-950);
  transform: translateY(-180%);
  transition: transform 150ms ease;
}
.skip-link:focus { transform: translateY(0); }

.connection-banner {
  position: sticky;
  z-index: 80;
  top: 0;
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.5rem max(1rem, env(safe-area-inset-right)) 0.5rem max(1rem, env(safe-area-inset-left));
  color: #fff6e6;
  background: #613f11;
  font-size: 0.9rem;
  font-weight: 600;
}
.connection-banner__mark { width: 0.7rem; height: 0.7rem; border: 2px solid currentColor; border-radius: 50%; }

.topbar {
  position: relative;
  z-index: 40;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.85rem max(2rem, env(safe-area-inset-right)) 0.85rem max(2rem, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255,255,255,0.12);
  color: var(--white);
  background: var(--ink-900);
}
.brand { display: inline-flex; min-width: 0; min-height: 44px; align-items: center; gap: 0.85rem; color: inherit; text-decoration: none; }
.brand:hover { color: inherit; }
.brand > span:last-child { display: grid; min-width: 0; }
.brand strong { font-size: 1.08rem; line-height: 1.2; letter-spacing: 0.01em; }
.brand small { margin-top: 0.18rem; color: #a9bed3; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.brand__mark { position: relative; display: flex; width: 42px; height: 42px; flex: 0 0 42px; align-items: flex-end; gap: 3px; padding: 9px; border: 1px solid rgba(255,255,255,0.24); border-radius: 50%; }
.brand__mark::after { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(0, 211, 220, 0.26); border-radius: 50%; }
.brand__mark span { z-index: 1; width: 5px; border-radius: 4px 4px 1px 1px; background: #5be0e2; }
.brand__mark span:nth-child(1) { height: 10px; }
.brand__mark span:nth-child(2) { height: 18px; background: var(--gold); }
.brand__mark span:nth-child(3) { height: 14px; background: var(--coral); }
.topbar__nav { display: flex; align-items: center; gap: 0.35rem; }
.topbar__nav a { display: inline-flex; min-height: 44px; align-items: center; padding: 0.5rem 0.75rem; border-radius: 0.5rem; color: #d8e6f3; font-size: 0.9rem; font-weight: 600; text-decoration: none; }
.topbar__nav a:hover { color: var(--white); background: rgba(255,255,255,0.08); }

h1, h2, h3, h4, h5, p { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; }
h1, h2 { font-family: var(--font-display); }
h1 { font-size: clamp(2.6rem, 6vw, 5rem); line-height: 0.92; letter-spacing: -0.035em; }
h2 { font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1; letter-spacing: -0.025em; }
h3 { font-size: 1.55rem; line-height: 1.12; }
h4 { font-size: 1.22rem; line-height: 1.2; }
h5 { margin-bottom: 0.25rem; font-size: 1rem; }

.eyebrow, .section-number {
  margin-bottom: 0.6rem;
  color: var(--cyan-dark);
  font: 600 0.72rem/1.3 var(--font-utility);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.68rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.6rem;
  color: var(--ink-900);
  background: var(--white);
  box-shadow: 0 1px 0 rgba(11,23,41,0.04);
  font-weight: 700;
  line-height: 1.15;
  text-decoration: none;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
.button:hover:not(:disabled) { border-color: var(--ink-700); background: #f1f5f9; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.button:active:not(:disabled) { transform: translateY(0); }
.button--primary { border-color: var(--cyan-dark); color: var(--white); background: var(--cyan-dark); }
.button--primary:hover:not(:disabled) { border-color: var(--ink-900); color: var(--white); background: var(--ink-900); }
.button--quiet { color: var(--ink-700); background: transparent; box-shadow: none; }
.topbar .button--quiet { border-color: rgba(255,255,255,0.22); color: var(--white); }
.topbar .button--quiet:hover:not(:disabled) { border-color: rgba(255,255,255,0.45); color: var(--white); background: rgba(255,255,255,0.08); }
.button--compact { min-height: 44px; padding: 0.55rem 0.8rem; font-size: 0.86rem; }
.button--large { min-height: 54px; padding: 0.9rem 1.4rem; font-size: 1.02rem; }
.button--danger { border-color: var(--danger); color: var(--white); background: var(--danger); }
.button--danger:hover:not(:disabled) { border-color: #781c25; color: var(--white); background: #781c25; }

.gate {
  position: relative;
  width: min(880px, calc(100% - 2rem));
  min-height: calc(100vh - 76px);
  margin: 0 auto;
  padding: clamp(5rem, 11vh, 9rem) clamp(1rem, 6vw, 5rem) 5rem;
  text-align: center;
}
.gate h1 { max-width: 760px; margin-right: auto; margin-bottom: 1.35rem; margin-left: auto; }
.gate > p:not(.eyebrow, .fine-print) { max-width: 640px; margin-right: auto; margin-left: auto; color: var(--ink-600); font-size: 1.1rem; }
.gate__lede { margin-bottom: 2rem; font-size: 1.18rem !important; }
.gate .fine-print { max-width: 560px; margin: 1rem auto 0; color: var(--ink-500); font-size: 0.82rem; }
.gate__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }
.gate__instrument { display: flex; width: 88px; height: 88px; align-items: flex-end; justify-content: center; gap: 6px; margin: 0 auto 2rem; padding: 21px; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--white); box-shadow: var(--shadow-sm); }
.gate__instrument i { display: block; width: 8px; border-radius: 8px 8px 2px 2px; background: var(--cyan); animation: meter 900ms ease-in-out infinite alternate; }
.gate__instrument i:nth-child(1) { height: 16px; }
.gate__instrument i:nth-child(2) { height: 38px; animation-delay: -300ms; background: var(--gold); }
.gate__instrument i:nth-child(3) { height: 27px; animation-delay: -600ms; background: var(--coral); }
@keyframes meter { from { transform: scaleY(0.65); } to { transform: scaleY(1); } }

.gate__composition { position: relative; width: 230px; height: 140px; margin: 0 auto 2.5rem; color: var(--ink-900); }
.composition__prompt { position: absolute; z-index: 2; top: 4px; left: 16px; display: grid; width: 88px; height: 88px; place-items: center; border: 2px solid var(--ink-900); border-radius: 1rem; color: var(--white); background: var(--ink-900); font: 700 4.5rem/1 var(--font-display); box-shadow: 10px 10px 0 var(--cyan-pale); transform: rotate(-4deg); }
.composition__line { position: absolute; right: 15px; display: block; height: 13px; border-radius: 10px; background: var(--line-strong); transform: rotate(3deg); }
.composition__line--one { top: 28px; width: 104px; }
.composition__line--two { top: 56px; width: 84px; }
.composition__standard { position: absolute; right: 24px; bottom: 16px; display: grid; width: 72px; height: 38px; place-items: center; border: 2px solid var(--coral-dark); border-radius: 50%; color: var(--coral-dark); font: 600 0.74rem var(--font-utility); transform: rotate(-7deg); }

.setup-card { display: grid; width: min(600px, 100%); gap: 1.2rem; margin: 2rem auto 0; padding: 1.5rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--white); box-shadow: var(--shadow-md); text-align: left; }
.setup-card > div:first-child { display: grid; gap: 0.2rem; }
.setup-card > div:first-child strong { font-size: 1.25rem; }
.setup-card > div:first-child span { color: var(--ink-600); }
.check-row { display: flex; min-height: 48px; align-items: flex-start; gap: 0.75rem; padding: 0.7rem; border-radius: 0.6rem; background: var(--paper); cursor: pointer; }
.check-row input { width: 20px; height: 20px; flex: 0 0 20px; margin-top: 0.1rem; accent-color: var(--cyan-dark); }
.check-row a { display: inline-flex; min-height: 44px; align-items: center; }

.notice { margin: 1rem 0; padding: 0.9rem 1rem; border: 1px solid var(--line); border-radius: 0.65rem; color: var(--ink-700); background: var(--white); }
.notice--error { border-color: #e8aeb3; color: #7c2029; background: var(--danger-pale); }
.notice--privacy { border-color: #b9b4eb; color: #3e347c; background: var(--violet-pale); }
.gate > .notice { max-width: 600px; margin-right: auto; margin-left: auto; text-align: left; }

.studio { display: grid; height: calc(100vh - 76px); grid-template-columns: minmax(260px, 330px) minmax(0, 1fr); overflow: hidden; }
.library { display: flex; min-width: 0; flex-direction: column; overflow: hidden; border-right: 1px solid var(--line); background: rgba(247,249,252,0.96); }
.library__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; padding: 1.5rem 1.25rem 1rem; }
.library__head h1 { margin: 0; font-size: 2rem; }
.library__head .eyebrow { margin-bottom: 0.25rem; }
.teacher-chip { display: flex; min-width: 0; align-items: center; gap: 0.75rem; margin: 0 1.25rem 1rem; padding: 0.75rem; border: 1px solid var(--line); border-radius: 0.7rem; background: var(--white); }
.teacher-chip__avatar { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 50%; color: var(--white); background: var(--violet); font: 700 1rem var(--font-utility); }
.teacher-chip > span:last-child { display: grid; min-width: 0; }
.teacher-chip strong, .teacher-chip small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.teacher-chip small { color: var(--ink-500); }
.template-entry { display: grid; min-height: 64px; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 0.75rem; margin: 0 1.25rem 1rem; padding: 0.65rem 0.8rem; border: 1px solid #b9b4eb; border-radius: 0.7rem; color: var(--ink-900); background: var(--violet-pale); text-align: left; }
.template-entry:hover { border-color: var(--violet); box-shadow: var(--shadow-sm); }
.template-entry__mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 0.5rem; color: var(--white); background: var(--violet); font: 600 0.72rem var(--font-utility); letter-spacing: 0.08em; }
.template-entry > span:nth-child(2) { display: grid; min-width: 0; gap: 0.12rem; }
.template-entry strong, .template-entry small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-entry small { color: var(--ink-600); font-size: 0.74rem; }
.search-field { display: grid; gap: 0.35rem; margin: 0 1.25rem 1rem; color: var(--ink-600); font-size: 0.78rem; font-weight: 700; }
.search-field input { min-height: 46px; padding: 0.65rem 0.85rem; border: 1px solid var(--line); border-radius: 0.6rem; color: var(--ink-900); background: var(--white); }
.search-field:focus-within { color: var(--cyan-dark); }
.library__status { min-height: 1.5rem; padding: 0 1.25rem; color: var(--ink-600); font-size: 0.82rem; }
.bank-list { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0.5rem 0.75rem 2rem; }
.bank-card { position: relative; display: grid; width: 100%; min-height: 92px; gap: 0.35rem; margin-bottom: 0.5rem; padding: 0.85rem 0.9rem 0.85rem 1.15rem; border: 1px solid transparent; border-radius: 0.7rem; color: var(--ink-900); background: transparent; text-align: left; }
.bank-card::before { content: ""; position: absolute; top: 14px; bottom: 14px; left: 0; width: 4px; border-radius: 5px; background: var(--line-strong); }
.bank-card:hover { border-color: var(--line); background: var(--white); }
.bank-card[aria-current="true"] { border-color: #b4dfe2; background: var(--cyan-pale); }
.bank-card[aria-current="true"]::before { background: var(--cyan-dark); }
.bank-card strong { overflow-wrap: anywhere; font-size: 0.96rem; }
.bank-card__meta { display: flex; flex-wrap: wrap; gap: 0.35rem 0.65rem; color: var(--ink-600); font-size: 0.76rem; }
.bank-card__meta span:first-child { font-family: var(--font-utility); text-transform: uppercase; }
.bank-list__empty { padding: 2rem 1rem; color: var(--ink-600); text-align: center; }
.bank-list__empty strong { display: block; margin-bottom: 0.35rem; color: var(--ink-900); }

.workspace { position: relative; min-width: 0; overflow: hidden; background: rgba(255,255,255,0.5); }
.empty-workspace { display: grid; width: min(620px, calc(100% - 2rem)); min-height: calc(100vh - 76px); place-content: center; justify-items: center; margin: 0 auto; padding: 3rem 1rem; text-align: center; }
.empty-workspace h2 { margin-bottom: 1rem; }
.empty-workspace p:not(.eyebrow) { max-width: 540px; color: var(--ink-600); }
.empty-workspace__glyph { display: grid; width: 86px; height: 86px; place-items: center; margin-bottom: 1.5rem; border: 2px dashed var(--line-strong); border-radius: 50%; color: var(--cyan-dark); background: var(--white); font: 400 3rem/1 var(--font-display); }
.empty-workspace__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.65rem; }

.editor { display: flex; height: 100%; min-width: 0; flex-direction: column; }
.editor__toolbar { display: flex; min-height: 88px; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.96); }
.editor__identity { min-width: 0; }
.editor__identity .eyebrow { margin-bottom: 0.2rem; }
.editor__identity h2 { max-width: 46vw; margin: 0; overflow: hidden; font-family: var(--font-body); font-size: 1.2rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.editor__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.45rem; }
.editor__actions .button { min-height: 44px; padding: 0.55rem 0.75rem; font-size: 0.82rem; }
.save-recovery { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 1.5rem; border-bottom: 1px solid #e8aeb3; color: #7c2029; background: var(--danger-pale); }
.save-recovery > div { display: grid; }
.save-recovery span { font-size: 0.85rem; }
.editor__scroll { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: clamp(1.25rem, 3vw, 2.5rem); }
.bank-details, .template-review, .question-workbench { width: min(1120px, 100%); margin: 0 auto; }
.question-workbench { margin-top: 3.5rem; padding-top: 2.5rem; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 1.5rem; }
.section-heading h3 { margin-bottom: 0; }
.section-heading > p { max-width: 410px; margin-bottom: 0.2rem; color: var(--ink-600); text-align: right; }
.section-heading--questions { align-items: center; }
.section-heading__actions { display: flex; max-width: 620px; flex-wrap: wrap; justify-content: flex-end; gap: 0.45rem; }
.section-heading__actions .button { min-height: 44px; font-size: 0.78rem; text-align: center; }
.file-input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap; }
.file-input:focus-visible + .button { outline: 3px solid var(--focus); outline-offset: 3px; }
.bulk-import-status { width: min(1120px, 100%); min-height: 1.4em; margin: -0.9rem auto 1.2rem; color: var(--ink-600); font-size: 0.78rem; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.details-grid--question { margin-top: 1rem; }
.field { display: grid; min-width: 0; align-content: start; gap: 0.38rem; color: var(--ink-700); font-size: 0.82rem; font-weight: 700; }
.field--wide { grid-column: 1 / -1; }
.field input, .field textarea, .field select, .search-field input, .compare-controls select {
  width: 100%;
  min-height: 46px;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.55rem;
  color: var(--ink-900);
  background: var(--white);
  font-size: 0.94rem;
  font-weight: 400;
}
.field textarea { resize: vertical; }
.field select, .compare-controls select { appearance: auto; }
.field input:hover, .field textarea:hover, .field select:hover, .search-field input:hover { border-color: var(--ink-500); }
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.field small:not(.field-error) { color: var(--ink-500); font-weight: 400; }
.field-error { min-height: 1.2em; color: var(--danger); font-weight: 600; }

.visibility-fieldset { margin: 1.4rem 0 0; padding: 0; border: 0; }
.visibility-fieldset legend { margin-bottom: 0.6rem; color: var(--ink-700); font-size: 0.82rem; font-weight: 700; }
.visibility-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; }
.visibility-card { position: relative; display: flex; min-height: 104px; align-items: flex-start; gap: 0.75rem; padding: 1rem; border: 1px solid var(--line); border-radius: 0.7rem; background: var(--white); cursor: pointer; }
.visibility-card:hover { border-color: var(--ink-500); }
.visibility-card:has(input:checked) { border-color: var(--violet); box-shadow: inset 0 0 0 1px var(--violet); background: var(--violet-pale); }
.visibility-card:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.visibility-card input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.visibility-card__icon { display: grid; width: 32px; height: 32px; flex: 0 0 32px; place-items: center; border-radius: 50%; color: var(--violet); background: var(--violet-pale); font-weight: 700; }
.visibility-card:has(input:checked) .visibility-card__icon { color: var(--white); background: var(--violet); }
.visibility-card > span:last-child { display: grid; gap: 0.3rem; }
.visibility-card small { color: var(--ink-600); font-size: 0.78rem; font-weight: 400; }
.privacy-explanation { margin: 0.75rem 0 0; padding-left: 0.15rem; color: var(--ink-600); font-size: 0.82rem; }
.privacy-explanation strong { color: var(--ink-800); }

.template-review { margin-top: 3.5rem; padding-top: 2.5rem; border-top: 1px solid var(--line); }
.template-review__heading { margin-bottom: 1rem; }
.template-review__status { display: flex; min-height: 58px; align-items: center; gap: 0.75rem; margin-bottom: 0.85rem; padding: 0.8rem 1rem; border: 1px solid #e4c572; border-left: 5px solid var(--gold); border-radius: 0.7rem; color: #60460d; background: #fff9e9; font-weight: 600; }
.template-review__status::before { content: "TX"; display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 0.45rem; color: var(--white); background: #8a6819; font: 700 0.68rem var(--font-utility); letter-spacing: 0.08em; }
.template-review__status[data-state="passed"] { border-color: #9cd1b8; border-left-color: var(--success); color: #0f5435; background: var(--success-pale); }
.template-review__status[data-state="passed"]::before { background: var(--success); }
.template-review__status[data-state="stale"] { border-color: #e8aeb3; border-left-color: var(--danger); color: #7c2029; background: var(--danger-pale); }
.template-review__status[data-state="stale"]::before { background: var(--danger); }
.template-review__route { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.55rem; margin: 0 0 1rem; }
.template-review__route > div { min-width: 0; padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: 0.55rem; background: var(--white); }
.template-review__route dt { color: var(--ink-500); font: 600 0.66rem var(--font-utility); letter-spacing: 0.04em; text-transform: uppercase; }
.template-review__route dd { margin: 0.2rem 0 0; overflow-wrap: anywhere; color: var(--ink-900); font-size: 0.84rem; font-weight: 700; }
.template-course, .review-confirmations { margin: 0 0 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--white); }
.template-course legend, .review-confirmations legend { padding: 0 0.35rem; color: var(--ink-800); font-weight: 700; }
.template-course > p { margin: 0 0 1rem; color: var(--ink-600); font-size: 0.84rem; }
.template-course__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.review-confirmations { display: grid; gap: 0.55rem; }
.review-confirmations > label { position: relative; display: grid; min-height: 70px; grid-template-columns: 44px minmax(0, 1fr); align-items: start; gap: 0.75rem; padding: 0.75rem; border: 1px solid var(--line); border-radius: 0.6rem; background: var(--paper); cursor: pointer; }
.review-confirmations > label:hover { border-color: var(--ink-500); }
.review-confirmations > label:has(input:checked) { border-color: var(--success); background: var(--success-pale); }
.review-confirmations > label:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.review-confirmations input { width: 44px; height: 44px; margin: 0; accent-color: var(--success); }
.review-confirmations span { display: grid; gap: 0.18rem; }
.review-confirmations small { color: var(--ink-600); font-size: 0.78rem; font-weight: 400; }
.review-confirmations__error { min-height: 1.4em; margin: -0.35rem 0 0.7rem; color: var(--danger); font-size: 0.82rem; font-weight: 600; }
.template-review__notice { margin-bottom: 0.75rem; }
.template-review__actions { display: flex; justify-content: flex-end; margin-top: 0.75rem; }
.template-review__actions .button { min-width: 220px; }
.template-review__guard { max-width: 360px; margin: 0.45rem 0 0; color: var(--ink-700); font-size: 0.8rem; font-weight: 600; text-align: right; }

.question-layout { display: grid; grid-template-columns: minmax(210px, 280px) minmax(0, 1fr); align-items: start; gap: 1rem; }
.question-rail { display: grid; max-height: 720px; gap: 0.45rem; overflow-y: auto; overscroll-behavior: contain; }
.question-tab { position: relative; display: grid; width: 100%; min-height: 74px; grid-template-columns: 34px minmax(0, 1fr); gap: 0.65rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: 0.65rem; color: var(--ink-900); background: var(--white); text-align: left; }
.question-tab:hover { border-color: var(--ink-500); box-shadow: var(--shadow-sm); }
.question-tab[aria-current="true"] { border-color: var(--cyan-dark); box-shadow: inset 4px 0 0 var(--cyan-dark); background: var(--cyan-pale); }
.question-tab__number { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 0.45rem; color: var(--white); background: var(--ink-800); font: 600 0.72rem var(--font-utility); }
.question-tab[aria-current="true"] .question-tab__number { background: var(--cyan-dark); }
.question-tab__copy { display: grid; min-width: 0; gap: 0.25rem; }
.question-tab__copy strong { overflow: hidden; font-size: 0.84rem; text-overflow: ellipsis; white-space: nowrap; }
.question-tab__copy small { color: var(--ink-500); font: 500 0.65rem var(--font-utility); text-transform: uppercase; }

.question-editor { min-width: 0; min-height: 430px; padding: clamp(1rem, 2.5vw, 1.5rem); border: 1px solid var(--line); border-radius: 0.9rem; background: var(--white); box-shadow: var(--shadow-sm); }
.question-empty { display: grid; min-height: 390px; place-content: center; justify-items: center; text-align: center; }
.question-empty > span { display: grid; width: 62px; height: 62px; place-items: center; margin-bottom: 1rem; border: 1px solid var(--line-strong); border-radius: 0.8rem; color: var(--cyan-dark); background: var(--cyan-pale); font: 700 1.8rem var(--font-display); transform: rotate(-3deg); }
.question-empty h4 { margin-bottom: 0.5rem; }
.question-empty p { max-width: 440px; color: var(--ink-600); }
.question-editor__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.question-editor__head .eyebrow { margin-bottom: 0.25rem; }
.question-editor__head h4 { margin-bottom: 0; }
.icon-button { display: inline-grid; width: 46px; height: 46px; flex: 0 0 46px; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--ink-700); background: var(--white); font-size: 1.5rem; transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease; }
.icon-button:hover { border-color: var(--ink-700); color: var(--ink-950); background: var(--paper); }
.icon-button--danger { color: var(--danger); }
.icon-button--danger:hover { border-color: var(--danger); color: var(--white); background: var(--danger); }

.question-type-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.45rem; margin-bottom: 1.1rem; }
.question-type-row label { position: relative; display: block; cursor: pointer; }
.question-type-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.question-type-row span { display: grid; min-height: 48px; place-items: center; padding: 0.5rem; border: 1px solid var(--line); border-radius: 0.55rem; color: var(--ink-600); background: var(--paper); font-size: 0.76rem; font-weight: 700; text-align: center; }
.question-type-row label:hover span { border-color: var(--ink-500); color: var(--ink-900); }
.question-type-row input:checked + span { border-color: var(--cyan-dark); color: var(--cyan-dark); background: var(--cyan-pale); box-shadow: inset 0 0 0 1px var(--cyan-dark); }
.question-type-row input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }

.answer-panel { margin: 1.1rem 0; padding: 1rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--paper); }
.answer-panel__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.answer-panel__head p { margin: 0; color: var(--ink-600); font-size: 0.78rem; }
.choice-list { display: grid; gap: 0.7rem; }
.choice-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) minmax(0, 0.9fr) 44px; align-items: start; gap: 0.55rem; }
.choice-correct { position: relative; display: grid; width: 44px; height: 46px; place-items: center; border: 1px solid var(--line-strong); border-radius: 0.5rem; color: var(--ink-600); background: var(--white); cursor: pointer; }
.choice-correct input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.choice-correct span { display: grid; width: 26px; height: 26px; place-items: center; border: 2px solid var(--line-strong); border-radius: 50%; font-size: 0.7rem; font-weight: 700; }
.choice-correct:has(input:checked) { border-color: var(--success); color: var(--success); background: var(--success-pale); }
.choice-correct:has(input:checked) span { border-color: var(--success); color: var(--white); background: var(--success); }
.choice-correct:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.choice-row .field span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.choice-row .field-error { font-size: 0.72rem; }
.choice-remove { width: 44px; height: 46px; min-height: 44px; padding: 0; border: 1px solid var(--line-strong); border-radius: 0.5rem; color: var(--danger); background: var(--white); font-size: 1.2rem; }
.choice-remove:hover:not(:disabled) { border-color: var(--danger); color: var(--white); background: var(--danger); }
.binary-choice { display: grid; grid-template-columns: repeat(2, minmax(0, 180px)); gap: 0.65rem; }
.binary-choice label { position: relative; cursor: pointer; }
.binary-choice input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.binary-choice span { display: grid; min-height: 48px; place-items: center; border: 1px solid var(--line-strong); border-radius: 0.55rem; background: var(--white); font-weight: 700; }
.binary-choice input:checked + span { border-color: var(--success); color: var(--success); background: var(--success-pale); box-shadow: inset 0 0 0 1px var(--success); }
.binary-choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.question-form-actions { display: flex; min-height: 60px; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.question-form-actions > span { color: var(--success); font-size: 0.82rem; font-weight: 600; }
.question-form-actions > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }

.dialog {
  width: min(720px, calc(100% - 2rem));
  max-height: min(90vh, 880px);
  padding: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  border: 1px solid var(--line-strong);
  border-radius: 1rem;
  color: var(--ink-900);
  background: var(--white);
  box-shadow: var(--shadow-md);
}
.dialog--wide { width: min(1080px, calc(100% - 2rem)); }
.dialog--compact { width: min(520px, calc(100% - 2rem)); }
.dialog::backdrop { background: rgba(5, 14, 28, 0.72); backdrop-filter: blur(5px); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--paper); }
.dialog__head .eyebrow { margin-bottom: 0.25rem; }
.dialog__head h2 { margin: 0; font-family: var(--font-body); font-size: 1.35rem; font-weight: 700; }
.dialog__body { max-height: calc(90vh - 155px); overflow-y: auto; overscroll-behavior: contain; padding: 1.25rem; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 0.65rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); background: var(--paper); }
.template-browser { background: #fbfcff; }
.template-ledger { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; padding: 1rem; border: 1px solid #b9b4eb; border-left: 5px solid var(--violet); border-radius: 0.75rem; background: var(--violet-pale); }
.template-ledger__mark { display: grid; width: 58px; height: 58px; place-items: center; border-radius: 0.65rem; color: var(--white); background: var(--violet); font: 600 0.82rem var(--font-utility); letter-spacing: 0.1em; }
.template-ledger strong { display: block; margin-bottom: 0.25rem; }
.template-ledger p { margin: 0; color: var(--ink-700); }
.template-filters { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr) auto; align-items: start; gap: 0.75rem; margin-bottom: 0.75rem; padding: 1rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--white); }
.template-filters .button { align-self: end; margin-bottom: 1.2em; }
.template-status { min-height: 1.6rem; margin: 0.25rem 0 0.65rem; color: var(--ink-600); font-size: 0.84rem; }
.template-error { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.template-error[hidden] { display: none; }
.template-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.template-list__empty { grid-column: 1 / -1; padding: 2.5rem 1rem; border: 1px dashed var(--line-strong); border-radius: 0.75rem; color: var(--ink-600); text-align: center; }
.template-list__empty strong { display: block; margin-bottom: 0.3rem; color: var(--ink-900); }
.template-card { position: relative; display: flex; min-width: 0; min-height: 275px; flex-direction: column; padding: 1rem; overflow: hidden; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--white); box-shadow: 0 1px 0 rgba(11,23,41,0.03); }
.template-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--cyan-dark); }
.template-card--unavailable { background: #f3f5f8; }
.template-card--unavailable::before { background: var(--ink-500); }
.template-card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.template-card__stamp { display: grid; min-width: 60px; min-height: 44px; place-items: center; padding: 0.35rem 0.5rem; border-radius: 0.5rem; color: var(--cyan-dark); background: var(--cyan-pale); font: 600 0.68rem var(--font-utility); text-align: center; }
.template-card--unavailable .template-card__stamp { color: var(--ink-700); background: #e3e8ee; }
.template-card h3 { margin: 0; overflow-wrap: anywhere; font-family: var(--font-body); font-size: 1.05rem; }
.template-card__meta { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.65rem 0; }
.template-card__meta .pill { min-height: 26px; }
.template-card__model { margin: 0 0 0.45rem; color: var(--ink-700); font-size: 0.8rem; overflow-wrap: anywhere; }
.template-card__explanation { margin: 0 0 0.65rem; color: var(--ink-600); font-size: 0.84rem; }
.template-card__subroute { margin: -0.2rem 0 0.65rem; padding: 0.45rem 0.6rem; border-radius: 0.45rem; color: #3e347c; background: var(--violet-pale); font-size: 0.78rem; font-weight: 700; }
.template-card__guidance { margin-bottom: 0.35rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.template-card__guidance summary { display: flex; min-height: 44px; align-items: center; color: var(--ink-700); font-size: 0.78rem; font-weight: 700; cursor: pointer; }
.template-card__guidance summary:hover { color: var(--cyan-dark); }
.template-card__guidance p { margin: 0 0 0.65rem; color: var(--ink-600); font-size: 0.76rem; }
.template-card__source { display: inline-flex; min-height: 44px; align-items: center; align-self: flex-start; margin-top: auto; color: var(--cyan-dark); font-size: 0.8rem; font-weight: 700; }
.template-card__source:hover { color: var(--ink-900); }
.template-card__action { display: grid; gap: 0.35rem; margin-top: 0.55rem; }
.template-card__action small { min-height: 1.2em; color: var(--ink-600); font-size: 0.74rem; }
.template-card__action .button { width: 100%; }
.publish-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-bottom: 1rem; }
.publish-summary > div { display: grid; gap: 0.2rem; padding: 0.8rem; border: 1px solid var(--line); border-radius: 0.55rem; background: var(--paper); }
.publish-summary small { color: var(--ink-500); font-size: 0.72rem; }
.preview__head { margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.preview__head h3 { margin-bottom: 0.35rem; font-family: var(--font-display); font-size: 2rem; }
.preview__head p { margin-bottom: 0.5rem; color: var(--ink-600); }
.preview__meta { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.pill { display: inline-flex; min-height: 28px; align-items: center; padding: 0.25rem 0.55rem; border-radius: 2rem; color: var(--ink-700); background: var(--paper); font: 500 0.68rem var(--font-utility); text-transform: uppercase; }
.preview-question { margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 0.7rem; }
.preview-question__number { color: var(--cyan-dark); font: 600 0.7rem var(--font-utility); text-transform: uppercase; }
.preview-question h4 { margin: 0.45rem 0 0.8rem; overflow-wrap: anywhere; }
.preview-answer { display: grid; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.preview-answer li { padding: 0.6rem 0.7rem; border-radius: 0.4rem; background: var(--paper); overflow-wrap: anywhere; }
.preview-answer li[data-correct="true"] { color: var(--success); background: var(--success-pale); font-weight: 600; }
.preview-rationale { margin: 0.8rem 0 0; padding: 0.75rem; border-left: 3px solid var(--gold); color: var(--ink-700); background: #fff9e9; overflow-wrap: anywhere; }
.compare-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: 0.75rem; }
.version-comparison { min-height: 220px; margin-top: 1.25rem; }
.compare-placeholder { display: grid; min-height: 220px; place-content: center; color: var(--ink-500); text-align: center; }
.diff-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.65rem; margin-bottom: 1rem; }
.diff-summary article { padding: 0.8rem; border: 1px solid var(--line); border-radius: 0.55rem; background: var(--paper); }
.diff-summary strong { display: block; font: 700 1.5rem var(--font-display); font-variant-numeric: tabular-nums; }
.diff-list { display: grid; gap: 0.55rem; }
.diff-row { display: grid; grid-template-columns: 120px 1fr; gap: 0.75rem; padding: 0.75rem; border: 1px solid var(--line); border-radius: 0.55rem; }
.diff-row strong { color: var(--ink-600); font-size: 0.8rem; }
.diff-row span { overflow-wrap: anywhere; }

.toast-region { position: fixed; z-index: 120; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); display: grid; width: min(380px, calc(100% - 2rem)); gap: 0.6rem; pointer-events: none; }
.toast { padding: 0.85rem 1rem; border: 1px solid #9cd1b8; border-radius: 0.65rem; color: #0f5435; background: #eefaf4; box-shadow: var(--shadow-md); font-weight: 600; animation: toast-in 180ms ease-out both; }
.toast--error { border-color: #e8aeb3; color: #7c2029; background: var(--danger-pale); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1050px) {
  .studio { grid-template-columns: 260px minmax(0, 1fr); }
  .editor__toolbar { align-items: flex-start; flex-direction: column; }
  .editor__actions { width: 100%; justify-content: flex-start; }
  .editor__identity h2 { max-width: 82vw; }
  .question-layout { grid-template-columns: 190px minmax(0, 1fr); }
  .choice-row { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .choice-row .field:nth-of-type(2) { grid-column: 2 / -1; }
}

@media (max-width: 820px) {
  .topbar { padding-inline: max(1rem, env(safe-area-inset-left)); }
  .topbar__nav a { display: none; }
  .studio { height: auto; min-height: calc(100vh - 76px); grid-template-columns: 1fr; overflow: visible; }
  .library { max-height: 360px; border-right: 0; border-bottom: 1px solid var(--line); }
  .bank-list { min-height: 130px; }
  .workspace { min-height: 640px; overflow: visible; }
  .editor { height: auto; }
  .editor__toolbar { position: sticky; z-index: 20; top: 0; }
  .editor__scroll { overflow: visible; }
  .empty-workspace { min-height: 540px; }
  .question-layout { grid-template-columns: 1fr; }
  .question-rail { max-height: none; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); overflow: visible; }
  .question-type-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .visibility-grid { grid-template-columns: 1fr; }
  .visibility-card { min-height: 88px; }
  .template-review__route { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .template-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .template-filters .button { margin-bottom: 0; }
}

@media (max-width: 600px) {
  .topbar { min-height: 70px; }
  .brand small { display: none; }
  .brand strong { font-size: 0.92rem; }
  .brand__mark { width: 38px; height: 38px; flex-basis: 38px; }
  .gate { min-height: calc(100vh - 70px); padding-top: 4rem; }
  .gate h1 { font-size: clamp(2.5rem, 13vw, 3.8rem); }
  .library__head { align-items: center; }
  .editor__toolbar { padding: 0.85rem 1rem; }
  .editor__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor__actions .button { width: 100%; }
  .save-recovery { align-items: stretch; flex-direction: column; padding: 0.8rem 1rem; }
  .editor__scroll { padding: 1rem; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 0.8rem; }
  .section-heading > p { text-align: left; }
  .section-heading--questions { flex-direction: column; align-items: stretch; }
  .section-heading__actions { display: grid; max-width: none; grid-template-columns: 1fr; }
  .section-heading__actions .button { width: 100%; }
  .details-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
  .template-review__route, .template-course__grid { grid-template-columns: 1fr; }
  .template-review__actions .button { width: 100%; min-width: 0; }
  .template-review__guard { max-width: none; text-align: left; }
  .question-rail { display: flex; margin-right: -1rem; margin-left: -1rem; padding: 0 1rem 0.25rem; overflow-x: auto; scroll-snap-type: x proximity; }
  .question-tab { min-width: 190px; scroll-snap-align: start; }
  .question-editor { margin-right: -0.25rem; margin-left: -0.25rem; padding: 1rem 0.8rem; }
  .choice-row { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .choice-row .field:nth-of-type(2) { grid-column: 1 / -1; }
  .binary-choice { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .question-form-actions { align-items: stretch; flex-direction: column; }
  .question-form-actions > div { display: grid; grid-template-columns: 1fr; }
  .dialog, .dialog--wide, .dialog--compact { width: calc(100% - 1rem); max-height: calc(100vh - 1rem); }
  .dialog__body { max-height: calc(100vh - 150px); }
  .dialog__actions { display: grid; grid-template-columns: 1fr; }
  .dialog__actions .button { width: 100%; }
  .publish-summary, .diff-summary { grid-template-columns: 1fr; }
  .compare-controls { grid-template-columns: 1fr; }
  .diff-row { grid-template-columns: 1fr; gap: 0.2rem; }
  .template-ledger { grid-template-columns: 44px minmax(0, 1fr); padding: 0.8rem; }
  .template-ledger__mark { width: 44px; height: 44px; }
  .template-filters, .template-list { grid-template-columns: 1fr; }
  .template-error { align-items: stretch; flex-direction: column; }
  .template-error .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media print {
  .topbar, .library, .editor__toolbar, .question-rail, .question-form-actions, .toast-region, .connection-banner { display: none !important; }
  .studio, .workspace, .editor { display: block; height: auto; overflow: visible; }
  .editor__scroll { overflow: visible; padding: 0; }
}
