/* ============================================================
   AA — Algorithm Analysis for Absolute Beginners
   Shared stylesheet. Dark by default, warm-cream light theme.
   ============================================================ */

:root {
  --bg:            #0b0d13;
  --bg-soft:       #11141c;
  --surface:       rgba(255, 255, 255, 0.025);
  --surface-2:     rgba(255, 255, 255, 0.05);
  --border:        rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text:          #dfe1ea;
  --heading:       #ffffff;
  --muted:         #868a9c;
  --accent:        #ffd475;   /* stellar gold  */
  --accent-soft:   rgba(255, 212, 117, 0.10);
  --blue:          #6fb2ff;
  --blue-soft:     rgba(111, 178, 255, 0.10);
  --green:         #57d38c;
  --green-soft:    rgba(87, 211, 140, 0.10);
  --red:           #ff8a8a;
  --red-soft:      rgba(255, 138, 138, 0.10);
  --code-bg:       #0f131c;
  --header-bg:     rgba(11, 13, 19, 0.88);

  --font-display: "Playfair Display", Georgia, serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-body: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius: 14px;
  --measure: 68ch;
}

[data-theme="light"] {
  --bg:            #f5f0e8;
  --bg-soft:       #efe9df;
  --surface:       rgba(0, 0, 0, 0.028);
  --surface-2:     rgba(0, 0, 0, 0.055);
  --border:        rgba(0, 0, 0, 0.11);
  --border-strong: rgba(0, 0, 0, 0.2);
  --text:          #3d3929;
  --heading:       #1a1710;
  --muted:         #7d7462;
  --accent:        #b06d10;
  --accent-soft:   rgba(176, 109, 16, 0.10);
  --blue:          #2b6cb0;
  --blue-soft:     rgba(43, 108, 176, 0.09);
  --green:         #16763a;
  --green-soft:    rgba(22, 118, 58, 0.09);
  --red:           #b3261e;
  --red-soft:      rgba(179, 38, 30, 0.08);
  --code-bg:       #ece5d9;
  --header-bg:     rgba(245, 240, 232, 0.9);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  font-family: var(--font-body);
  font-weight: 300;
  font-size: 1.02rem;
  line-height: 1.72;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background .35s ease, color .35s ease;
}

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.4rem);
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-family: var(--font-mono);
  font-size: .82rem; letter-spacing: .5px;
  color: var(--accent); text-decoration: none; white-space: nowrap;
}
.brand span { color: var(--muted); }
.header-nav { margin-left: auto; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.hlink {
  font-family: var(--font-mono); font-size: .72rem;
  color: var(--muted); text-decoration: none;
  padding: .3rem .7rem; border: 1px solid var(--border);
  border-radius: 20px; transition: all .18s ease; background: none; cursor: pointer;
}
.hlink:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.4rem) 5rem; }
.lesson { max-width: var(--measure); }
section { margin-top: 3.2rem; }
section:first-of-type { margin-top: 2rem; }

