:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --line: #d9e1ea;
  --text: #18212d;
  --muted: #647386;
  --muted-2: #8a98a9;
  --accent: #1f6feb;
  --accent-dark: #164fb2;
  --amber: #c77816;
  --good: #16803c;
  --review: #b42318;
  --active: #1f6feb;
  --shadow: 0 12px 30px rgba(24, 33, 45, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 330px minmax(460px, 1fr) 410px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.course-rail,
.source-panel,
.answer-panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
}

.course-rail {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #18212d;
  color: #fff;
  font-weight: 800;
}

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

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.course-list,
.source-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.course-list {
  flex: 1;
  padding-right: 4px;
}

.course-button,
.source-button,
.question-button {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  border-radius: var(--radius);
  color: var(--text);
}

.course-button {
  padding: 11px 10px;
}

.course-button strong {
  display: block;
  font-size: 13px;
}

.course-button span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.course-button.active,
.source-button.active,
.question-button.active {
  background: #edf4ff;
  border-color: #b9d4ff;
}

.course-button:hover,
.source-button:hover,
.question-button:hover {
  background: #f3f7fc;
}

.source-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 12px;
}

.panel-header,
.answer-header,
.topbar,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toolbar {
  justify-content: flex-end;
  flex-wrap: wrap;
  row-gap: 8px;
}

.panel-header strong {
  color: var(--text);
  font-size: 12px;
}

.search-box {
  margin: 13px 0 10px;
}

.search-box input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 11px;
  outline: none;
  color: var(--text);
  background: #fbfcfe;
  font-size: 13px;
}

.search-box input:focus,
textarea:focus {
  border-color: #8bbcff;
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 12px 0 10px;
}

.mode-switch button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
}

.mode-switch button.active {
  border-color: #b9d4ff;
  background: #edf4ff;
  color: var(--accent);
}

.hidden {
  display: none !important;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  padding: 7px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.segmented button.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(24, 33, 45, 0.08);
}

.source-list {
  flex: 1;
  min-height: 0;
  padding-right: 3px;
}

.progress-summary {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
  padding: 10px;
  margin-bottom: 12px;
}

.progress-top,
.completion-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.progress-top {
  font-size: 12px;
  color: var(--muted);
}

.progress-top strong {
  color: var(--text);
}

.progress-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebf2;
  margin: 9px 0;
}

.progress-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--good);
  transition: width 160ms ease;
}

.progress-breakdown {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.progress-breakdown span {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  white-space: nowrap;
}

.source-group {
  border-bottom: 1px solid #edf1f5;
  padding-bottom: 8px;
}

.source-button {
  padding: 9px;
}

.source-button strong {
  display: block;
  font-size: 12px;
  line-height: 1.25;
}

.source-button span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.question-list {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 3px 0 0 10px;
}

.source-group.open .question-list {
  display: flex;
}

.question-button {
  padding: 8px 9px;
  font-size: 12px;
}

.question-button .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.question-button small {
  color: var(--muted);
  line-height: 1.2;
}

.question-button .note-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status-mark {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted-2);
}

.status-mark.status-completed {
  background: var(--good);
}

.status-mark.status-in_progress {
  background: var(--active);
}

.status-mark.status-needs_review {
  background: var(--review);
}

.status-mark.status-unseen {
  background: var(--muted-2);
}

.question-button.status-completed {
  border-color: rgba(22, 128, 60, 0.22);
}

.question-button.status-needs_review {
  border-color: rgba(180, 35, 24, 0.28);
  background: #fff7f5;
}

.viewer-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #eef2f7;
}

.topbar {
  flex: 0 0 auto;
  min-height: 78px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.crumb {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.25;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.counter {
  min-width: 62px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.copy-status {
  min-width: 54px;
  color: var(--good);
  font-size: 12px;
}

.copy-status.error {
  color: var(--review);
}

.document-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  padding: 22px;
}

#questionImage {
  display: block;
  max-width: 100%;
  margin: 0 auto 24px;
  background: #fff;
  border: 1px solid #cfd8e3;
  box-shadow: var(--shadow);
}

#noteFrame {
  display: none;
  width: min(100%, 980px);
  height: 100%;
  min-height: 420px;
  margin: 0 auto 24px;
  border: 1px solid #cfd8e3;
  background: #fff;
  box-shadow: var(--shadow);
}

.note-text-viewer {
  display: none;
  width: min(100%, 980px);
  min-height: 100%;
  margin: 0 auto 24px;
  border: 1px solid #cfd8e3;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 28px;
  font-size: 15px;
  line-height: 1.62;
  white-space: pre-wrap;
}

.note-text-viewer h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.note-text-viewer .note-source {
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}

body.notes-mode #questionImage {
  display: none;
}

body.notes-mode #noteFrame.active,
body.notes-mode #noteTextViewer.active {
  display: block;
}

.answer-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  gap: 12px;
  padding: 16px;
  border-right: 0;
  border-left: 1px solid var(--line);
}

.answer-header {
  min-height: 28px;
  color: var(--muted);
  font-size: 13px;
}

.answer-header > div {
  display: flex;
  align-items: center;
  gap: 7px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
}

.status-dot.busy {
  background: var(--amber);
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
}

.instruction-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  outline: none;
  background: #fbfcfe;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.primary-button {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.primary-button:disabled,
.ghost-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.completion-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfe;
}

.completion-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-pill {
  border-radius: 999px;
  padding: 4px 8px;
  background: #edf1f5;
  color: var(--muted);
  font-size: 11px;
}

.status-pill.status-completed {
  background: #e8f6ee;
  color: var(--good);
}

.status-pill.status-in_progress {
  background: #edf4ff;
  color: var(--active);
}

.status-pill.status-needs_review {
  background: #fff0ed;
  color: var(--review);
}

.completion-detail {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.completion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.completion-actions button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 750;
}

.completion-actions button.active {
  border-color: #b9d4ff;
  background: #edf4ff;
  color: var(--accent);
}

.answer-meta {
  min-height: 17px;
  color: var(--muted);
  font-size: 12px;
}

.answer-output {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfcfe;
  font-size: 14px;
  line-height: 1.55;
}

.answer-output h2,
.answer-output h3 {
  margin: 16px 0 8px;
  line-height: 1.25;
}

.answer-output h2:first-child,
.answer-output h3:first-child {
  margin-top: 0;
}

.answer-output pre {
  overflow: auto;
  padding: 12px;
  border-radius: 7px;
  background: #eef3f8;
}

.answer-output code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.copy-url-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  font-size: 12px;
}

.copy-url-detail {
  color: var(--muted);
  font-size: 12px;
}

.empty {
  color: var(--muted);
  padding: 14px 10px;
  font-size: 13px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px 290px minmax(420px, 1fr);
  }

  .answer-panel {
    position: fixed;
    right: 16px;
    bottom: 16px;
    top: 96px;
    width: min(410px, calc(100vw - 32px));
    max-height: calc(100dvh - 112px);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: 10px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .course-rail,
  .source-panel,
  .viewer-panel,
  .answer-panel {
    position: static;
    width: auto;
    height: auto;
    max-height: none;
    min-height: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }

  .answer-panel {
    overflow: visible;
  }

  .course-list,
  .source-list {
    flex: none;
    height: auto;
    max-height: 360px;
  }

  .topbar {
    align-items: flex-start;
  }

  .document-stage {
    min-height: 420px;
    padding: 12px;
  }

  #noteFrame {
    height: min(72dvh, 760px);
  }
}
