:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #eef3ee;
  --ink: #17201b;
  --muted: #5f6b64;
  --line: #d9e1da;
  --accent: #1b6f5a;
  --accent-strong: #104d41;
  --accent-soft: #dceee8;
  --warn: #835400;
  --warn-soft: #fff3d8;
  --shadow: 0 18px 45px rgba(31, 44, 37, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow: auto;
  padding: 28px 22px;
  background: #17201b;
  color: #f8fbf8;
}

.sidebar-header h1,
.course-intro h2,
.api-panel h2 {
  margin: 0;
}

.sidebar-header h1 {
  font-size: 1.6rem;
  line-height: 1.15;
}

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

.sidebar-toggle {
  display: none;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-weight: 700;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar .eyebrow {
  color: #91d8c5;
}

.progress-card {
  margin: 24px 0;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
}

.progress-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.92rem;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #91d8c5;
  transition: width 160ms ease;
}

.time-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.time-summary div {
  min-width: 0;
}

.time-summary span,
.time-summary strong {
  display: block;
}

.time-summary span {
  color: #a9b9af;
  font-size: 0.74rem;
}

.time-summary strong {
  margin-top: 2px;
  color: #ffffff;
  font-size: 0.9rem;
}

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

.state-button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-weight: 700;
}

.state-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.progress-list {
  display: grid;
  gap: 18px;
}

.progress-module-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
}

.progress-module-title span:last-child {
  color: #a9b9af;
  font-weight: 400;
  white-space: nowrap;
}

.progress-items {
  display: grid;
  gap: 6px;
}

.progress-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: #dbe6de;
  font-size: 0.84rem;
}

.progress-item input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: #91d8c5;
}

.progress-item a {
  color: inherit;
  text-decoration: none;
}

.progress-item a:hover {
  text-decoration: underline;
}

.course {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 32px 32px 56px;
}

.api-panel,
.course-intro {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.api-panel {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1fr);
  gap: 18px;
  align-items: end;
  padding: 18px;
}

.api-panel h2,
.course-intro h2 {
  font-size: 1.4rem;
  line-height: 1.2;
}

.api-key-form {
  min-width: 0;
}

.api-key-field {
  display: grid;
  gap: 6px;
}

.api-key-field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

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

.api-setup {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.api-setup summary {
  padding: 10px 12px;
  color: var(--accent-strong);
  font-weight: 700;
  cursor: pointer;
}

.api-setup p {
  margin: 0;
  padding: 0 12px 12px;
  color: var(--muted);
}

.api-setup a {
  color: var(--accent-strong);
}

#apiNote {
  grid-column: 1 / -1;
  margin: -4px 0 0;
  color: var(--warn);
  font-size: 0.86rem;
}

