:root {
  color-scheme: light;
  --bg: #f8fbff;
  --bg-strong: #eef4fb;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-solid: #ffffff;
  --surface-soft: #fbfdff;
  --surface-tint: #f1f6fd;
  --ink: #0f1f33;
  --ink-soft: #273a52;
  --muted: #64748b;
  --line: #d7e3f8;
  --line-strong: #b9cbea;
  --primary: #3b6ff5;
  --primary-strong: #2557d6;
  --primary-soft: #e7efff;
  --teal: #5f947f;
  --teal-soft: #edf7f1;
  --coral: #e25563;
  --coral-soft: #ffe4e7;
  --amber: #d88618;
  --amber-soft: #fff2cf;
  --violet: #7c3aed;
  --violet-soft: #ede9fe;
  --green: #16a34a;
  --danger: #dc2626;
  --shadow: 0 18px 42px rgba(15, 31, 51, 0.08);
  --shadow-soft: 0 10px 24px rgba(15, 31, 51, 0.055);
  --radius: 8px;
  --max-width: 1500px;
  --page-gutter: clamp(14px, 3vw, 32px);
  --font-sans: "Noto Sans SC", "Source Han Sans SC", "HarmonyOS Sans SC", "MiSans", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  --font-display: "Noto Sans SC", "Source Han Sans SC", "HarmonyOS Sans SC", "MiSans", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --font-brand: Bahnschrift, "DIN Alternate", "Aptos Display", "Segoe UI", Arial, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08111f;
  --bg-strong: #101c2d;
  --surface: rgba(15, 25, 42, 0.9);
  --surface-solid: #111d30;
  --surface-soft: #162338;
  --surface-tint: #102d3b;
  --ink: #eef6ff;
  --ink-soft: #d4e1ef;
  --muted: #9db0c6;
  --line: #263a54;
  --line-strong: #3b5270;
  --primary: #6aa2ff;
  --primary-strong: #8db8ff;
  --primary-soft: #153864;
  --teal: #35d0bf;
  --teal-soft: #113c3b;
  --coral: #ff7f8a;
  --coral-soft: #4b1d28;
  --amber: #f4b94e;
  --amber-soft: #3d2d13;
  --violet: #b79cff;
  --violet-soft: #2d2253;
  --green: #4ade80;
  --danger: #fb7185;
  --shadow: 0 22px 58px rgba(0, 0, 0, 0.36);
  --shadow-soft: 0 14px 34px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0) 280px),
    linear-gradient(135deg, var(--bg), var(--bg-strong));
  color: var(--ink);
  font-family: var(--font-sans);
  font-optical-sizing: auto;
  line-height: 1.55;
}

html[data-theme="dark"] body {
  background:
    linear-gradient(180deg, rgba(42, 72, 112, 0.18), rgba(8, 17, 31, 0) 320px),
    linear-gradient(135deg, var(--bg), var(--bg-strong));
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
  padding: 9px 15px;
  transition:
    transform 160ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    border-color 180ms ease;
}

button:hover {
  box-shadow: 0 10px 24px rgba(59, 111, 245, 0.2);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

button.is-loading,
button.is-complete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.is-loading:disabled,
button.is-complete:disabled {
  opacity: 0.92;
}

button.is-complete {
  background: linear-gradient(135deg, var(--teal), var(--green));
}

.button-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: buttonSpin 820ms linear infinite;
}

button.secondary {
  border: 1px solid var(--line);
  background: var(--surface-solid);
  color: var(--ink-soft);
  box-shadow: none;
}

button.secondary:hover {
  background: var(--surface-soft);
  box-shadow: var(--shadow-soft);
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent);
  outline-offset: 2px;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 26px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  color: var(--ink);
  font-size: 18px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 15px;
  letter-spacing: 0;
}

h4 {
  margin: 12px 0 6px;
  color: var(--ink-soft);
  font-size: 13px;
}

p {
  margin-bottom: 10px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  padding: 16px max(24px, calc((100vw - var(--max-width)) / 2 + 24px));
  box-shadow: 0 10px 28px rgba(15, 31, 51, 0.08);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 46px;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid color-mix(in srgb, var(--primary) 32%, var(--line));
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--primary) 16%, transparent), transparent 58%),
    var(--surface-solid);
  color: var(--primary);
  font-weight: 900;
  box-shadow: var(--shadow-soft);
}

.topbar p {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.eyebrow {
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 6px 12px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.status i {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #91a4b8;
}

.status.on {
  border-color: color-mix(in srgb, var(--teal) 38%, var(--line));
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 82%, var(--ink));
}

.status.on i {
  animation: statusPulse 1600ms ease-in-out infinite;
  background: var(--teal);
}

.language-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 3px;
}

.preference-button {
  min-width: 48px;
  min-height: 32px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  padding: 4px 10px;
}

.preference-button:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  box-shadow: none;
}

.preference-button.active {
  background: var(--primary);
  color: #ffffff;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: none;
}

.icon-button span {
  display: block;
  font-size: 18px;
  line-height: 1;
}

main {
  display: grid;
  gap: 18px;
  width: min(var(--max-width), calc(100% - 48px));
  margin: 0 auto;
  padding: 22px 0 42px;
}

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

.step-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

.step-item::before {
  position: absolute;
  inset: auto 12px 0;
  height: 3px;
  border-radius: 999px 999px 0 0;
  background: transparent;
  content: "";
}

.step-item > .step-number {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  box-sizing: border-box;
}

.step-item b {
  min-width: 0;
}

.step-item.active {
  border-color: color-mix(in srgb, var(--primary) 46%, var(--line));
  color: var(--ink);
  background: color-mix(in srgb, var(--primary-soft) 36%, var(--surface));
  box-shadow: none;
}

.step-item.active::before {
  background: color-mix(in srgb, var(--primary) 82%, var(--teal));
}

.step-item.active > .step-number {
  border-color: transparent;
  background: color-mix(in srgb, var(--primary) 88%, #163a9d);
  color: #ffffff;
  box-shadow: none;
}

.step-item.done > .step-number {
  border-color: transparent;
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 78%, var(--ink));
}

.flow-status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, auto);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 12px 14px;
}

.flow-status b {
  display: block;
  color: var(--ink);
  font-size: 15px;
}

.flow-status span,
.flow-status small {
  color: var(--muted);
  font-size: 13px;
}

.flow-saved-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.flow-saved-items span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 4px 9px;
  white-space: nowrap;
}

.flow-saved-items b {
  display: inline;
  font-size: 12px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  animation: surfaceIn 220ms ease-out both;
}

.metric-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 10px 12px;
}

.metric-card::before {
  display: block;
  grid-column: 1;
  width: 34px;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 16%, transparent);
  content: "";
}

.metric-card span {
  grid-column: 1;
  color: var(--ink-soft);
  font-weight: 900;
}

