/* ===== Tokens ===== */
:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1f2430;
  --muted: #5d6475;
  --line: #e4e0d6;
  --brand: #5b4bdb;
  --brand-dark: #4535b8;
  --orange: #f06a2a;
  --orange-soft: #fff0e6;
  --blue: #2f7de1;
  --blue-soft: #e8f1fd;
  --green: #0f9d72;
  --green-soft: #e3f6ef;
  --danger: #d93a3a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 36, 48, .06), 0 6px 20px rgba(31, 36, 48, .06);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

img { max-width: 100%; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; }
code, kbd, pre { font-family: var(--mono); }
:not(pre) > code, kbd {
  padding: .1em .35em;
  border-radius: 6px;
  background: #efebe2;
  font-size: .9em;
}
kbd { border: 1px solid var(--line); border-bottom-width: 2px; background: var(--surface); }
pre {
  overflow-x: auto;
  padding: 1rem;
  border-radius: 12px;
  background: #1f2430;
  color: #e9edf5;
  font-size: .9rem;
  line-height: 1.5;
}

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding-inline: 20px; }
.muted { color: var(--muted); }
.stack > * + * { margin-top: 1rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-header .container {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 64px;
  flex-wrap: wrap;
}
.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  text-decoration: none;
}
.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-family: var(--mono);
  font-size: .8rem;
}
.main-nav { display: flex; gap: .1rem; flex-wrap: wrap; flex: 1; }
.main-nav a, .user-nav a, .link-button {
  padding: .4rem .5rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.main-nav a:hover, .main-nav a.is-active, .user-nav a:hover, .user-nav a.is-active { background: #efebe2; color: var(--text); }
.user-nav { display: flex; align-items: center; gap: .1rem; flex-wrap: wrap; }
.link-button { border: 0; background: none; font: inherit; cursor: pointer; }
.link-button:hover { color: var(--danger); }
.menu-toggle { display: none; }

/* The widest header (super admin) needs ~1150px in one row; the extra room covers wider system fonts. */
@media (max-width: 1200px) {
  .menu-toggle {
    display: inline-flex;
    margin-left: auto;
    padding: .4rem .7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font: inherit;
    cursor: pointer;
  }
  .main-nav, .user-nav { display: none; flex-basis: 100%; flex-direction: column; padding-bottom: .75rem; }
  .site-header.is-open .main-nav, .site-header.is-open .user-nav { display: flex; align-items: stretch; }
}

/* ===== Layout ===== */
main.page { padding-block: 2rem 4rem; }
.page-head { margin-bottom: 2rem; }
.page-head h1 { margin: .25rem 0 .5rem; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.eyebrow { font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.site-footer { padding-block: 2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1.5rem; }
.footer-credit a { color: var(--text); font-weight: 700; }

/* ===== Guest limits ===== */
.guest-notice {
  margin-bottom: 1.5rem;
  padding: .9rem 1.1rem;
  border: 1px solid #f0d67a;
  border-radius: 14px;
  background: #fff7db;
  color: #4d3b00;
}
.guest-notice ul { margin: .25rem 0 .75rem; padding-left: 1.2rem; }
.guest-notice li + li { margin-top: .2rem; }
.guest-notice-lead { margin: 0 0 .5rem; }
.guest-notice-compact summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .25rem 1rem;
  cursor: pointer;
  list-style: none;
}
.guest-notice-compact summary::-webkit-details-marker { display: none; }
.guest-notice-more { font-weight: 700; text-decoration: underline; white-space: nowrap; }
.guest-notice-compact[open] summary { margin-bottom: .75rem; }
.guest-notice-compact[open] .guest-notice-more { visibility: hidden; }
.guest-limits { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.5rem; }
.guest-limits-title { margin: 0; font-weight: 800; }
.guest-inline { margin: .75rem 0 0; padding: .6rem .8rem; border-radius: 10px; background: #fff7db; color: #4d3b00; font-size: .95rem; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 700px) { .grid-halves { grid-template-columns: 1fr; } }

.cheatsheet-course { margin: 2.5rem 0 1.25rem; padding-top: 1.25rem; border-top: 2px solid var(--line); }
.cheatsheet-course:first-of-type { margin-top: 1rem; padding-top: 0; border-top: 0; }
.cheatsheet-course h2 { margin: .2rem 0 .35rem; }
.cheatsheet-course p { margin: 0; }
.cheatsheet-range { font-weight: 400; font-size: .9rem; }

.comment-form { display: grid; gap: .6rem; justify-items: start; margin-bottom: 1.5rem; }
.comment-form textarea { width: 100%; }
.comment { padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 14px; margin-bottom: .8rem; background: var(--surface); }
.comment-head { display: flex; flex-wrap: wrap; gap: .6rem; align-items: baseline; font-size: .95rem; }
.comment-head form { display: inline; }
.comment-body { margin: .35rem 0 0; }
.comment-reply { margin: .8rem 0 0 1.5rem; background: #faf9ff; }
.comment-answer summary { margin-top: .6rem; font-size: .9rem; font-weight: 600; cursor: pointer; color: var(--muted); }
.comment-answer[open] summary { margin-bottom: .6rem; }
@media (max-width: 600px) { .comment-reply { margin-left: .75rem; } }
@media print { .cheatsheet-course { break-after: avoid; page-break-after: avoid; } }

.card {
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card h2 { font-size: 1.3rem; }

/* ===== Buttons & forms ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: .55rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, transform .15s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .link-button:focus-visible, a:focus-visible { outline: 3px solid #b3aaf5; outline-offset: 2px; }
.btn-light { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-light:hover { background: #efebe2; }
.btn-success { background: var(--green); }
.btn-success:hover { background: #0b7f5c; }
.btn-danger { background: var(--surface); border-color: #f2c4c4; color: var(--danger); }
.btn-danger:hover { background: #fdeeee; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .9rem; border-radius: 9px; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .3rem; font-weight: 600; }
.input {
  width: 100%;
  min-height: 44px;
  padding: .55rem .8rem;
  border: 1px solid #cfc9bb;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.input:focus { outline: 3px solid #d6d1fa; border-color: var(--brand); }
.error { margin-top: .25rem; color: var(--danger); font-size: .9rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: .15rem; accent-color: var(--green); flex-shrink: 0; }

.flash {
  margin-bottom: 1.5rem;
  padding: .8rem 1rem;
  border-radius: 12px;
  background: var(--green-soft);
  color: #0b5e45;
  font-weight: 600;
}
.auth-card { max-width: 440px; margin: 0 auto; }
.btn-block { width: 100%; }
.oauth-divider { display: flex; align-items: center; gap: .8rem; margin: 1.2rem 0; color: var(--muted); font-size: .9rem; }
.oauth-divider::before, .oauth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ===== Admin ===== */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.admin-stats .card { display: flex; flex-direction: column; gap: .2rem; }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.admin-search { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.admin-search .input { flex: 1 1 240px; width: auto; }
.admin-progress { min-width: 8rem; white-space: nowrap; }
.admin-progress .progress { margin-top: .35rem; }
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; margin-top: 1rem; }

/* ===== Module colours ===== */
.theme-orange { --accent: var(--orange); --accent-soft: var(--orange-soft); }
.theme-blue { --accent: var(--blue); --accent-soft: var(--blue-soft); }
.theme-green { --accent: var(--green); --accent-soft: var(--green-soft); }
.theme-purple { --accent: var(--brand); --accent-soft: #efedfd; }

.badge {
  display: inline-block;
  padding: .15rem .6rem;
  border-radius: 999px;
  background: var(--accent-soft, #efebe2);
  color: var(--accent, var(--muted));
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-done { background: var(--green-soft); color: var(--green); }

/* ===== Hero ===== */
.hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 2rem;
  align-items: center;
  margin-bottom: 2.5rem;
}
.hero h1 { margin: .5rem 0 1rem; font-size: clamp(2rem, 5vw, 3.2rem); }
.hero p { font-size: 1.15rem; color: var(--muted); }
.hero .hero-tip { margin: 0 0 1.25rem; padding: .85rem 1.1rem; border-radius: 14px; background: #f2efff; color: inherit; font-size: 1rem; }
.hero .hero-tip strong { font-weight: 800; }
.hero-code {
  margin: 0;
  padding: 1.25rem;
  border-radius: 20px;
  font-size: .95rem;
  box-shadow: var(--shadow);
}
.hero-code .t { color: #ff9e64; }
.hero-code .a { color: #7dd3fc; }
.hero-code .s { color: #a7f3d0; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }
.hero-demo { display: grid; gap: .5rem; min-width: 0; }
.hero-arrow { text-align: center; color: var(--muted); font-size: .9rem; font-weight: 600; }
.hero-result { display: block; width: 100%; height: 150px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); pointer-events: none; }

.intro { margin-bottom: 2.5rem; }
.intro-icon { font-size: 2rem; line-height: 1; }
.intro-card h3 { margin: .5rem 0 .4rem; font-size: 1.2rem; }
.intro-card p { color: var(--muted); }
.intro-need {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.5rem;
  margin-top: 1rem;
  padding: .9rem 1.1rem;
  border: 1px dashed #cfc9bb;
  border-radius: 14px;
  background: var(--surface);
}
.module-link { color: inherit; text-decoration: none; }
.module-link:hover { color: var(--accent); text-decoration: underline; }

.flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.flow-step { padding: 1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.flow-step strong { display: block; }
.flow-step span { font-size: .9rem; color: var(--muted); }
@media (max-width: 700px) { .flow { grid-template-columns: repeat(2, 1fr); } }

/* ===== Progress ===== */
.progress { height: 10px; border-radius: 999px; background: #ebe6db; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent, var(--green)); }

.module-card { border-top: 6px solid var(--accent); }
.module-card h2 { margin: .4rem 0; }
.lesson-dots { display: flex; flex-wrap: wrap; gap: .35rem; margin: 1rem 0; }
.lesson-dot {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: .85rem;
  text-decoration: none;
}
.lesson-dot:hover { outline: 2px solid var(--accent); }
.lesson-dot.is-done { background: var(--accent); color: #fff; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: #faf8f3; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table .num { width: 3.5rem; font-weight: 800; color: var(--accent, var(--muted)); }
.table-module td { background: var(--accent-soft); font-weight: 800; color: var(--accent); }
.table a { font-weight: 600; text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* ===== Lesson ===== */
.lesson-head {
  padding: 2rem;
  border-radius: 24px;
  background: var(--accent-soft);
  margin-bottom: 1.5rem;
}
.lesson-head h1 { margin: .5rem 0; font-size: clamp(1.8rem, 4vw, 2.5rem); }
.lesson-head .goal { font-size: 1.15rem; max-width: 60ch; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.lesson-crumbs { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0 0 .6rem; font-size: .9rem; color: var(--muted); }
.lesson-crumbs a { color: inherit; }

.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }
.lesson-aside { position: sticky; top: 84px; display: grid; gap: 1rem; }
@media (max-width: 960px) {
  .lesson-layout { grid-template-columns: 1fr; }
  .lesson-aside { position: static; }
}

.theory h3 { margin-top: 1.5rem; }
.theory li + li { margin-top: .3rem; }
.section-title { display: flex; align-items: center; gap: .5rem; margin: 0 0 1rem; font-size: 1.3rem; }

.example-frame, .editor-output {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.example-frame { height: 320px; }

details.code-toggle { margin-top: .75rem; }
details.code-toggle summary { cursor: pointer; font-weight: 600; color: var(--brand); }

.cheat-list { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.cheat-list li { display: grid; gap: .1rem; }
.cheat-list code { justify-self: start; color: var(--accent, var(--brand)); background: var(--accent-soft, #efebe2); word-break: break-word; }
.cheat-list span { font-size: .9rem; color: var(--muted); }

.tasks { margin: 0; padding-left: 1.4rem; }
.tasks li + li { margin-top: .5rem; }
.tip { padding: 1rem 1.2rem; border-radius: 14px; }
.tip strong { display: block; margin-bottom: .2rem; }
.tip-bonus { background: #f2efff; }
.tip-support { background: #fff7db; }
.tip-home { background: #eef6ff; }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { display: flex; gap: .6rem; padding: .35rem 0; }
.timeline b { min-width: 5.5rem; color: var(--muted); font-weight: 600; font-size: .9rem; }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }

/* ===== Editor ===== */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
.editor-toolbar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.editor-tabs { display: flex; gap: .25rem; padding: .25rem; border-radius: 12px; background: #efebe2; }
.editor-tabs button {
  min-height: 34px;
  padding: .25rem .9rem;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.editor-tabs button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.editor-spacer { flex: 1; }
.editor-code {
  width: 100%;
  min-height: 420px;
  padding: 1rem;
  border: 0;
  border-radius: 12px;
  background: #1f2430;
  color: #e9edf5;
  font: 14px/1.6 var(--mono);
  tab-size: 2;
  resize: vertical;
  white-space: pre;
}
.editor-code:focus { outline: 3px solid #b3aaf5; }
.editor-preview { display: flex; justify-content: center; min-width: 0; padding: .5rem; border-radius: 14px; background: repeating-conic-gradient(#efebe2 0 25%, #f7f5f0 0 50%) 0 0 / 16px 16px; }
.editor-output { height: 420px; transition: width .2s; }
.editor.is-phone .editor-output { width: 375px; max-width: 100%; }
.editor-footer { grid-column: 1 / -1; }
.editor-hint { font-size: .85rem; color: var(--muted); }
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .editor-code, .editor-output { min-height: 300px; height: 300px; }
}

/* ===== Works ===== */
.work-card { display: flex; flex-direction: column; gap: .75rem; }
.work-card iframe { height: 180px; pointer-events: none; }
.work-card h3 { margin: 0; font-size: 1.05rem; }

/* ===== Quiz & project ===== */
.question { margin-bottom: 1rem; }
.question legend { padding: 0; font-weight: 700; font-size: 1.05rem; margin-bottom: .5rem; }
.question fieldset { margin: 0; padding: 0; border: 0; }
.option {
  display: flex;
  gap: .6rem;
  align-items: center;
  margin-top: .4rem;
  padding: .6rem .8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.option:hover { background: #faf8f3; }
.option:has(input:checked) { border-color: var(--brand); background: #f2efff; }
.option input { accent-color: var(--brand); }
.option.is-correct { border-color: var(--green); background: var(--green-soft); }
.option.is-wrong { border-color: var(--danger); background: #fdeeee; }
.score { font-size: 3rem; font-weight: 800; line-height: 1; }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; }
.topic {
  display: flex;
  gap: .5rem;
  align-items: center;
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}
.topic:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.topic input { accent-color: var(--green); }

.criteria { counter-reset: crit; margin: 0; padding: 0; list-style: none; display: grid; gap: .75rem; }
.criteria li { counter-increment: crit; display: grid; grid-template-columns: 2.2rem 1fr; gap: .2rem .75rem; }
.criteria li::before {
  content: counter(crit);
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
}
.criteria span { color: var(--muted); font-size: .95rem; }

.cheatsheet-lesson { break-inside: avoid; }
.cheatsheet-lesson h3 { margin: 0 0 .6rem; font-size: 1rem; }
.cheatsheet-lesson h3 a { color: var(--text); text-decoration: none; }
.columns { columns: 3 280px; column-gap: 1.25rem; }
.columns > * { margin-bottom: 1.25rem; }
