:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1f4f3;
  --text: #18211f;
  --muted: #5c6763;
  --line: #d9ded8;
  --line-strong: #aeb8b1;
  --accent: #176f63;
  --accent-strong: #0f5148;
  --accent-soft: #d9ebe7;
  --warn: #9a4b16;
  --warn-soft: #f8e5d3;
  --good: #197044;
  --good-soft: #dff0e6;
  --bad: #aa2d2d;
  --bad-soft: #f4dddd;
  --focus: #315cc9;
  --shadow: 0 12px 30px rgba(30, 43, 39, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(49, 92, 201, 0.22);
  outline-offset: 2px;
}

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

.app-shell {
  width: min(1680px, calc(100% - 24px));
  margin: 18px auto 40px;
}

.loading {
  margin: 32px auto;
  width: fit-content;
  color: var(--muted);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  padding: 16px 0 14px;
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
}

.user-switcher {
  display: inline-grid;
  grid-template-columns: minmax(58px, auto) minmax(86px, auto);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.user-switcher button {
  min-width: 86px;
  border-color: transparent;
  background: transparent;
  font-weight: 700;
}

.active-user {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  min-width: 58px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-left: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 800;
}

.sync-badge.synced {
  border-color: rgba(25, 112, 68, 0.25);
  background: var(--good-soft);
  color: var(--good);
}

.sync-badge.saving,
.sync-badge.loading {
  border-color: rgba(154, 75, 22, 0.28);
  background: var(--warn-soft);
  color: var(--warn);
}

.sync-badge.offline {
  border-color: rgba(170, 45, 45, 0.28);
  background: var(--bad-soft);
  color: var(--bad);
}

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

.sidebar,
.question-pane,
.progress-strip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 14px;
  padding: 14px;
}