.metric-card strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.metric-card small {
  align-self: center;
  color: var(--muted);
  font-weight: 800;
}

.metric-teal {
  color: var(--teal);
}

.metric-blue {
  color: var(--primary);
}

.metric-violet {
  color: var(--violet);
}

.screen {
  display: none;
}

.screen.active {
  display: grid;
  gap: 16px;
  animation: surfaceIn 240ms ease-out both;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(14px);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel-head.spread,
.spread {
  align-items: center;
  justify-content: space-between;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 28px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 900;
  padding: 4px 10px;
  white-space: nowrap;
}

.section-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.assignment-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(260px, 1.3fr);
  gap: 12px;
  margin-bottom: 14px;
}

.pretest-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.28fr);
  gap: 14px;
  align-items: start;
}

.pretest-case {
  position: sticky;
  top: 96px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.pretest-case p,
.compact-block p,
.case-text {
  color: var(--ink-soft);
}

.pretest-form {
  display: grid;
  gap: 12px;
}

.choice-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 22px;
  padding: 4px 0 0;
}

.choice-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 30px;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 3px 0;
  font-weight: 700;
}

.choice-list label:hover {
  color: var(--primary-strong);
}

.choice-list input {
  width: auto;
  min-height: auto;
  margin-top: 4px;
}

.pretest-result {
  margin-top: 14px;
}

.assignment-result {
  margin-top: 10px;
}

.score-card {
  display: grid;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--teal) 44%, var(--line));
  border-radius: var(--radius);
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 72%, var(--ink));
  padding: 13px;
}

.assignment-score-card {
  border-color: color-mix(in srgb, var(--amber) 44%, var(--line));
  background: var(--amber-soft);
  color: color-mix(in srgb, var(--amber) 66%, var(--ink));
}

.score-card h2 {
  margin-top: 8px;
}

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

.pretest-feedback-block {
  display: grid;
  align-content: start;
  gap: 7px;
  border: 1px solid color-mix(in srgb, currentColor 18%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-solid) 76%, transparent);
  padding: 10px;
}

.pretest-feedback-block h3 {
  margin: 0;
  font-size: 13px;
}

.pretest-feedback-block ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.pretest-feedback-block li,
.pretest-feedback-block p,
.next-step-advice {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.65;
}

.next-step-advice {
  display: grid;
  gap: 4px;
  border-left: 3px solid color-mix(in srgb, var(--teal) 70%, var(--primary));
  padding-left: 10px;
}

.next-step-advice b {
  color: var(--ink);
}

@media (max-width: 820px) {
  .pretest-feedback-grid {
    grid-template-columns: 1fr;
  }
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
}

.field-help,
.score-note,
.char-meter {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.55;
}

.score-note {
  margin-bottom: 0;
}

.char-meter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 5px 8px;
}

.char-meter.ok {
  border-color: color-mix(in srgb, var(--teal) 38%, var(--line));
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 76%, var(--ink));
}

.char-meter.warn {
  border-color: color-mix(in srgb, var(--amber) 42%, var(--line));
  background: var(--amber-soft);
  color: color-mix(in srgb, var(--amber) 72%, var(--ink));
}

select,
textarea,
input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-solid);
  color: var(--ink);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

select:hover,
textarea:hover,
input:hover {
  border-color: color-mix(in srgb, var(--primary) 42%, var(--line-strong));
}

select,
input {
  min-height: 44px;
  padding: 8px 10px;
}

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

::placeholder {
  color: color-mix(in srgb, var(--muted) 76%, transparent);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.button-row button {
  flex: 0 1 190px;
}

.next-step-row {
  justify-content: flex-end;
  align-items: center;
  margin-top: 18px;
  margin-bottom: 0;
}

.next-step-row button {
  flex: 0 0 auto;
  min-width: 220px;
  padding-inline: 24px;
}

.draw-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: auto;
  max-width: 100%;
  margin-top: 18px;
  padding: 0;
}

.draw-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  min-height: 48px;
  border-radius: 8px;
  font-weight: 950;
  letter-spacing: 0;
  padding: 0 18px;
  white-space: nowrap;
}

.draw-actions svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.draw-actions .secondary {
  flex: 0 0 auto;
  min-width: 156px;
  border: 1px solid color-mix(in srgb, var(--line-strong) 74%, transparent);
  background: var(--surface-solid);
  color: var(--ink-soft);
  box-shadow: none;
}

.draw-actions .secondary:hover {
  border-color: color-mix(in srgb, var(--primary) 28%, var(--line));
  background: var(--primary-soft);
  color: var(--primary-strong);
  box-shadow: 0 10px 20px rgba(59, 111, 245, 0.08);
  transform: translateY(-1px);
}

.draw-actions .action-primary {
  min-width: 176px;
  background:
    linear-gradient(135deg, #4f7df7, var(--primary-strong)),
    var(--primary);
  box-shadow: 0 14px 26px rgba(59, 111, 245, 0.2);
}

.draw-actions .action-primary:hover {
  box-shadow: 0 18px 32px rgba(59, 111, 245, 0.24);
  transform: translateY(-1px);
}

.assignment-card {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.condition-assignment-card {
  display: grid;
  gap: 10px;
  min-height: 92px;
  border: 1px solid color-mix(in srgb, var(--teal) 44%, var(--line));
  border-radius: var(--radius);
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 70%, var(--ink));
  padding: 14px;
  margin-bottom: 14px;
}

.assignment-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.case-id,
.condition-pill,
.scenario-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  padding: 4px 9px;
}

.case-id {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.condition-pill {
  background: var(--amber-soft);
  color: color-mix(in srgb, var(--amber) 72%, var(--ink));
  white-space: nowrap;
}

.assignment-card h2 {
  margin-top: 8px;
  margin-bottom: 10px;
}

.case-overview {
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
}

.case-meta dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.case-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0;
  align-items: stretch;
}

.case-meta div {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  min-height: auto;
  border-top: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  padding: 10px 12px;
}

.case-meta div:first-child {
  border-top: 0;
}

.case-meta-primary {
  background: transparent;
}

.case-meta dd {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.case-meta-primary dd {
  color: var(--ink);
  font-size: 16px;
}

.case-summary {
  max-width: 90ch;
  margin: 14px 0 0;
  color: var(--ink);
  font-family: KaiTi, STKaiti, "KaiTi", "楷体", "Kaiti SC", SimSun, serif;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.5;
  white-space: pre-line;
}

.assignment-reading-layout {
  display: grid;
  gap: 16px;
}

.assignment-reading-layout.has-visual {
  grid-template-columns: minmax(0, 1.42fr) minmax(280px, 0.86fr);
  align-items: start;
}

.assignment-reading-main {
  min-width: 0;
}

.case-readiness {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.case-readiness button {
  min-width: min(100%, 360px);
  min-height: 52px;
}

.assignment-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.assignment-facts.compact {
  grid-template-columns: minmax(220px, 320px);
  margin-bottom: 0;
}

.assignment-facts div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 9px 10px;
}

.assignment-facts dt {
  color: var(--muted);
  font-size: 12px;
}

.assignment-facts dd {
  margin: 2px 0 0;
  font-weight: 800;
}

#screen-task.active {
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 2.15fr);
  align-items: start;
}

