:root {
  --ink: #18201d;
  --muted: #5b6962;
  --line: #d8dfd9;
  --paper: #f7f6f1;
  --panel: #ffffff;
  --soft: #eef2ed;
  --accent: #1f6f5b;
  --accent-dark: #155242;
  --warn: #8f4f18;
  --error: #9d2b2b;
  --radius: 8px;
  --shadow: 0 18px 45px rgba(34, 41, 37, 0.10);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(31, 111, 91, 0.28);
  outline-offset: 2px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 30px;
}

.login-copy {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.login-card input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.1;
  letter-spacing: 0;
}

.session-pill {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--accent-dark);
  font: 700 14px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.guidance {
  display: flex;
  gap: 20px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.guidance p {
  max-width: 760px;
  margin-bottom: 0;
}

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

.navigator,
.coding-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.navigator {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.panel-head p {
  margin: 0;
  font-size: 15px;
}

.unit-list {
  max-height: calc(100vh - 98px);
  overflow: auto;
  padding: 8px;
}

.unit-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  margin: 0 0 6px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.unit-button:hover,
.unit-button[data-active="true"] {
  border-color: rgba(31, 111, 91, 0.28);
  background: var(--soft);
}

.unit-button[data-reviewed="true"] small {
  color: var(--accent);
}

.unit-button small {
  color: var(--muted);
  white-space: nowrap;
}

.coding-panel {
  padding: 18px;
}

.status {
  min-height: 42px;
  margin-bottom: 16px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbf8;
  color: var(--muted);
}

.status[data-kind="error"] {
  border-color: rgba(157, 43, 43, 0.35);
  color: var(--error);
  background: #fff6f3;
}

.status[data-kind="success"] {
  border-color: rgba(31, 111, 91, 0.35);
  color: var(--accent-dark);
}

.coding-body {
  display: flex;
  gap: 0;
  align-items: start;
  transition: gap 300ms cubic-bezier(0.22, 1, 0.36, 1);
}

.context-overview {
  display: grid;
  grid-template-columns: minmax(180px, 0.75fr) minmax(280px, 1.35fr) minmax(180px, 0.75fr);
  gap: 12px;
  margin-bottom: 16px;
}

.reader-rail {
  flex: 0 0 0;
  min-width: 0;
  position: sticky;
  top: 16px;
  display: block;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  padding-right: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateX(22px) scale(0.985);
  transition:
    flex-basis 360ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 220ms ease,
    transform 360ms cubic-bezier(0.22, 1, 0.36, 1),
    padding-right 360ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: flex-basis, opacity, transform;
}

.sticky-reader-active .coding-body {
  gap: 16px;
}

.sticky-reader-active .reader-rail {
  flex-basis: 360px;
  overflow: auto;
  padding-right: 2px;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.reader-rail .context-card.current {
  min-height: auto;
}

.coding-work {
  flex: 1 1 auto;
  min-width: 0;
  transition: flex-basis 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

.context-card {
  min-width: 0;
  min-height: 190px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbf8;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.context-card h2 {
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--muted);
}

.context-card.current {
  background: #ffffff;
  border-color: rgba(31, 111, 91, 0.38);
}

.context-card.current p:last-child {
  font-size: 19px;
  line-height: 1.62;
}

.context-overview .context-card {
  max-height: 290px;
  overflow: auto;
}

.context-overview .overview-current {
  max-height: none;
}

.context-card.muted {
  color: #69756f;
}

.unit-label {
  margin-bottom: 10px;
  color: var(--accent-dark);
  font: 700 13px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.code-tools {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.search {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
}

.no-code {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  cursor: pointer;
  white-space: nowrap;
}

.mode-button {
  white-space: nowrap;
}

.copilot-panel {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid rgba(31, 111, 91, 0.28);
  border-radius: var(--radius);
  background: #f6fbf8;
}

.copilot-panel h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

.copilot-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.copilot-list li {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.copilot-code {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-dark);
  font-weight: 700;
}

.copilot-quote {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.codebook {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.family {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: visible;
}

.family h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
  line-height: 1.25;
}

.code-list {
  padding: 8px;
}

.code-row {
  position: relative;
  min-height: 42px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
}

.code-row:hover {
  background: var(--soft);
}

.code-row input {
  width: 18px;
  height: 18px;
}

.code-row input:disabled + span {
  color: #9aa29d;
}

.info {
  position: relative;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(31, 111, 91, 0.32);
  border-radius: 50%;
  background: #f6fbf8;
  color: var(--accent-dark);
  font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  cursor: help;
}

.tip {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 8px);
  width: min(340px, 72vw);
  display: none;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #17211d;
  color: #f7f6f1;
  box-shadow: var(--shadow);
  text-align: left;
  line-height: 1.4;
}

.tip strong,
.tip span {
  display: block;
}

.tip strong {
  margin-bottom: 5px;
}

.info:hover .tip,
.info:focus .tip,
.info:focus-within .tip {
  display: block;
}

.actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(255,255,255,0.86), #fff);
}

.proposed-code {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbf8;
}

.previous-proposals label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.proposal-detail {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  line-height: 1.45;
}

.proposal-detail:empty {
  display: none;
}

.proposal-detail p {
  margin-bottom: 7px;
}

.proposal-detail p:last-child {
  margin-bottom: 0;
}

.proposed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.proposed-head h2,
.proposed-head p {
  margin: 0;
}

.proposed-head h2 {
  font-size: 17px;
}

.proposed-head p {
  color: var(--muted);
  font-size: 14px;
}

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

.proposal-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.proposal-grid label:last-child {
  grid-column: 1 / -1;
}

select,
textarea {
  font: inherit;
}

select,
textarea,
.proposal-grid input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.primary,
.secondary {
  min-height: 44px;
  padding: 10px 15px;
  border-radius: var(--radius);
  cursor: pointer;
}

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

.primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

@media (max-width: 1180px) {
  .sticky-reader-active .reader-rail {
    flex-basis: 300px;
  }
}

@media (max-width: 980px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    padding: 24px 14px;
  }

  .workspace,
  .context-overview,
  .codebook,
  .code-tools,
  .proposal-grid {
    grid-template-columns: 1fr;
  }

  .coding-body {
    display: block;
  }

  .navigator {
    position: static;
    max-height: 260px;
  }

  .guidance,
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .coding-panel {
    padding: 12px;
  }

  .context-card {
    min-height: auto;
  }

  .reader-rail {
    display: none;
  }

  .proposed-head {
    align-items: start;
    flex-direction: column;
  }

  .actions {
    align-items: stretch;
  }

  .primary,
  .secondary {
    min-width: 0;
    flex: 1;
    padding-inline: 10px;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 28px;
  }

  .session-pill {
    overflow-wrap: anywhere;
  }

  .context-card.current p:last-child {
    font-size: 17px;
  }

  .family h3 {
    align-items: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .coding-body,
  .coding-work,
  .reader-rail {
    transition: none;
  }
}