.control-group {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.control-group label,
.section-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 34px 8px 10px;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.login-screen {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-brand h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.login-brand p {
  margin: 6px 0 18px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 13px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.login-error {
  border: 1px solid rgba(170, 45, 45, 0.28);
  border-radius: 7px;
  background: var(--bad-soft);
  color: var(--bad);
  padding: 9px 10px;
  font-size: 14px;
  font-weight: 700;
}

.bank-tabs {
  display: grid;
  gap: 7px;
}

.bank-tabs button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
}

.bank-tabs button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.bank-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.toggle-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  margin: 12px 0 14px;
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
}

.toggle-row span {
  min-width: 0;
}

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

.microcopy {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.stat {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 9px;
}

.stat strong {
  display: block;
  font-size: 21px;
  line-height: 1.15;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.danger:hover:not(:disabled) {
  border-color: var(--bad);
  color: var(--bad);
}

.main-stack {
  display: grid;
  gap: 14px;
}

.progress-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
}

.progress-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.progress-title strong {
  font-size: 17px;
}

.chip {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 700;
}

.chip.warn {
  border-color: #e7bf9d;
  background: var(--warn-soft);
  color: var(--warn);
}

.progress-meter {
  min-width: min(300px, 42vw);
}

.meter-line {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e6e1;
}

.meter-line span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #77853a);
}

.meter-caption {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.question-pane {
  overflow: hidden;
}

.question-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
  padding: 14px 16px;
}

.question-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

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

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary:hover:not(:disabled) {
  background: var(--accent-strong);
  color: #fff;
}

.question-body {
  padding: 22px 24px 24px;
}

.question-main {
  min-width: 0;
  width: 100%;
}

.stem {
  color: var(--text);
  font-size: 19px;
}

.stem p,
.rich-text p,
.commentary p,
.references p {
  margin: 0 0 14px;
}

.stem table,
.commentary table,
.references table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.stem td,
.stem th,
.commentary td,
.commentary th,
.references td,
.references th {
  border: 1px solid var(--line);
  padding: 6px;
  vertical-align: top;
}

.lead-in {
  margin-top: 16px;
  font-size: 20px;
  font-weight: 800;
}

.choices {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.choice {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.choice:not(.submitted):hover {
  border-color: var(--accent);
  background: #f8fcfa;
}

.choice:focus-visible {
  outline: 3px solid rgba(49, 92, 201, 0.22);
  outline-offset: 2px;
}

.choice.submitted {
  cursor: default;
}

.choice.selected:not(.submitted) {
  border-color: var(--focus);
  background: #eef3ff;
}

.choice.correct {
  border-color: #7ab38e;
  background: var(--good-soft);
}

.choice.incorrect {
  border-color: #d89191;
  background: var(--bad-soft);
}

.choice-letter {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
}

.choice-content {
  min-width: 0;
}

.choice-text {
  color: var(--text);
  font-size: 17px;
}

.choice-text p {
  margin: 0 0 8px;
}

.choice-text p:last-child {
  margin-bottom: 0;
}

.choice-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.percent-bar {
  position: relative;
  width: min(180px, 100%);
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe5df;
}

.percent-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: #77853a;
}

.feedback {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.status {
  border-radius: 8px;
  padding: 12px;
  font-weight: 800;
}

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

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

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

.explanation h2,
.empty-state h2 {
  margin: 0;
  font-size: 18px;
}

.high-yield,
.commentary,
.references {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.high-yield {
  border-color: #b8c7ad;
  background: #fbfdf8;
}

.high-yield h2 {
  margin: 0 0 10px;
}

.high-yield ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.high-yield li {
  padding-left: 2px;
}

.outdated-note {
  margin-top: 14px;
  border: 1px solid #e0ae74;
  border-radius: 8px;
  background: #fff7ec;
  padding: 12px;
}

.outdated-note h3 {
  margin: 0 0 8px;
  color: var(--warn);
  font-size: 16px;
}

.outdated-note p {
  margin: 0 0 8px;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.source-links a {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid #d89b5c;
  border-radius: 999px;
  background: #fff;
  color: var(--warn);
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.references {
  overflow-wrap: anywhere;
}

.references summary {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  list-style-position: inside;
}

.references summary::-webkit-details-marker {
  margin-right: 6px;
}

.references .rich-text {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.reference-count {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.references a {
  color: var(--focus);
}

.question-dock {
  position: sticky;
  top: 10px;
  z-index: 12;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.question-dock[open] {
  position: static;
}

.question-dock summary {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
  transition: background 0.16s ease, box-shadow 0.16s ease;
}

.question-dock summary:hover {
  background: #f6faf8;
}

.question-dock summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -3px;
}

.question-dock summary::marker {
  content: "";
}

.question-dock summary::-webkit-details-marker {
  display: none;
}

.dock-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.dock-title {
  white-space: nowrap;
}

.dock-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.dock-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
}

.dock-meta span {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 2px 8px;
  white-space: nowrap;
}

.dock-toggle {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(31, 116, 92, 0.32);
  border-radius: 999px;
  background: #e9f5f0;
  color: var(--focus);
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.dock-close-text {
  display: none;
}

.question-dock[open] .dock-open-text {
  display: none;
}

.question-dock[open] .dock-close-text {
  display: inline;
}

.dock-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}

.question-dock[open] .dock-chevron {
  transform: translateY(2px) rotate(225deg);
}

.dock-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
  padding: 10px 12px;
}

.jump-label {
  display: flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.jump-label input {
  width: 76px;
  min-height: 34px;
  padding: 5px 8px;
  font-weight: 800;
}

.dock-tools .small-button {
  min-height: 34px;
  white-space: nowrap;
}

.question-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 5px;
  max-height: 132px;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
}

.question-map button {
  min-width: 0;
  min-height: 30px;
  padding: 4px 2px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.question-map button.current {
  border-color: var(--focus);
  background: #eef3ff;
  color: var(--focus);
}

.question-map button.done {
  border-color: #9bc0a8;
  background: var(--good-soft);
}

.question-map button.wrong {
  border-color: #d99a9a;
  background: var(--bad-soft);
}

.image-tray {
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.image-tray summary {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  list-style-position: inside;
}

.image-tray summary::-webkit-details-marker {
  margin-right: 6px;
}

.image-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  padding: 10px;
  scroll-snap-type: x proximity;
}

.figure {
  flex: 0 0 min(260px, 72vw);
  margin: 0;
  scroll-snap-align: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
}

.figure button {
  display: grid;
  width: 100%;
  min-height: 116px;
  place-items: center;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: #f4f5f2;
}

.figure img {
  display: block;
  max-width: 100%;
  max-height: 190px;
  width: auto;
  height: auto;
  margin: 0 auto;
}

.figure figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 28px;
  box-shadow: var(--shadow);
}

.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(15, 22, 20, 0.72);
  padding: 20px;
}

.modal-content {
  display: grid;
  gap: 10px;
  width: min(1120px, 96vw);
  max-height: 94vh;
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.modal-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.modal-title {
  min-width: 0;
  font-weight: 800;
}

.modal img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.small-button {
  min-height: 34px;
  padding: 5px 9px;
  font-size: 13px;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 18px, 1680px);
    margin-top: 8px;
  }

  .topbar,
  .progress-strip,
  .question-header {
    grid-template-columns: 1fr;
  }

  .main-stack {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  .progress-meter {
    min-width: 0;
  }

  .meter-caption {
    text-align: left;
  }

  .question-actions,
  .sidebar-actions {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .question-actions button,
  .sidebar-actions button {
    width: 100%;
  }

  .question-body {
    padding: 16px 12px 18px;
  }

  .question-dock {
    top: 8px;
  }

  .question-dock summary {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
    min-height: 0;
  }

  .dock-meta {
    justify-content: flex-start;
  }

  .dock-toggle {
    justify-content: center;
    width: 100%;
  }

  .dock-tools {
    align-items: stretch;
    padding: 8px 10px;
  }

  .jump-label {
    flex: 1 0 100%;
    justify-content: space-between;
  }

  .jump-label input {
    width: 96px;
  }

  .dock-tools .small-button {
    flex: 1 1 108px;
    padding: 5px 6px;
    white-space: normal;
    line-height: 1.15;
  }

  .question-map {
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    max-height: 96px;
    padding: 8px 10px 10px;
  }

  .image-list {
    padding: 8px;
  }

  .figure {
    flex-basis: min(240px, 82vw);
  }

  .choice {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 9px;
  }

  .stem,
  .choice-text {
    font-size: 16px;
  }

  .lead-in {
    font-size: 17px;
  }

  .brand h1 {
    font-size: 23px;
  }
}