#screen-task.static-task-layout.active {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

#screen-task.static-task-layout .scenario-panel,
#screen-task.static-task-layout #static-shell {
  min-width: 0;
}

#screen-task.static-task-layout #static-shell {
  align-self: start;
}

#screen-task.static-task-layout .response-panel {
  min-height: 100%;
}

.scenario-panel {
  position: sticky;
  top: 102px;
  align-self: start;
  padding: 14px;
}

.scenario-visual {
  position: relative;
  overflow: hidden;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  aspect-ratio: 1 / 0.84;
}

.scenario-visual img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scenario-visual figcaption {
  position: absolute;
  left: 12px;
  bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  background: rgba(5, 16, 32, 0.66);
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  padding: 6px 10px;
  backdrop-filter: blur(12px);
}

.objective-strip {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.objective-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.objective-list span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid color-mix(in srgb, var(--teal) 28%, var(--line));
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 900;
  padding: 3px 8px;
}

.objective-list span:nth-child(2) {
  border-color: color-mix(in srgb, var(--primary) 28%, var(--line));
}

.objective-list span:nth-child(3) {
  border-color: color-mix(in srgb, var(--violet) 28%, var(--line));
}

.task-progress-card {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.task-progress-card ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-progress-card li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.task-progress-card li::before {
  display: grid;
  flex: 0 0 22px;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--muted);
  content: counter(list-item);
  font-size: 11px;
  font-weight: 900;
}

.task-progress-card li.done::before {
  border-color: transparent;
  background: var(--teal);
  color: #ffffff;
  content: "";
}

.task-progress-card li.done::after {
  position: absolute;
  left: 7px;
  width: 8px;
  height: 5px;
  border: solid #ffffff;
  border-width: 0 0 2px 2px;
  content: "";
  transform: rotate(-45deg);
}

.task-progress-card li.active {
  color: var(--primary-strong);
}

.task-progress-card li.active::before {
  border-color: var(--primary);
  color: var(--primary-strong);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 13%, transparent);
}

.scenario-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.scenario-meta span {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink-soft);
}

.case-reading {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.7fr);
  gap: 12px;
}

.scenario-panel .case-reading {
  grid-template-columns: 1fr;
}

.scenario-panel .reading-block {
  max-height: none;
  overflow: visible;
}

.case-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 10px;
}

.case-toc a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--surface-soft);
  padding: 5px 10px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.reading-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 9px 10px;
}

.reading-block h3 {
  margin: 0 0 7px;
  color: var(--ink);
  font-size: 13px;
}

.scenario-panel .section-kicker {
  font-size: 11px;
}

.scenario-panel .case-reading {
  gap: 8px;
}

.reading-block mark,
.case-summary-details mark {
  border-radius: 4px;
  background: color-mix(in srgb, var(--amber-soft) 74%, transparent);
  color: var(--ink);
  padding: 0 3px;
}

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

.case-section-list ul,
.case-summary-details ul {
  margin: 0;
  padding-left: 18px;
}

.case-section-list li,
.case-summary-details li {
  margin: 6px 0;
}

.sidebar-compact-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 16px;
}

.sidebar-compact-list li,
.sidebar-empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.35;
}

.case-summary-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.case-summary-details details {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 10px 12px;
}

.case-summary-details summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 800;
}

.case-text {
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
}

.condition-shell {
  display: grid;
  gap: 16px;
  min-width: 0;
}

#static-shell {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.dynamic-shell {
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.78fr);
  align-items: start;
}

.dynamic-insight-rail {
  display: grid;
  gap: 16px;
  min-width: 0;
  position: sticky;
  top: 102px;
  align-self: start;
}

.dynamic-insight-rail .ret-insight-panel {
  order: 1;
}

.dynamic-insight-rail .role-state-panel {
  order: 2;
}

.text-state-list,
.agent-state-list {
  display: grid;
  gap: 10px;
}

.agent-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.agent-state p {
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 13px;
}

.agent-state header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.agent-state strong {
  display: block;
  color: var(--primary-strong);
}

.agent-state header span {
  color: var(--muted);
  font-size: 12px;
}

.state-meter {
  display: grid;
  gap: 4px;
  margin-top: 7px;
}

.state-meter div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.state-meter i {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 64%, transparent);
}

.state-meter em {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--primary), var(--amber));
  transition: width 280ms ease;
}

.response-panel form,
.post-panel form {
  display: grid;
  gap: 12px;
}

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

.chat-column,
.ret-column {
  min-width: 0;
}

.chat-column {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  gap: 12px;
}

.chat-feed {
  min-height: 420px;
  max-height: 620px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-tint) 58%, transparent), transparent),
    var(--surface-soft);
  padding: 14px;
}

.dynamic-closing-panel {
  display: grid;
  gap: 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 26%, var(--line));
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.dynamic-closing-panel.hidden {
  display: none;
}

.dynamic-closing-panel .panel-head {
  margin: 0;
}

.dynamic-closing-panel h3 {
  margin: 0;
  font-size: 17px;
}

.dynamic-closing-panel p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  line-height: 1.55;
}

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

.dynamic-closing-grid textarea {
  min-height: 110px;
}

@media (max-width: 760px) {
  .dynamic-closing-grid {
    grid-template-columns: 1fr;
  }
}

.empty-chat {
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--muted);
  text-align: center;
}

.chat-message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.chat-message.student {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.chat-message.student .chat-avatar {
  grid-column: 2;
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.chat-message.student .chat-bubble {
  grid-column: 1;
  grid-row: 1;
  border-color: color-mix(in srgb, var(--primary) 28%, var(--line));
  background: color-mix(in srgb, var(--primary-soft) 40%, var(--surface-solid));
}

.chat-message.queued .chat-avatar {
  background: color-mix(in srgb, var(--amber-soft) 82%, var(--surface-solid));
  color: color-mix(in srgb, var(--amber) 74%, var(--ink));
}

.chat-message.queued .chat-bubble {
  border-style: dashed;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--surface-soft) 88%, transparent), color-mix(in srgb, var(--amber-soft) 42%, transparent)),
    var(--surface-solid);
}

.chat-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 72%, var(--ink));
  font-size: 12px;
  font-weight: 900;
}

.chat-bubble {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 10px 12px;
}

.chat-bubble header {
  margin-bottom: 6px;
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 900;
}

.chat-bubble p {
  margin: 8px 0 0;
  color: var(--ink-soft);
}

.voice-strip {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 8px;
}