.api-purpose {
  grid-column: 1 / -1;
  margin: -10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.api-status {
  grid-column: 1 / -1;
  min-height: 1.2em;
  margin: -12px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.course-intro {
  padding: 24px;
}

.course-intro p {
  max-width: 760px;
  color: var(--muted);
}

.course-intro p:last-child {
  margin-bottom: 0;
}

.modules {
  display: grid;
  gap: 14px;
}

.completion-message {
  margin-top: 18px;
  padding: 24px;
  border: 1px solid #98c6ab;
  border-radius: var(--radius);
  background: #f2faf5;
  box-shadow: var(--shadow);
}

.completion-message h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.completion-message p {
  max-width: 780px;
  color: var(--muted);
}

.completion-message p:last-of-type {
  margin-bottom: 0;
}

.completion-media-button {
  max-width: 360px;
  margin-top: 16px;
}

.site-footer {
  margin-top: 28px;
  padding: 20px 0 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.site-footer a {
  color: var(--accent-strong);
  font-weight: 700;
}

.module {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(31, 44, 37, 0.08);
}

.module summary {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  list-style: none;
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.module[open] summary {
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}

.module.is-complete summary {
  background: #edf8f1;
}

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

.module-title {
  margin: 0 0 4px;
  font-size: 1.22rem;
  line-height: 1.2;
}

.module-description {
  max-width: 780px;
  margin: 6px 0 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.module-meta,
.lo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-action {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-muted);
}

.summary-action::before,
.summary-action::after {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent-strong);
  content: "";
  transform: translate(-50%, -50%);
}

.summary-action::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.module[open] .summary-action::after {
  opacity: 0;
}

.module-body {
  display: grid;
  gap: 18px;
  padding: 0 20px 20px;
}

.learning-objective {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fbfcfb;
  transition: background 160ms ease, border-color 160ms ease;
}

.learning-objective.is-complete {
  border-color: #98c6ab;
  background: #f2faf5;
}

.learning-objective.is-collapsed .lo-body {
  display: none;
}

.lo-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 0;
  background: var(--surface-muted);
}

.learning-objective.is-complete .lo-header {
  background: #e7f5ec;
}

.lo-toggle {
  display: grid;
  gap: 4px;
  min-width: 0;
  width: 100%;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.lo-toggle:hover .lo-title {
  text-decoration: underline;
}

.lo-ref {
  width: max-content;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 700;
}

.learning-objective.is-complete .lo-ref {
  background: #cde8d5;
}

.lo-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

.complete-toggle {
  display: inline-grid;
  grid-template-columns: 18px auto;
  gap: 8px;
  align-items: center;
  margin-right: 16px;
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.complete-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.lo-body {
  border-top: 1px solid var(--line);
}

.lo-sections {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.lo-section {
  min-width: 0;
  padding: 16px;
  border-right: 1px solid var(--line);
}

.lo-section:last-child {
  border-right: 0;
}

.lo-section h4 {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 0.92rem;
  text-transform: uppercase;
}

.lo-section p,
.lo-section ol {
  margin-top: 0;
}

.lo-section p:last-child,
.lo-section ol:last-child {
  margin-bottom: 0;
}

.lo-section ol {
  padding-left: 20px;
}

.do-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.objective-text {
  padding: 10px;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft);
}

.resources {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.resources h5 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.resource-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  font-size: 0.9rem;
}

.resource-list a {
  color: var(--accent-strong);
}

.media-buttons {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.media-button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: left;
}

.media-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.check-question {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.check-question strong {
  color: var(--accent-strong);
}

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

.connect-form textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.connect-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ask-button,
.clear-button {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-weight: 700;
}

.ask-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.ask-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.clear-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent-strong);
}

.answer {
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  white-space: pre-wrap;
}

.answer[data-state="error"] {
  border-color: #d49a9a;
  background: #fff0f0;
  color: #6b1d1d;
}

.media-modal,
.state-modal {
  width: min(92vw, 900px);
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.media-modal::backdrop,
.state-modal::backdrop {
  background: rgba(9, 16, 12, 0.62);
}

.media-modal-inner,
.state-modal-inner {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.state-modal {
  width: min(92vw, 760px);
}

.media-modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.media-modal h2 {
  margin: 0;
  font-size: 1.1rem;
}

.state-modal h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-close {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--accent-strong);
  font-weight: 700;
}

.media-modal img {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf8;
}

.media-modal p {
  margin: 0;
  color: var(--muted);
}

.state-help {
  margin: 0;
  color: var(--muted);
}

.state-field {
  display: grid;
  gap: 8px;
}

.state-field span {
  color: var(--accent-strong);
  font-weight: 700;
}

.state-field textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
}

.state-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .sidebar-toggle {
    display: inline-block;
  }

  .sidebar.is-collapsed .progress-card,
  .sidebar.is-collapsed .progress-list {
    display: none;
  }

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

  .course {
    padding: 24px 18px 44px;
  }

  .lo-sections {
    grid-template-columns: 1fr;
  }

  .lo-section {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .lo-section:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 680px) {
  .api-panel,
  .lo-header {
    grid-template-columns: 1fr;
  }

  .complete-toggle {
    margin: 0 16px 16px;
  }

  .progress-list {
    grid-template-columns: 1fr;
  }

  .complete-toggle {
    white-space: normal;
  }
}
