:root {
  --nav-bg: #3c5d70;
  --nav-bg-dark: #34536a;
  --page-bg: #eef2f5;
  --card-bg: #ffffff;
  --card-border: #dde3e8;
  --card-shadow: 0 1px 2px rgba(20, 40, 60, 0.04), 0 1px 4px rgba(20, 40, 60, 0.04);
  --text: #2a3744;
  --text-muted: #6b7a87;
  --code-inline-bg: #f4f1ea;
  --code-block-bg: #f7f4ec;
  --code-text: #2a3744;
  --code-keyword: #d14;
  --code-builtin: #1f8dd6;
  --code-string: #d14;
  --code-number: #d14;
  --code-var: #2a8b9c;
  --btn-border: #d4dadf;
  --btn-hover-bg: #f4f6f8;
  --primary: #3c5d70;
  --accent-yellow: #fff8d6;
  --success: #2e9d4f;
  --error: #d14;
  --pro-bg: #ffd866;
  --pro-text: #4a3500;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  color: var(--text);
  background: var(--page-bg);
  font-size: 16px;
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }

/* ===================== NAV ===================== */

.nav {
  background: var(--nav-bg);
  color: white;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 600;
}

.nav-brand-img {
  height: 40px;
  width: auto;
  display: block;
}

.nav-brand-text {
  color: white;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 28px;
  font-size: 15px;
}

.nav-links a:hover { opacity: 0.85; }

.nav-trophy {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #ffd66b;
}

/* ============== INDEX (LESSONS LIST) PAGE ============== */

.index-header {
  background: var(--nav-bg);
  color: white;
  padding: 40px 32px 80px;
  position: relative;
}

.index-header h1 {
  margin: 0 0 16px;
  font-size: 36px;
  font-weight: 700;
}

.index-header-centered {
  text-align: center;
}

.page-title-image-wrap {
  margin: 0 0 12px;
  padding: 0;
  font-size: 0;
  line-height: 0;
}

.page-title-img {
  max-width: 448px;
  width: 100%;
  height: auto;
  display: inline-block;
}

.index-header .meta {
  margin: 4px 0;
  color: #d6e0e8;
  font-size: 15px;
}

.index-header .meta b { color: white; }

.index-header a {
  text-decoration: underline;
  cursor: pointer;
}

.index-curve {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 80px;
  pointer-events: none;
  overflow: hidden;
}

.index-curve svg {
  width: 100%;
  height: 100%;
  display: block;
}

.index-body {
  max-width: 880px;
  margin: -60px auto 60px;
  padding: 0 24px;
  position: relative;
  z-index: 1;
}

.index-card {
  background: white;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(20, 40, 60, 0.06);
  padding: 24px;
}

.section {
  border: 1px solid var(--card-border);
  border-radius: 4px;
  margin-bottom: 8px;
  overflow: hidden;
}

.section-header {
  padding: 16px 20px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-size: 17px;
  color: var(--text);
}

.section-header:hover { background: #fafbfc; }

.section.expanded .section-header {
  background: #f6f7f9;
  border-bottom: 1px solid var(--card-border);
}

.section-chevron {
  transition: transform 0.2s ease;
  color: var(--text-muted);
  font-size: 14px;
}

.section.expanded .section-chevron { transform: rotate(180deg); }

/* F15: ribbon shown next to the section title when every playable item
   in the section is fully complete. */
.section-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.section-done {
  background: var(--success);
  color: white;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
}

/* F13: short confetti burst on a passed Submit. Container covers the
   viewport but ignores pointer events; pieces fall + spin + fade then
   the whole container is removed by JS. */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  width: 10px;
  height: 14px;
  opacity: 0;
  border-radius: 2px;
  animation: confetti-fall 1.4s ease-out forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg);    opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .confetti-container { display: none; }
}

.section-body {
  display: none;
  padding: 16px 20px 20px;
  background: #f6f7f9;
}

.section.expanded .section-body { display: block; }

.section-desc {
  margin: 0 0 16px;
  color: var(--text);
  font-size: 15px;
}

.lesson-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: white;
  border: 1px solid var(--card-border);
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.lesson-link:hover {
  border-color: var(--nav-bg);
  box-shadow: 0 1px 3px rgba(20, 40, 60, 0.08);
}

.lesson-link.locked {
  cursor: not-allowed;
  opacity: 0.95;
}
.lesson-link.locked:hover {
  border-color: var(--card-border);
  box-shadow: none;
}

.lesson-link-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lesson-link-icon {
  color: var(--text);
  display: inline-flex;
  width: 20px;
  justify-content: center;
}

/* Green tick at the right of a completed lesson row (replaces the old
   green-icon-on-completed treatment — that was too subtle). */
.lesson-link-tick {
  color: var(--success);
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
}