.voice-dot {
  width: 14px;
  height: 14px;
  border: 3px solid color-mix(in srgb, var(--primary) 22%, transparent);
  border-radius: 999px;
  background: var(--primary);
}

.voice-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.voice-meta b,
.voice-meta span,
.voice-strip small {
  color: var(--ink-soft);
  font-size: 12px;
}

.agent-reveal-button {
  min-height: 34px;
  border-color: color-mix(in srgb, var(--amber) 42%, var(--line));
  background: var(--amber-soft);
  color: color-mix(in srgb, var(--amber) 74%, var(--ink));
  font-size: 12px;
  font-weight: 900;
  padding: 7px 10px;
}

.voice-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wave {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 18px;
}

.wave i {
  width: 5px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--primary), var(--teal));
  animation: wavePulse 980ms ease-in-out infinite;
}

.wave i:nth-child(1) {
  height: 7px;
  animation-delay: 0ms;
}

.wave i:nth-child(2) {
  height: 13px;
  animation-delay: 80ms;
}

.wave i:nth-child(3) {
  height: 10px;
  animation-delay: 160ms;
}

.wave i:nth-child(4) {
  height: 16px;
  animation-delay: 240ms;
}

.wave i:nth-child(5) {
  height: 9px;
  animation-delay: 320ms;
}

.wave i:nth-child(6) {
  height: 12px;
  animation-delay: 400ms;
}

audio {
  width: 150px;
  height: 34px;
}

.turn-form {
  display: grid;
  gap: 10px;
}

.outcome-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink-soft);
  padding: 10px 12px;
}

.outcome-banner p {
  margin: 4px 0 0;
}

.outcome-banner.success {
  border-color: color-mix(in srgb, var(--green) 38%, var(--line));
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--green) 76%, var(--ink));
}

.outcome-banner.failure {
  border-color: color-mix(in srgb, var(--danger) 38%, var(--line));
  background: var(--coral-soft);
  color: color-mix(in srgb, var(--danger) 78%, var(--ink));
}

.outcome-banner.continue {
  border-color: color-mix(in srgb, var(--amber) 42%, var(--line));
  background: var(--amber-soft);
  color: color-mix(in srgb, var(--amber) 70%, var(--ink));
}

.outcome-banner.recovery {
  display: block;
}

.recovery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.mini-score-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.mini-score-grid span {
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.ret-column {
  display: grid;
  align-content: start;
  gap: 12px;
}

.ret-insight-panel {
  border-color: color-mix(in srgb, var(--violet) 28%, var(--line));
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--violet) 9%, transparent), transparent 58%),
    var(--surface);
}

.ret-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 13px;
  animation: surfaceIn 220ms ease-out both;
}

.ret-panel h3 {
  color: var(--violet);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ret-panel h3::before {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: currentColor;
  box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 12%, transparent);
  content: "";
}

.ret-panel.locked {
  border-style: dashed;
  background: var(--surface-soft);
  color: var(--muted);
}

.ret-panel p,
.ret-panel li,
.ret-panel dd {
  color: var(--ink-soft);
  font-size: 13px;
}

.ret-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.ret-list div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 8px;
}

.ret-list dt {
  color: var(--muted);
  font-size: 12px;
}

.ret-list dd {
  margin: 2px 0 0;
  font-weight: 800;
}

.ret-panel ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

fieldset {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

legend {
  color: var(--primary-strong);
  font-weight: 900;
  padding: 0 6px;
}

input[type="range"] {
  min-height: 30px;
  padding: 0;
  accent-color: var(--primary);
}

.rubric-fieldset {
  gap: 12px;
}

.rubric-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 11px;
}

.rubric-item h3 {
  margin-bottom: 0;
}

.rubric-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  gap: 10px 18px;
  padding-top: 2px;
}

.post-panel .rubric-options > * {
  grid-column: auto !important;
  width: auto !important;
  min-width: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.rubric-options label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 3px 0;
  font-weight: 600;
  box-shadow: none;
}

.rubric-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 2px 0;
  color: var(--ink-soft);
  font-weight: 600;
  cursor: pointer;
}

.post-panel .rubric-options > label {
  min-height: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 2px 0 !important;
}

.rubric-options label:hover,
.rubric-option:hover {
  color: var(--primary-strong);
}

.rubric-option.selected {
  color: var(--primary-strong);
}

.rubric-option.selected span {
  color: var(--ink);
}

.rubric-options input[type="radio"],
.rubric-option input[type="radio"] {
  width: auto;
  min-height: auto;
  margin-top: 4px;
}

.rubric-options span,
.rubric-option span {
  display: grid;
  gap: 2px;
}

.rubric-options b,
.rubric-option b {
  color: var(--ink);
}

.muted {
  color: var(--muted);
}

.submission-confirmation {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  border: 1px solid color-mix(in srgb, var(--green) 42%, var(--line));
  border-radius: var(--radius);
  background: var(--teal-soft);
  padding: 16px;
}

.confirmation-head h2 {
  margin: 4px 0;
}

.confirmation-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 0;
}

.confirmation-list div {
  border: 1px solid color-mix(in srgb, var(--green) 24%, var(--line));
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 10px;
}

.confirmation-list dt {
  color: var(--muted);
  font-size: 12px;
}

.confirmation-list dd {
  margin: 3px 0 0;
  color: var(--ink);
  font-weight: 900;
}

.confirmation-note {
  margin-bottom: 0;
  color: var(--ink-soft);
}

.problem-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(var(--max-width), calc(100% - 48px));
  margin: -18px auto 84px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-solid);
  color: var(--muted);
  padding: 12px;
}

.problem-strip button {
  min-height: 38px;
}

.site-footer {
  width: min(var(--max-width), calc(100% - 48px));
  margin: -60px auto 84px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.6;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--primary-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid color-mix(in srgb, var(--teal) 44%, var(--line));
  border-radius: var(--radius);
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 72%, var(--ink));
  box-shadow: var(--shadow);
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@keyframes surfaceIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes wavePulse {
  0%,
  100% {
    transform: scaleY(0.72);
    opacity: 0.62;
  }
  50% {
    transform: scaleY(1.18);
    opacity: 1;
  }
}

@keyframes voiceSweep {
  0% {
    transform: translateX(-75%);
  }
  100% {
    transform: translateX(75%);
  }
}

@keyframes statusPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--teal) 32%, transparent);
  }
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--teal) 0%, transparent);
  }
}

@keyframes progressShimmer {
  0%,
  100% {
    opacity: 0.74;
    transform: translateX(-8px);
  }
  50% {
    opacity: 1;
    transform: translateX(8px);
  }
}