/* ---------- hero ---------- */
.hero { padding: 3rem 0 1.2rem; border-bottom: 1px solid var(--border); }
.eyebrow {
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: 2.5px;
  text-transform: uppercase; color: var(--accent); margin-bottom: .9rem;
}
h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 3rem); line-height: 1.12;
  color: var(--heading); letter-spacing: -.5px;
}
.lede { font-size: 1.12rem; color: var(--muted); margin-top: 1rem; max-width: var(--measure); }
.hero-meta { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.4rem; }
.chip {
  font-family: var(--font-mono); font-size: .68rem;
  padding: .25rem .7rem; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.chip.gold  { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.chip.blue  { color: var(--blue);   border-color: var(--blue);   background: var(--blue-soft); }
.chip.green { color: var(--green);  border-color: var(--green);  background: var(--green-soft); }

h2 {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(1.4rem, 3.4vw, 1.95rem);
  color: var(--heading); margin-bottom: .9rem; letter-spacing: -.2px;
}
h2 .num { font-family: var(--font-mono); font-size: .75rem; color: var(--accent); margin-right: .6rem; vertical-align: middle; }
h3 { font-family: var(--font-body); font-weight: 500; font-size: 1.12rem; color: var(--heading); margin: 1.8rem 0 .6rem; }
p { margin-bottom: 1rem; max-width: var(--measure); }
strong { font-weight: 500; color: var(--heading); }
em { font-style: italic; }
a { color: var(--blue); text-underline-offset: 3px; }

ul, ol { margin: 0 0 1.1rem 1.3rem; max-width: var(--measure); }
li { margin-bottom: .45rem; }
li::marker { color: var(--accent); }

/* ---------- inline code + blocks ---------- */
code {
  font-family: var(--font-mono); font-size: .86em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .08em .38em; border-radius: 5px; color: var(--accent);
}
.code {
  position: relative; margin: 1.2rem 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--code-bg); overflow: hidden;
}
.code-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .9rem; border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); font-size: .68rem; color: var(--muted);
  background: var(--surface);
}
.code-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.copy-btn {
  margin-left: auto; font-family: var(--font-mono); font-size: .66rem;
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: .15rem .55rem; border-radius: 14px; cursor: pointer; transition: all .15s;
}
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn.done { color: var(--green); border-color: var(--green); }
.code pre { margin: 0; padding: .95rem 1.1rem; overflow-x: auto; }
.code code {
  background: none; border: none; padding: 0; color: var(--text);
  font-size: .84rem; line-height: 1.65; white-space: pre;
}
.code .c { color: var(--muted); font-style: italic; }   /* comment  */
.code .k { color: var(--blue); }                         /* keyword  */
.code .s { color: var(--green); }                        /* string   */
.code .n { color: var(--accent); }                       /* number   */
.out {
  border-left: 2px solid var(--border-strong); background: var(--surface);
  font-family: var(--font-mono); font-size: .78rem; color: var(--muted);
  padding: .7rem 1rem; margin: -.6rem 0 1.2rem; border-radius: 0 8px 8px 0; white-space: pre-wrap;
}

/* ---------- callouts ---------- */
.note {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.2rem; margin: 1.4rem 0; max-width: var(--measure);
}
.note p:last-child { margin-bottom: 0; }
.note .label {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--accent); display: block; margin-bottom: .4rem;
}
.note.blue  { border-left-color: var(--blue); }
.note.blue .label { color: var(--blue); }
.note.green { border-left-color: var(--green); }
.note.green .label { color: var(--green); }
.note.red   { border-left-color: var(--red); }
.note.red .label { color: var(--red); }

/* ---------- objectives / cards ---------- */
.objectives { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem 1.5rem; background: var(--surface); }
.objectives ul { margin-bottom: 0; }

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); max-width: 100%; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 1.1rem 1.2rem; transition: all .18s ease;
}
.card h4 { font-weight: 500; color: var(--heading); font-size: 1rem; margin-bottom: .3rem; }
.card p { font-size: .9rem; color: var(--muted); margin: 0; }

/* week index cards */
a.week-card { text-decoration: none; color: inherit; display: block; position: relative; }
a.week-card:hover .card { border-color: var(--accent); background: var(--surface-2); transform: translateY(-2px); }
.week-card .wk { font-family: var(--font-mono); font-size: .68rem; color: var(--accent); letter-spacing: 1.4px; }
.week-card .card.done { border-color: var(--green); }
.week-card .tick { position: absolute; top: .9rem; right: 1rem; color: var(--green); font-size: .9rem; display: none; }
.week-card .card.done + .tick, .week-card .card.done .tick { display: block; }

/* phase heading */
.phase {
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--muted); margin: 2.4rem 0 .9rem; display: flex; align-items: center; gap: .8rem;
}
.phase::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.3rem 0; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; min-width: 460px; }
th, td { text-align: left; padding: .6rem .85rem; border-bottom: 1px solid var(--border); }
th {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted); font-weight: 400;
}
td code { font-size: .82em; }
tbody tr:hover { background: var(--surface); }

/* ---------- exercise / details ---------- */
details.solution {
  border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .9rem; margin: .8rem 0; background: var(--surface); max-width: var(--measure);
}
details.solution summary {
  cursor: pointer; font-family: var(--font-mono); font-size: .72rem;
  color: var(--muted); list-style: none;
}
details.solution summary::-webkit-details-marker { display: none; }
details.solution summary::before { content: "▸ "; color: var(--accent); }
details.solution[open] summary::before { content: "▾ "; }
details.solution[open] { padding-bottom: .2rem; }
details.solution > *:not(summary) { margin-top: .8rem; }