.lesson-link-right {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-muted);
}

.pro-badge {
  background: var(--pro-bg);
  color: var(--pro-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 3px;
}

.soon-badge {
  background: #e8edf1;
  color: #6b7a87;
  font-size: 12px;
  font-style: italic;
  padding: 4px 8px;
  border-radius: 3px;
}

.row-chevron {
  color: var(--text-muted);
  font-size: 14px;
}

/* ============== CHALLENGES TABLE PAGE ============== */

.chall-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.chall-table thead th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 12px 16px;
  border-bottom: 1px solid var(--card-border);
}

.chall-table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text);
}

.chall-table tbody tr:last-child td {
  border-bottom: none;
}

.chall-table tbody tr:hover {
  background: #fafbfc;
}

.chall-table tbody tr.stub:hover {
  background: transparent;
}

.chall-table a {
  color: var(--nav-bg);
  text-decoration: none;
  font-weight: 500;
}

.chall-table a:hover { text-decoration: underline; }

.chall-stub-title {
  color: #9aa6b1;
  cursor: not-allowed;
}

.chall-coming {
  color: #9aa6b1;
  font-style: italic;
  font-size: 13px;
}

.chall-solved { color: var(--success); font-weight: 500; }

/* ============== LESSON / CHALLENGE PAGE ============== */

.lesson-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 24px;
  max-width: 1500px;
  margin: 0 auto;
}

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

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.lesson-content {
  padding: 32px 36px;
  min-height: 500px;
}

.lesson-content h2 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
}

.lesson-content hr {
  border: none;
  border-top: 1px solid var(--card-border);
  margin: 4px 0 28px;
}

.lesson-content h3 {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 18px;
}

.lesson-content p { margin: 0 0 18px; }

.lesson-content em { font-style: italic; }