@keyframes buttonSpin {
  to {
    transform: rotate(360deg);
  }
}

  @media (max-width: 1240px) {
  #screen-task.active,
  #static-shell,
  .dynamic-shell,
  .case-reading,
  .pretest-layout,
  .interaction-grid {
    grid-template-columns: 1fr;
  }

  .scenario-panel,
  .dynamic-insight-rail,
  .pretest-case {
    position: static;
  }

  .chat-column {
    grid-template-rows: auto minmax(360px, auto) auto;
  }

  .dynamic-insight-rail {
    grid-template-columns: 1fr;
  }

  .rubric-options {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 920px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    width: 100%;
  }

  main {
    width: min(100% - 28px, var(--max-width));
    padding-top: 16px;
  }

  .stepper,
  .metric-strip,
  .assignment-grid,
  .participant-gate,
  .participant-profile-form,
  .objective-list,
  .case-overview,
  .assignment-facts {
    grid-template-columns: 1fr;
  }

  .profile-consent {
    grid-column: auto;
  }

  #save-participant-profile {
    width: 100%;
  }

  .case-meta {
    grid-template-columns: 1fr;
  }

  .assignment-reading-layout.has-visual {
    grid-template-columns: 1fr;
  }

  .step-item {
    min-height: 52px;
  }

  .assignment-head,
  .outcome-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .draw-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    max-width: none;
  }

  .draw-actions .secondary {
    min-height: 44px;
    border: 1px solid var(--line);
    background: var(--surface-solid);
    padding-inline: 12px;
  }

  .draw-actions button {
    width: 100%;
  }

  .next-step-row {
    justify-content: flex-start;
  }

  .next-step-row button {
    width: 100%;
  }

  .case-readiness {
    justify-content: stretch;
  }

  .case-readiness button {
    width: 100%;
  }

  .voice-strip {
    grid-template-columns: 18px minmax(0, 1fr);
  }

  .voice-strip audio,
  .voice-strip small {
    grid-column: 2;
    width: 100%;
  }
}

@media (max-width: 620px) {
  h1 {
    font-size: 22px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .top-actions {
    grid-template-columns: 1fr 1fr 44px;
  }

  .top-actions #refresh {
    grid-column: 1 / -1;
  }

  .panel {
    padding: 14px;
  }

  .metric-card {
    min-height: 48px;
  }

  .rubric-options {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

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

/* Product workspace refresh */
.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(320px, 1.2fr) minmax(260px, 0.9fr);
  align-items: center;
  min-height: 78px;
  padding-block: 12px;
  border-bottom-color: color-mix(in srgb, var(--line) 82%, transparent);
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
}

.brand-lockup {
  gap: 12px;
}

.brand-logo {
  position: relative;
  display: grid;
  flex: 0 0 132px;
  place-items: center;
  width: 132px;
  height: 63px;
  overflow: hidden;
  border-radius: 4px;
  background: #ffffff;
}

.brand-logo img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.brand-lockup strong {
  display: block;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 850;
  line-height: 1.18;
}

.brand-lockup span:not(.brand-logo) {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.top-title {
  min-width: 0;
  text-align: center;
}

.top-title h1 {
  margin: 0;
  color: color-mix(in srgb, var(--ink) 92%, var(--primary));
  font-family: var(--font-display);
  font-size: clamp(26px, 2.35vw, 36px);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.08;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7), 0 10px 28px rgba(15, 31, 51, 0.08);
  text-wrap: balance;
}

.top-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.2;
}

.top-actions {
  gap: 12px;
}

.icon-button,
.user-chip,
.ghost-link {
  touch-action: manipulation;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  border-radius: 999px;
}

.panel,
.participant-gate,
.stepper,
.pretest-case,
.char-meter,
.score-card,
.case-brief-card,
.chat-feed,
.live-pill,
.timer-pill,
.turn-pill,
.ghost-link,
.popover-facts div {
  border-radius: var(--radius);
}

.panel {
  background: color-mix(in srgb, var(--surface-solid) 98%, transparent);
  box-shadow: var(--shadow-soft);
}

.icon-button svg,
.timer-pill svg,
.mobile-bottom-nav svg,
.send-button svg,
.user-chip svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.help-request-button {
  position: relative;
}

.help-request-button.is-loading {
  color: var(--primary-strong);
}

.help-request-button.is-loading::after,
.help-request-button.is-complete::after {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  content: "";
}

.help-request-button.is-loading::after {
  background: var(--amber);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 18%, transparent);
  animation: statusPulse 900ms ease-in-out infinite;
}

.help-request-button.is-complete::after {
  background: var(--teal);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--teal) 18%, transparent);
}

.user-chip {
  display: grid;
  grid-template-columns: 44px minmax(120px, auto) 18px;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  padding: 4px 10px 4px 4px;
}

.user-chip:hover {
  background: var(--surface-soft);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: linear-gradient(145deg, #9bb8ff, #2f6bea);
  color: #ffffff;
  font-weight: 950;
}

.user-copy {
  display: grid;
  min-width: 0;
  text-align: left;
}

.user-copy b {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.1;
}

.user-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-popover {
  position: fixed;
  top: 82px;
  right: max(24px, calc((100vw - var(--max-width)) / 2 + 24px));
  z-index: 60;
  display: grid;
  gap: 12px;
  width: min(380px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-solid) 96%, transparent);
  box-shadow: var(--shadow);
  padding: 14px;
  backdrop-filter: blur(18px);
  animation: surfaceIn 180ms ease-out both;
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.popover-head strong {
  color: var(--ink);
  font-size: 15px;
}

.ghost-link {
  min-height: 34px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--primary-strong);
  box-shadow: none;
  padding: 6px 10px;
}

.popover-facts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.popover-facts div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 9px 10px;
}

.popover-facts dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.popover-facts dd {
  min-width: 0;
  margin: 0;
  color: var(--ink-soft);
  font-weight: 900;
}

.help-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--ink-soft);
}

.preference-row {
  display: grid;
  grid-template-columns: auto 44px minmax(74px, auto) minmax(86px, auto);
  align-items: center;
  gap: 8px;
}

#reset-participant {
  min-height: 38px;
  border: 1px solid color-mix(in srgb, var(--danger) 24%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface-solid));
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

.participant-gate {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(0, 1.28fr);
  gap: 16px;
  align-items: start;
  border: 1px solid color-mix(in srgb, var(--primary) 20%, var(--line));
  border-radius: var(--radius);
  background: var(--surface-solid);
  box-shadow: var(--shadow-soft);
  padding: 16px 18px;
}

.participant-gate.completed {
  border-color: color-mix(in srgb, var(--teal) 30%, var(--line));
  background: var(--surface-solid);
}

.participant-gate.consent-pending {
  border-color: color-mix(in srgb, var(--amber) 36%, var(--line));
}

.participant-gate-copy h2 {
  margin: 6px 0;
  font-size: 20px;
}

.participant-gate-copy p {
  max-width: 58ch;
  margin: 0;
  color: var(--ink-soft);
}

.participant-profile-form {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(180px, 1fr) minmax(130px, 0.72fr) auto;
  gap: 10px;
  align-items: end;
}

.participant-profile-form label {
  margin: 0;
}

