:root {
  --ink: #18201f;
  --muted: #66706e;
  --line: #d8dedc;
  --paper: #ffffff;
  --surface: #f3f5f4;
  --accent: #087f5b;
  --accent-dark: #056747;
  --accent-soft: #e4f3ed;
  --blue: #2456a6;
  --warning: #a34a10;
  --danger: #a12c35;
  --shadow: 0 18px 45px rgb(23 34 31 / 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--surface);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--surface);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 0.96);
}

.brand-block,
.topbar-actions,
.access-row,
.scenario-header,
.answer-heading,
.workspace-footer,
.book-header,
.book-tools,
.flag-row {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 6px;
  color: white;
  background: var(--accent);
  font-weight: 800;
}

.brand-block div {
  display: grid;
  gap: 1px;
}

.brand-block strong {
  font-size: 15px;
}

.brand-block div span {
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  gap: 12px;
}

.session-identity {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.session-identity > span {
  color: var(--muted);
  font-size: 11px;
}

.code-button,
.switch-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
}

.code-button {
  padding: 0 10px;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
}

.switch-button {
  padding: 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

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

.save-state.saving {
  color: var(--blue);
}

.save-state.error {
  color: var(--danger);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: white;
  font-size: 21px;
}

.header-book-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: white;
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  min-height: calc(100vh - 64px);
}

.access-view,
.intro-view,
.profile-view,
.completed-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: calc(100vh - 64px);
  padding: 32px 20px;
  place-items: center;
}