.task {
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 1.1rem 1.3rem; margin: 1.3rem 0; max-width: var(--measure); background: var(--surface);
}
.task .label {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--green); display: block; margin-bottom: .5rem;
}
.task.challenge { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.task.challenge .label { color: var(--accent); }
.task.challenge .label::before { content: "\2605 optional challenge \00b7 "; }
.task p:last-child, .task ul:last-child, .task ol:last-child { margin-bottom: 0; }

/* ---------- quiz ---------- */
.quiz { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem 1.5rem; background: var(--surface); max-width: var(--measure); }
.quiz .q { margin-bottom: 1.6rem; }
.quiz .q:last-of-type { margin-bottom: .4rem; }
.quiz .q > p { font-weight: 400; color: var(--heading); margin-bottom: .7rem; }
.quiz .opt {
  display: block; width: 100%; text-align: left; font-family: var(--font-body); font-size: .95rem;
  font-weight: 300; color: var(--text); background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: 9px;
  padding: .5rem .85rem; margin-bottom: .45rem; cursor: pointer; transition: all .15s;
}
.quiz .opt:hover:not(.locked) { border-color: var(--border-strong); background: var(--surface-2); }
.quiz .opt.right { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.quiz .opt.wrong { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.quiz .why {
  display: none; font-size: .86rem; color: var(--muted);
  border-left: 2px solid var(--border-strong); padding-left: .8rem; margin-top: .5rem;
}
.quiz .why.show { display: block; }
.quiz-score { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); }

/* ---------- growth widget ---------- */
.widget { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.4rem; background: var(--surface); margin: 1.4rem 0; }
.widget label { font-family: var(--font-mono); font-size: .7rem; color: var(--muted); display: block; margin-bottom: .5rem; }
.widget input[type=range] { width: 100%; accent-color: var(--accent); }
.widget .readout { font-family: var(--font-mono); font-size: .8rem; color: var(--accent); margin-bottom: .8rem; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 110px; gap: .7rem; align-items: center; margin-bottom: .45rem; font-family: var(--font-mono); font-size: .72rem; }
.bar-row .name { color: var(--text); }
.bar-track { display: block; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--accent)); width: 0; transition: width .3s ease; }
.bar-row .val { color: var(--muted); text-align: right; }

/* ---------- footer nav ---------- */
.week-nav { display: flex; gap: 1rem; justify-content: space-between; margin-top: 4rem; padding-top: 1.6rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.week-nav a {
  font-family: var(--font-mono); font-size: .74rem; text-decoration: none; color: var(--muted);
  border: 1px solid var(--border); border-radius: 20px; padding: .45rem 1rem; transition: all .18s;
}
.week-nav a:hover { color: var(--accent); border-color: var(--accent); }
.done-btn {
  font-family: var(--font-mono); font-size: .72rem; cursor: pointer;
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: .45rem 1rem; border-radius: 20px; transition: all .18s;
}
.done-btn:hover { color: var(--text); border-color: var(--border-strong); }
.done-btn.on { color: var(--green); border-color: var(--green); background: var(--green-soft); }

.site-footer {
  border-top: 1px solid var(--border); padding: 1.6rem clamp(1rem, 4vw, 2.4rem);
  display: flex; gap: 1rem; justify-content: space-between; flex-wrap: wrap;
  font-family: var(--font-mono); font-size: .7rem; color: var(--muted);
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* progress bar on home */
.progress-wrap { margin: 1.6rem 0 0; max-width: var(--measure); }
.progress-track { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--accent)); transition: width .4s ease; }
.progress-label { font-family: var(--font-mono); font-size: .7rem; color: var(--muted); margin-top: .45rem; }

@media (max-width: 620px) {
  body { font-size: .98rem; }
  .bar-row { grid-template-columns: 70px 1fr 88px; font-size: .66rem; }
}

@media print {
  .site-header, .week-nav, .copy-btn, .done-btn { display: none; }
  body { background: #fff; color: #000; }
  .code code { white-space: pre-wrap; overflow-wrap: anywhere; }
}