.profile-consent {
  grid-column: 1 / -2;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  border: 1px solid color-mix(in srgb, var(--teal) 22%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--teal-soft) 48%, var(--surface-solid));
  color: var(--ink-soft);
  padding: 9px 10px;
}

.profile-consent input {
  width: auto;
  min-height: auto;
  margin-top: 3px;
}

#save-participant-profile {
  align-self: stretch;
  min-width: 164px;
}

.research-consent-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
}

.research-consent-modal.hidden {
  display: none;
}

.research-consent-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 38%, transparent);
  backdrop-filter: blur(8px);
}

.research-consent-card {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  width: min(760px, 100%);
  max-height: min(86dvh, 820px);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line));
  border-radius: 16px;
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  padding: 18px;
}

.research-consent-head h2 {
  margin: 6px 0;
  font-size: clamp(20px, 3vw, 28px);
}

.research-consent-head p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.6;
}

.research-consent-body {
  display: grid;
  gap: 12px;
  max-height: min(46dvh, 420px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--soft) 52%, var(--surface-solid));
  padding: 12px;
}

.research-consent-body section {
  display: grid;
  gap: 5px;
}

.research-consent-body h3 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
}

.research-consent-body p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.65;
}

.research-consent-check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid color-mix(in srgb, var(--teal) 28%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--teal-soft) 52%, var(--surface-solid));
  color: var(--ink);
  font-weight: 760;
  line-height: 1.55;
  padding: 10px 12px;
}

.research-consent-check input {
  width: 18px;
  min-height: 18px;
  margin-top: 3px;
}

.research-consent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.secondary-button {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--soft) 68%, var(--surface-solid));
  color: var(--ink);
}

body.consent-modal-open {
  overflow: hidden;
}

.pretest-panel.is-locked::before {
  display: block;
  margin-bottom: 12px;
  border: 1px solid color-mix(in srgb, var(--teal) 28%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--teal-soft) 56%, var(--surface-solid));
  color: color-mix(in srgb, var(--teal) 72%, var(--ink));
  content: attr(data-lock-message);
  font-weight: 900;
  padding: 10px 12px;
}

.stepper {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-solid) 96%, transparent);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.stepper::before {
  position: absolute;
  top: 47px;
  right: 11%;
  left: 11%;
  height: 0;
  border-top: 2px dashed color-mix(in srgb, var(--line-strong) 62%, transparent);
  content: "";
}

.step-item {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 64px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  overflow: visible;
  padding: 8px 10px;
  text-align: left;
}

.step-item:hover {
  background: color-mix(in srgb, var(--primary-soft) 48%, transparent);
  box-shadow: none;
  transform: none;
}

.step-item::before {
  display: none;
}

.step-number {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--muted);
  font-size: 18px;
  font-weight: 850;
  line-height: 1;
  box-sizing: border-box;
}

.step-copy {
  display: grid;
  width: auto;
  height: auto;
  gap: 2px;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  place-items: start;
}

.step-copy b {
  color: inherit;
  font-family: var(--font-display);
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.18;
}

.step-copy small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.step-item.active {
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line));
  background: color-mix(in srgb, var(--primary-soft) 42%, var(--surface-solid));
  color: var(--primary-strong);
  box-shadow: none;
}

.step-item.active::after {
  display: none;
}

.step-item.active .step-number {
  border-color: #ffffff;
  background: color-mix(in srgb, var(--primary) 88%, #163a9d);
  color: #ffffff;
  box-shadow: none;
  animation: none;
}

.step-item.done .step-number {
  border-color: transparent;
  background: var(--teal-soft);
  color: color-mix(in srgb, var(--teal) 80%, var(--ink));
}

#screen-task.active {
  grid-template-columns: minmax(310px, 0.82fr) minmax(0, 2.5fr);
  gap: 18px;
}

.scenario-panel {
  overflow: hidden;
}

.scenario-panel .panel-head {
  margin-bottom: 8px;
}

.scenario-panel .panel-head h2 {
  font-size: 18px;
}

.scenario-visual {
  aspect-ratio: 1 / 0.72;
  border-radius: 14px;
  box-shadow: 0 18px 34px rgba(15, 31, 51, 0.12);
}

.scenario-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.fact-chip {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  padding: 7px 9px;
}

.fact-chip.wide {
  grid-column: 1 / -1;
}

.fact-chip i {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-style: normal;
  font-weight: 950;
}

.fact-chip b {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-brief-card {
  border-color: color-mix(in srgb, var(--primary) 20%, var(--line));
  background: linear-gradient(145deg, color-mix(in srgb, var(--primary-soft) 34%, transparent), transparent 70%), var(--surface-soft);
}

.case-detail summary {
  cursor: pointer;
  color: var(--primary-strong);
  font-weight: 900;
}

.role-brief {
  border-color: color-mix(in srgb, var(--teal) 24%, var(--line));
}

.dynamic-shell {
  grid-template-columns: minmax(0, 2fr) minmax(260px, 0.72fr);
  gap: 18px;
}

.interaction-panel {
  min-width: 0;
}

.interaction-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(270px, 0.72fr);
  align-items: stretch;
}

.chat-column {
  grid-template-rows: auto minmax(420px, 1fr) auto;
}

.interaction-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.interaction-status .outcome-banner {
  flex: 1 1 260px;
}

.live-pill,
.timer-pill,
.turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--ink-soft);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
}

.live-pill i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--teal);
  animation: statusPulse 1500ms ease-in-out infinite;
}

.timer-pill {
  color: var(--teal);
}

.turn-pill {
  color: var(--primary-strong);
}

.chat-feed {
  border-radius: 16px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--primary-soft) 22%, transparent), transparent 38%),
    var(--surface-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.chat-message {
  grid-template-columns: 44px minmax(0, 1fr);
  animation: surfaceIn 220ms ease-out both;
}

.chat-message.student {
  grid-template-columns: minmax(0, 1fr) 44px;
}

.chat-avatar {
  width: 44px;
  height: 44px;
  background: transparent;
}

.avatar-face {
  position: relative;
  display: block;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: linear-gradient(145deg, #dbeafe, #eff6ff);
  box-shadow: 0 8px 18px rgba(15, 31, 51, 0.13);
}

.avatar-head {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #f0b58f;
  transform: translateX(-50%);
}

.avatar-body {
  position: absolute;
  right: 8px;
  bottom: -3px;
  left: 8px;
  height: 18px;
  border-radius: 14px 14px 0 0;
  background: #2563eb;
}

.avatar-face b {
  position: absolute;
  right: 4px;
  bottom: 3px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--primary-strong);
  font-size: 10px;
}

.avatar-face.resident .avatar-body {
  background: #ef6f5a;
}

.avatar-face.property .avatar-body {
  background: #0f8f83;
}

.avatar-face.rider .avatar-body {
  background: #2563eb;
}

.avatar-face.official .avatar-body {
  background: #334155;
}

.avatar-face.student-face .avatar-body {
  background: #7c3aed;
}

.chat-bubble {
  border-radius: 14px;
  box-shadow: 0 10px 22px rgba(15, 31, 51, 0.06);
}

.chat-bubble header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-bubble header b {
  color: var(--primary-strong);
}

.chat-bubble header time {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.message-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.mini-wave em {
  display: block;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--primary), var(--teal));
  animation: wavePulse 1000ms ease-in-out infinite;
}