.lesson-content code {
  background: var(--code-inline-bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  color: var(--code-text);
  border: 1px solid #eae5da;
}

.lesson-content code .kw { color: var(--code-keyword); }
.lesson-content code .bn { color: var(--code-builtin); }
.lesson-content code .st { color: var(--code-string); }
.lesson-content code .nm { color: var(--code-number); }
.lesson-content code .vn { color: var(--code-var); }

.code-block {
  background: var(--code-block-bg);
  border: 1px solid #eae5da;
  border-radius: 4px;
  padding: 12px 16px;
  margin: 0 0 18px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  white-space: pre;
  overflow-x: auto;
  color: var(--code-text);
  line-height: 1.55;
}

.code-block .kw { color: var(--code-keyword); }
.code-block .bn { color: var(--code-builtin); }
.code-block .st { color: var(--code-string); }
.code-block .nm { color: var(--code-number); }
.code-block .vn { color: var(--code-var); }
.code-block .cm { color: #8a96a0; font-style: italic; }

.right-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-header {
  text-align: center;
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 10px 0;
  border-bottom: 1px solid var(--card-border);
  background: #fafbfc;
}

.editor-host {
  background: white;
  position: relative;
}

.CodeMirror {
  height: auto !important;
  min-height: 320px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  background: white !important;
}

.CodeMirror-gutters {
  background: #fafbfc !important;
  border-right: 1px solid #eef0f2 !important;
}

.CodeMirror-linenumber { color: #b6bdc4 !important; padding: 0 8px 0 6px !important; }

.CodeMirror-activeline-background {
  background: var(--accent-yellow) !important;
}

/* String literals in editor - red */
.cm-s-default .cm-string { color: var(--code-string) !important; }
.cm-s-default .cm-number { color: var(--code-number) !important; }
.cm-s-default .cm-keyword { color: var(--code-keyword) !important; }
.cm-s-default .cm-builtin { color: var(--code-builtin) !important; }

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--card-border);
  background: white;
}

.toolbar-group { display: flex; gap: 8px; }

.btn {
  background: white;
  border: 1px solid var(--btn-border);
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) { background: var(--btn-hover-bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon { font-size: 14px; line-height: 1; display: inline-flex; }

/* F9: faint vertical lines every 4 character widths in the editor so kids
   can see where each indent level starts. Uses the editor's monospace font,
   so `ch` is exactly one character wide. CodeMirror's per-line element is
   `div.CodeMirror-line` containing a `<pre>` — paint on the div so the
   guides cover the full line area even when content is short. */
.CodeMirror pre.CodeMirror-line {
  background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(4ch - 1px), rgba(60, 93, 112, 0.03) calc(4ch - 1px), rgba(60, 93, 112, 0.03) 4ch) !important;
}

.output-panel { min-height: 220px; }

.output-body {
  padding: 16px 20px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  white-space: pre-wrap;
  min-height: 180px;
  max-height: 360px;
  overflow-y: auto;
  color: var(--text);
}

.output-body.empty { color: var(--text-muted); }
.output-body .err { color: var(--error); }
.output-body .pass { color: var(--success); }
.output-body .fail { color: var(--error); }

/* F5: kid-friendly explanation block, shown above the raw traceback when
   Python errors. Soft cyan so it reads as "guidance" rather than "wrong". */
.output-body .err-kidline {
  background: #e6f3f8;
  border-left: 4px solid #1f8dd6;
  color: var(--text);
  padding: 10px 14px;
  margin: 0 0 10px;
  border-radius: 0 4px 4px 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  white-space: normal;
}
.output-body .err-kidline strong { color: #0a4e75; }
.output-body .err-kidline code {
  background: rgba(31, 141, 214, 0.12);
  color: #0a4e75;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

/* The raw Python traceback shown below the kid-line — keep it red but
   slightly muted so the kid's eye lands on the friendly explanation first. */
.output-body .err-raw {
  color: var(--error);
  display: block;
  margin-top: 4px;
}

.output-body .stdout-pre { display: block; color: var(--text); margin-bottom: 6px; }

/* F10: actual-vs-expected diagnostic for a failing test. */
.output-body .diag-got { color: var(--error); font-weight: 600; }
.output-body .diag-exp { color: var(--success); font-weight: 600; }

.status-banner {
  padding: 12px 20px;
  border-top: 1px solid var(--card-border);
  font-size: 14px;
  display: none;
}

.status-banner.show { display: block; }
.status-banner.success { background: #e9f6ed; color: #1c6a35; }
.status-banner.fail { background: #fbe9e9; color: #8a1c1c; }

.hint-box {
  margin-top: 16px;
  padding: 12px 16px;
  background: #fffbe5;
  border: 1px solid #f0e3a0;
  border-radius: 4px;
  font-size: 14px;
  display: none;
}

.hint-box.show { display: block; }

.loading-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff8d6;
  color: #6a5a00;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  border-top: 1px solid #f0e3a0;
  z-index: 100;
}

/* ============== PAGINATION ============== */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 32px;
  padding: 14px 24px;
  position: sticky;
  bottom: 0;
  background: var(--page-bg);
  border-top: 1px solid var(--card-border);
  z-index: 10;
}

.pagination .position {
  color: var(--text-muted);
  font-size: 14px;
  min-width: 40px;
  text-align: center;
}

.pagination .btn:disabled { visibility: hidden; }

/* Locked state for the pagination Next/Done <a> — kid sees the button
   exists but can't click it. Hover keeps the title-attribute tooltip
   visible (no pointer-events:none, which would suppress the title). */
.btn.disabled,
.btn.disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
  background: white;
  color: var(--text-muted);
  box-shadow: none;
  border-color: var(--btn-border);
}

.btn.disabled.btn-done,
.btn.disabled.btn-done:hover {
  background: white;
  color: var(--text-muted);
  border-color: var(--btn-border);
}

/* Done button on the last page of an item (and on single-page items).
   Green = match the section-done ribbon and overall completion accent. */
.btn-done {
  background: var(--success);
  color: white;
  border-color: var(--success);
  font-weight: 600;
}

.btn-done:hover:not(:disabled) {
  background: #267e40; /* slightly darker green */
  border-color: #267e40;
}

/* ===================== HOME PAGE ===================== */

.home-hero {
  max-width: 720px;
  margin: 0 auto;
  padding: 56px 24px 80px;
  text-align: center;
}

.home-logo {
  width: 240px;
  height: auto;
  margin-bottom: 20px;
}

.home-hero h1 {
  margin: 0 0 16px;
  font-size: 44px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.home-tagline {
  margin: 0 auto 32px;
  max-width: 520px;
  font-size: 18px;
  line-height: 1.6;
  color: var(--text-muted);
}

.home-cta {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.home-cta-btn {
  display: inline-block;
  padding: 14px 28px;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 600;
  border: 2px solid var(--primary);
  color: var(--primary);
  background: white;
  transition: transform 0.08s ease, background 0.12s ease;
}

.home-cta-btn:hover {
  background: var(--btn-hover-bg);
  transform: translateY(-1px);
}

.home-cta-btn-primary {
  background: var(--primary);
  color: white;
}

.home-cta-btn-primary:hover {
  background: var(--nav-bg-dark);
}

/* ===================== FOOTER ===================== */

.site-footer {
  display: block;
  text-align: center;
  padding: 36px 24px 28px;
  margin-top: 48px;
  border-top: 1px solid var(--card-border);
}

.site-footer-logo {
  height: 56px;
  width: auto;
  opacity: 0.85;
  transition: opacity 0.12s ease;
}

.site-footer-logo:hover { opacity: 1; }