.access-panel,
.intro-panel,
.profile-panel,
.completed-panel {
  width: 100%;
  max-width: 620px;
  min-width: 0;
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.intro-panel {
  max-width: 760px;
}

.access-panel h1,
.intro-panel h1,
.profile-panel h1,
.completed-panel h1 {
  max-width: 560px;
  margin: 9px 0 12px;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.08;
}

.intro-panel h1 {
  max-width: 680px;
}

.access-panel p,
.profile-panel > p,
.completed-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.access-panel .book-credit {
  margin: 0 0 8px;
  color: var(--ink);
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

#access-form {
  margin-top: 0;
}

.access-primary {
  width: 100%;
  margin-top: 20px;
}

.access-divider {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 26px 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.access-divider::before,
.access-divider::after {
  flex: 1;
  height: 1px;
  background: var(--line);
  content: "";
}

.access-note {
  margin: 11px 0 0;
  font-size: 12px;
}

label {
  color: #3f4947;
  font-size: 13px;
  font-weight: 650;
}

.access-row {
  gap: 8px;
  margin-top: 8px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #bfc8c5;
  border-radius: 5px;
  color: var(--ink);
  background: white;
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  padding: 10px 12px;
  line-height: 1.45;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.access-row button,
.primary-button,
.secondary-button,
.book-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 5px;
  font-weight: 700;
}

.access-row button,
.primary-button {
  border: 1px solid var(--accent);
  color: white;
  background: var(--accent);
}

.access-row button:hover,
.primary-button:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.secondary-button,
.book-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.profile-form {
  display: grid;
  min-width: 0;
  gap: 17px;
  margin-top: 25px;
}

.profile-form label {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.profile-form .primary-button {
  margin-top: 8px;
}

.intro-lead {
  max-width: 680px;
  margin: 12px 0 24px;
  color: var(--muted);
  line-height: 1.6;
}

.instruction-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.instruction-list li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 13px;
  padding: 13px 0;
  border-top: 1px solid #e2e7e5;
}

.instruction-list li > span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.instruction-list strong {
  font-size: 14px;
}

.instruction-list p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.protocol-note {
  margin-top: 17px;
  padding: 14px 16px;
  border-left: 3px solid var(--blue);
  background: #eef3f9;
}

.recovery-card {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin: 0 0 20px;
  padding: 14px 16px;
  border: 1px solid #b8d9cd;
  border-radius: 6px;
  background: var(--accent-soft);
}

.recovery-card strong {
  font-size: 13px;
}

.recovery-card p {
  margin: 3px 0 0;
  color: #41504c;
  font-size: 12px;
  line-height: 1.45;
}

.recovery-value {
  flex: none;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid #78b49f;
  border-radius: 5px;
  color: var(--accent-dark);
  background: white;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 750;
}

.protocol-note strong {
  color: var(--blue);
  font-size: 12px;
  text-transform: uppercase;
}

.protocol-note p {
  margin: 5px 0 0;
  color: #3b474b;
  font-size: 13px;
  line-height: 1.5;
}

.intro-actions,
.profile-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

.intro-actions button,
.profile-actions button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
}

.profile-actions .primary-button {
  margin-top: 0;
}

.form-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.evaluation-view {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.scenario-rail {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  padding: 22px 14px;
  border-right: 1px solid var(--line);
  background: #eef1f0;
}

.progress-summary {
  padding: 0 8px 20px;
}

.progress-summary > span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.progress-summary strong {
  display: block;
  margin-top: 3px;
  font-size: 19px;
}

.progress-track {
  height: 5px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 3px;
  background: #d6ddda;
}

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

#scenario-nav {
  display: grid;
  gap: 4px;
}

.scenario-link {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 7px 8px;
  border: 0;
  border-radius: 5px;
  color: #495350;
  background: transparent;
  text-align: left;
}

.scenario-link:hover,
.scenario-link.active {
  color: var(--ink);
  background: white;
}

.scenario-link .nav-number {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid #c7cfcc;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 750;
}

.scenario-link.complete .nav-number {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.scenario-link .nav-title {
  overflow: hidden;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 34px 38px 80px;
}

.scenario-header {
  justify-content: space-between;
  gap: 20px;
}

.scenario-header h1 {
  margin: 5px 0 0;
  font-size: 26px;
  line-height: 1.2;
}

.book-button {
  display: inline-flex;
  flex: none;
  gap: 8px;
  align-items: center;
}

.question-band {
  margin: 22px 0;
  padding: 18px 20px;
  border-left: 3px solid var(--blue);
  background: #eef3f9;
}

.question-band span {
  color: var(--blue);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.question-band p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.answers {
  display: grid;
  gap: 16px;
}

.answer-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
}

.answer-heading {
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e6eae8;
}

.answer-label {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 4px;
  color: white;
  background: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.answer-status {
  color: var(--warning);
  font-size: 12px;
  font-weight: 700;
}

.answer-card.rated .answer-status {
  color: var(--accent);
}

.answer-response {
  padding: 18px 2px;
  color: #27302e;
  font-size: 14px;
  line-height: 1.68;
}

.answer-response p,
.answer-response ul,
.answer-response ol {
  margin: 0 0 11px;
}

.answer-response li {
  margin: 4px 0;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid #e6eae8;
}

.rating-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.rating-field legend {
  margin-bottom: 7px;
  color: #404a47;
  font-size: 12px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  overflow: hidden;
  border: 1px solid #c6cfcc;
  border-radius: 5px;
}

.segmented label {
  position: relative;
  display: grid;
  min-width: 34px;
  height: 36px;
  place-items: center;
  border-right: 1px solid #d6ddda;
  color: #52605c;
  background: white;
  font-size: 12px;
  cursor: pointer;
}

.segmented label:last-child {
  border-right: 0;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented label:has(input:checked) {
  color: white;
  background: var(--accent);
}

.flag-row {
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 16px;
}

.flag-control {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #404a47;
  font-size: 12px;
  font-weight: 700;
}

.binary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid #c6cfcc;
  border-radius: 5px;
}

.binary label {
  position: relative;
  display: grid;
  min-width: 48px;
  height: 34px;
  place-items: center;
  border-right: 1px solid #d6ddda;
  font-size: 11px;
  cursor: pointer;
}

.binary label:last-child {
  border-right: 0;
}

.binary input {
  position: absolute;
  opacity: 0;
}

.binary label:has(input:checked) {
  color: white;
  background: #4b5955;
}

.notes-field {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.notes-field > span {
  color: var(--muted);
  font-weight: 450;
}

.workspace-footer {
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

.complete-button {
  background: var(--blue);
  border-color: var(--blue);
}

.book-drawer {
  position: fixed;
  z-index: 60;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(720px, 92vw);
  height: 100vh;
  overflow: hidden;
  border-left: 1px solid var(--line);
  background: white;
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform 180ms ease;
}

.book-drawer.open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  z-index: 55;
  inset: 0;
  background: rgb(14 24 22 / 0.32);
}

.book-header {
  justify-content: space-between;
  height: 78px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.book-header h2 {
  margin: 3px 0 0;
  font-size: 18px;
}

.book-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.book-tools {
  gap: 10px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: #f7f8f8;
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box span {
  position: absolute;
  top: 11px;
  left: 12px;
  color: var(--muted);
}

.search-box input {
  padding-left: 34px;
}

.book-tools select {
  width: 230px;
}

.chapter-picker {
  display: flex;
  flex: none;
  gap: 6px;
  align-items: flex-end;
}

.chapter-picker label {
  display: grid;
  gap: 3px;
}

.chapter-picker label > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.chapter-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid #bfc8c5;
  border-radius: 5px;
  color: var(--ink);
  background: white;
  font-size: 24px;
}

.chapter-button:disabled {
  color: #aeb6b3;
  background: #f0f2f1;
  cursor: default;
}

.book-content {
  flex: 1;
  min-height: 0;
  padding: 28px clamp(20px, 5vw, 50px) 80px;
  overflow-y: auto;
  color: #252d2b;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.72;
}

.book-content h3 {
  margin: 0 0 22px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 20px;
}

.book-content p {
  margin: 0 0 15px;
}

.book-content mark {
  color: inherit;
  background: #ffe08a;
}

.book-empty {
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.completed-panel {
  text-align: center;
}

.completed-code {
  display: grid;
  gap: 5px;
  margin-top: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f8f8;
}

.completed-code span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.completed-code strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.completion-mark {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  font-size: 26px;
  font-weight: 800;
}

@media (max-width: 760px) {
  .topbar {
    padding: 0 14px;
  }

  .brand-block div span,
  .save-state,
  .session-identity > span,
  .switch-button {
    display: none;
  }

  .code-button {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .access-panel,
  .intro-panel,
  .profile-panel,
  .completed-panel {
    padding: 28px 22px;
  }

  .header-book-button {
    width: 42px;
    padding: 0;
    justify-content: center;
    font-size: 0;
  }

  .header-book-button span:first-child {
    font-size: 18px;
  }

  .intro-actions,
  .profile-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .recovery-card {
    align-items: stretch;
    flex-direction: column;
  }

  .recovery-value {
    width: 100%;
  }

  .evaluation-view {
    display: block;
  }

  .scenario-rail {
    position: sticky;
    z-index: 20;
    top: 64px;
    width: 100%;
    height: auto;
    padding: 10px 14px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .progress-summary {
    display: none;
  }

  #scenario-nav {
    display: flex;
    width: max-content;
  }

  .scenario-link {
    display: grid;
    width: 40px;
    min-height: 40px;
    padding: 4px;
    place-items: center;
  }

  .scenario-link .nav-title {
    display: none;
  }

  .workspace {
    padding: 25px 14px 60px;
  }

  .scenario-header {
    align-items: flex-start;
  }

  .scenario-header h1 {
    font-size: 22px;
  }

  .book-button {
    width: 42px;
    padding: 0;
    justify-content: center;
    font-size: 0;
  }

  .book-button span {
    font-size: 18px;
  }

  .answer-card {
    padding: 17px 14px;
  }

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

  .flag-row {
    align-items: stretch;
    flex-direction: column;
  }

  .flag-control {
    justify-content: space-between;
  }

  .book-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .book-tools select {
    width: 100%;
  }

  .chapter-picker {
    width: 100%;
  }

  .chapter-picker label {
    flex: 1;
    min-width: 0;
  }

}