.send-button {
  min-width: 104px;
  min-height: 48px;
}

.chat-ret-rail {
  min-width: 0;
}

.chat-ret-rail .ret-insight-panel {
  height: 100%;
}

.dynamic-insight-rail {
  position: sticky;
  top: 96px;
}

.agent-state {
  border-radius: 14px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-soft);
}

.agent-state header {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 10px;
}

.mini-wave {
  display: flex;
  align-items: end;
  justify-content: end;
  gap: 3px;
  height: 22px;
}

.mini-wave em:nth-child(1) { height: 8px; animation-delay: 0ms; }
.mini-wave em:nth-child(2) { height: 16px; animation-delay: 110ms; }
.mini-wave em:nth-child(3) { height: 11px; animation-delay: 220ms; }

.ret-section {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.ret-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.ret-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ret-tags span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line));
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
}

.ret-tags b {
  color: var(--ink);
}

.ret-section.boundary {
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--amber) 32%, var(--line));
  background: var(--amber-soft);
  padding: 10px;
}

.mobile-bottom-nav {
  display: none;
}

@keyframes activeStepGlow {
  0%,
  100% {
    box-shadow:
      0 0 0 6px rgba(59, 111, 245, 0.14),
      0 16px 28px rgba(59, 111, 245, 0.22);
  }
  50% {
    box-shadow:
      0 0 0 10px rgba(59, 111, 245, 0.07),
      0 20px 36px rgba(59, 111, 245, 0.28);
  }
}

@media (max-width: 1240px) {
  .topbar {
    grid-template-columns: minmax(260px, 0.85fr) minmax(220px, 1fr) minmax(220px, 0.8fr);
  }

  #screen-task.active,
  .dynamic-shell,
  .interaction-grid {
    grid-template-columns: 1fr;
  }

  .dynamic-insight-rail {
    position: static;
  }
}

@media (max-width: 920px) {
  body {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .top-title {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }

  .user-copy {
    display: none;
  }

  .user-chip {
    grid-template-columns: 40px 18px;
    min-width: 70px;
  }

  .top-popover {
    top: 118px;
    right: 14px;
  }

  .participant-gate,
  .participant-profile-form {
    grid-template-columns: 1fr;
  }

  .profile-consent {
    grid-column: auto;
  }

  #save-participant-profile {
    width: 100%;
  }

  .stepper {
    gap: 6px;
    padding: 12px 8px;
  }

  .stepper::before {
    top: 30px;
    right: 13%;
    left: 13%;
  }

  .step-item {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 7px;
    min-height: 84px;
    padding: 8px 4px;
    text-align: center;
  }

  .step-number {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .step-copy {
    justify-items: center;
    place-items: center;
  }

  .step-copy b {
    font-size: 12px;
    line-height: 1.15;
  }

  .step-copy small {
    font-size: 10px;
    line-height: 1.2;
  }

  .scenario-meta {
    grid-template-columns: 1fr;
  }

  .mobile-bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 55;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
    box-shadow: 0 -14px 30px rgba(15, 31, 51, 0.1);
    padding: 7px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    backdrop-filter: blur(18px);
  }

  .mobile-bottom-nav button {
    display: grid;
    place-items: center;
    gap: 3px;
    min-height: 54px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
    padding: 5px 4px;
  }

  .mobile-bottom-nav button.active {
    background: var(--primary-soft);
    color: var(--primary-strong);
  }

  .mobile-bottom-nav span {
    font-size: 11px;
    font-weight: 900;
  }

  .screen.active {
    scroll-margin-bottom: 112px;
  }

  .condition-shell,
  .post-panel,
  .problem-strip {
    margin-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .site-footer {
    margin: calc(-70px - env(safe-area-inset-bottom)) auto calc(92px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 620px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-inline: 14px;
  }

  .top-actions {
    display: flex;
    width: auto;
    max-width: 100%;
    gap: 8px;
    justify-content: flex-end;
  }

  .icon-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
  }

  .user-chip {
    grid-template-columns: 34px 16px;
    gap: 6px;
    min-width: 62px;
    min-height: 40px;
    padding: 3px 8px 3px 3px;
  }

  .user-avatar {
    width: 34px;
    height: 34px;
  }

  .brand-logo,
  .brand-logo img {
    width: 112px;
    height: 53px;
  }

  .brand-logo {
    flex-basis: 112px;
  }

  .brand-lockup div {
    display: none;
  }

  .top-title h1 {
    font-size: 19px;
  }

  .top-title p {
    font-size: 11px;
  }

  .top-popover {
    top: 110px;
  }

  .chat-feed {
    min-height: 360px;
  }

  .popover-facts div {
    grid-template-columns: 72px minmax(0, 1fr);
  }
}

/* Viewport-responsive alignment layer */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.topbar {
  min-width: 0;
  padding-inline: max(var(--page-gutter), calc((100vw - var(--max-width)) / 2 + var(--page-gutter)));
}

.topbar > *,
.brand-lockup,
.brand-lockup > div,
.top-title,
.top-actions,
main,
.screen,
.panel,
.participant-gate,
.participant-profile-form,
.condition-shell,
.dynamic-shell,
.interaction-grid,
.chat-column,
.chat-ret-rail,
.dynamic-insight-rail {
  min-width: 0;
}

main {
  width: min(var(--max-width), calc(100% - (var(--page-gutter) * 2)));
}

.top-title h1,
.top-title p,
.brand-lockup strong,
.brand-lockup span:not(.brand-logo) {
  overflow-wrap: anywhere;
}

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

.participant-profile-form input,
.participant-profile-form select,
.participant-profile-form button,
.message-actions,
.rubric-options,
.rubric-option {
  min-width: 0;
}

.scenario-panel,
.pretest-case,
.dynamic-insight-rail {
  max-height: calc(100dvh - 120px);
  overflow: auto;
}

@media (max-width: 1180px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 8px;
  }

  .top-title {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }

  .top-actions {
    justify-self: end;
  }

  .participant-gate,
  .pretest-layout,
  #screen-task.active,
  .dynamic-shell,
  .interaction-grid,
  .case-reading,
  .case-summary-details {
    grid-template-columns: 1fr;
  }

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

  .profile-consent {
    grid-column: 1 / -1;
  }

  #save-participant-profile {
    width: min(100%, 260px);
  }

  .scenario-panel,
  .pretest-case,
  .dynamic-insight-rail {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .chat-column {
    grid-template-rows: auto minmax(360px, auto) auto;
  }
}

@media (max-width: 820px) {
  :root {
    --page-gutter: 14px;
  }

  main {
    gap: 14px;
    padding-top: 16px;
  }

  .participant-profile-form,
  .assignment-grid,
  .assignment-facts,
  .objective-list,
  .metric-strip,
  .flow-status {
    grid-template-columns: 1fr;
  }

  .flow-saved-items {
    justify-content: flex-start;
  }

  #save-participant-profile {
    width: 100%;
  }

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

  .stepper::before {
    display: none;
  }

  .step-item {
    min-height: 58px;
  }

  .panel-head.spread,
  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-head.spread > button {
    width: 100%;
  }

  .chat-feed {
    min-height: min(360px, 52dvh);
    max-height: none;
  }

  .research-consent-modal {
    padding: 12px;
  }

  .research-consent-card {
    max-height: calc(100dvh - 24px);
    padding: 14px;
  }

  .research-consent-actions {
    justify-content: stretch;
  }

  .research-consent-actions button {
    flex: 1 1 180px;
  }
}

@media (max-width: 520px) {
  :root {
    --page-gutter: 12px;
  }

  .topbar {
    padding-inline: var(--page-gutter);
  }

  main {
    width: calc(100% - (var(--page-gutter) * 2));
  }

  .problem-strip {
    width: calc(100% - (var(--page-gutter) * 2));
    margin-bottom: calc(112px + env(safe-area-inset-bottom));
  }

  .site-footer {
    width: calc(100% - (var(--page-gutter) * 2));
    margin: calc(-88px - env(safe-area-inset-bottom)) auto calc(112px + env(safe-area-inset-bottom));
  }

  .stepper {
    gap: 8px;
    padding: 10px;
  }

  .step-item {
    grid-template-columns: 36px minmax(0, 1fr);
    justify-items: start;
    min-height: 56px;
    text-align: left;
  }

  .step-number {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .preference-row {
    grid-template-columns: 1fr;
  }
}

/* Formal experiment flow refinements */
.participant-gate {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 90;
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  transform: translate(-50%, -50%);
  box-shadow: var(--shadow), 0 0 0 100vmax color-mix(in srgb, var(--ink) 42%, transparent);
}

body.participant-modal-open,
body.task-brief-modal-open,
body.interaction-feedback-modal-open,
body.dynamic-ending-modal-open,
body.experiment-end-modal-open {
  overflow: hidden;
}

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

.participant-profile-form .profile-consent,
#save-participant-profile {
  grid-column: 1 / -1;
}

.task-brief-modal,
.interaction-feedback-modal,
.dynamic-ending-modal,
.experiment-end-modal {
  position: fixed;
  inset: 0;
  z-index: 88;
  display: grid;
  place-items: center;
  padding: 18px;
}

.task-brief-modal.hidden,
.interaction-feedback-modal.hidden,
.dynamic-ending-modal.hidden,
.experiment-end-modal.hidden {
  display: none;
}

.task-brief-backdrop,
.interaction-feedback-backdrop,
.dynamic-ending-backdrop,
.experiment-end-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 40%, transparent);
  backdrop-filter: blur(8px);
}

.task-brief-card,
.interaction-feedback-card,
.dynamic-ending-card,
.experiment-end-card {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  width: min(760px, 100%);
  max-height: min(86dvh, 760px);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line));
  border-radius: 16px;
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  padding: 18px;
}

.task-brief-head h2,
.interaction-feedback-head h2,
.dynamic-ending-head h2,
.experiment-end-head h2 {
  margin: 6px 0 0;
  font-size: clamp(20px, 3vw, 26px);
}

.task-brief-body,
.interaction-feedback-body {
  display: grid;
  gap: 12px;
  overflow: auto;
  max-height: min(58dvh, 480px);
}

.task-brief-section,
.interaction-feedback-section {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.task-brief-section h3,
.interaction-feedback-section h3 {
  margin: 0;
  color: var(--primary-strong);
  font-size: 15px;
}

.task-brief-section p,
.interaction-feedback-section p,
.dynamic-ending-head p,
.experiment-end-head p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.65;
}

.dynamic-ending-checklist {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
  line-height: 1.6;
}

.dynamic-ending-actions,
.dynamic-closing-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.task-brief-actions,
.interaction-feedback-actions,
.experiment-end-actions {
  display: flex;
  justify-content: flex-end;
}

.assignment-visual {
  position: relative;
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  aspect-ratio: 16 / 10;
}

.assignment-visual img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.case-detail-block {
  display: grid;
  gap: 10px;
}

.case-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.case-detail-head h3,
.case-detail-block h3 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
}

.case-detail-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.case-quick-summary {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 10px;
}

.case-quick-summary summary {
  color: var(--primary-strong);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.quick-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding-top: 10px;
}

.quick-summary-grid section {
  min-width: 0;
}

.quick-summary-grid h4 {
  margin-top: 0;
}

@media (max-width: 760px) {
  .quick-summary-grid {
    grid-template-columns: 1fr;
  }
}

.role-task-focus dl,
.feedback-facts {
  display: grid;
  gap: 7px;
  margin: 0;
}

.role-task-focus dl div,
.feedback-facts div {
  display: grid;
  gap: 3px;
}

.role-task-focus dt,
.feedback-facts dt {
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 900;
}

.role-task-focus dd,
.feedback-facts dd {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.42;
}

.role-task-focus dd ul {
  margin: 0;
  padding-left: 18px;
}

.reminder-block {
  border-color: color-mix(in srgb, var(--amber) 30%, var(--line));
}

#screen-task.dynamic-task-layout.active {
  grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
}

#screen-task.dynamic-task-layout .dynamic-shell,
#screen-task.dynamic-task-layout .interaction-grid {
  display: block;
}

#screen-task.dynamic-task-layout .chat-ret-rail,
#screen-task.dynamic-task-layout .dynamic-insight-rail {
  display: none !important;
}

#screen-task.dynamic-task-layout .interaction-panel {
  min-height: calc(100dvh - 172px);
}

#screen-task.dynamic-task-layout .chat-column {
  grid-template-rows: auto minmax(520px, 1fr) auto;
}

#screen-task.dynamic-task-layout .chat-feed {
  min-height: min(560px, 58dvh);
}

.next-stage-rule {
  margin-top: 8px;
  color: var(--ink-soft);
  line-height: 1.6;
}

@media (max-width: 900px) {
  .participant-gate,
  #screen-task.dynamic-task-layout.active {
    grid-template-columns: 1fr;
  }

  #screen-task.dynamic-task-layout .interaction-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .participant-profile-form,
  .case-summary-details {
    grid-template-columns: 1fr;
  }

  .task-brief-card,
  .interaction-feedback-card {
    max-height: calc(100dvh - 24px);
    padding: 14px;
  }
}
