/* ByteBud — one stylesheet, no build step. */

:root {
  --bg: #f7f3ea;
  --surface: #ffffff;
  --surface-2: #f1ece1;
  --ink: #2a2138;
  --muted: #6d6579;
  --line: #e2dccf;
  --accent: #5b45c9;
  --accent-ink: #ffffff;
  --accent-soft: #ebe6ff;
  --ok: #24864a;
  --ok-soft: #e1f4e7;
  --bad: #c2353e;
  --bad-soft: #fbe5e5;
  --coin: #c98a0b;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(42, 33, 56, 0.06), 0 6px 18px rgba(42, 33, 56, 0.06);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141f;
    --surface: #211d2c;
    --surface-2: #2a2537;
    --ink: #eeeaf5;
    --muted: #a59fb3;
    --line: #3a3449;
    --accent: #9d8bff;
    --accent-ink: #17141f;
    --accent-soft: #2f2852;
    --ok: #5fd08a;
    --ok-soft: #1d3527;
    --bad: #ff7d84;
    --bad-soft: #3d2226;
    --coin: #f0be4a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: 1.9rem; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; }
code, pre, kbd { font-family: var(--mono); font-size: 0.92em; }
:not(pre) > code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
pre { background: var(--surface-2); padding: 0.8em 1em; border-radius: 8px; overflow-x: auto; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; padding: 0 0.35em; border-radius: 4px; background: var(--surface); }
img { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }

/* --- Frame --- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--ink); letter-spacing: -0.02em; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 1rem; flex: 1; }
.nav a { color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--accent); }
.wallet { display: flex; gap: 0.9rem; align-items: center; font-weight: 600; }
.wallet form { margin: 0; }
.coins::before {
  content: ""; display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.3em; vertical-align: -0.05em;
  background: var(--coin); border-radius: 50%; box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.18);
}
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.linkish:hover { color: var(--accent); }
a.linkish { text-decoration: none; font-weight: 500; }
.page { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 2rem 1rem; }
.crumbs { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.75rem; }
.crumbs a { color: var(--muted); }

/* --- Pieces --- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card.narrow { max-width: 440px; margin: 2rem auto; }
.notice { background: var(--accent-soft); border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; gap: 0.35em; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 650;
  padding: 0.6em 1.1em; text-decoration: none; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.btn.small { padding: 0.35em 0.8em; font-size: 0.9rem; }
.tag {
  display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 0.15em 0.6em; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); vertical-align: middle;
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.bar { display: block; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: var(--pct, 0%); background: var(--accent); border-radius: inherit; }
.bar.thin { height: 6px; margin: 0.5rem 0 0.35rem; }
.flash { list-style: none; padding: 0; margin: 0 0 1rem; }
.flash li { padding: 0.65rem 1rem; border-radius: 8px; margin-bottom: 0.5rem; background: var(--accent-soft); }
.flash-error { background: var(--bad-soft) !important; color: var(--bad); }
.flash-success { background: var(--ok-soft) !important; color: var(--ok); }
.dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--muted); margin-right: 0.45em; }
.dot.ok, .ok > .dot { background: var(--ok); }
.dot.bad, .bad > .dot { background: var(--bad); }
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
.activity li:last-child { border-bottom: 0; }
.two-col { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* --- Forms --- */
.form .field { margin-bottom: 1rem; }
.form label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.form input[type="text"], .form input[type="password"], .form input:not([type]), textarea, select {
  width: 100%; font: inherit; padding: 0.55em 0.7em; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}
.help { font-size: 0.82rem; color: var(--muted); margin-top: 0.25rem; }
.help ul { margin: 0.25rem 0 0; padding-left: 1.1rem; }
.error, .errors { color: var(--bad); }
.errors { background: var(--bad-soft); padding: 0.6rem 0.9rem; border-radius: 8px; margin-bottom: 1rem; }
.errors p { margin: 0; }
.has-error input { border-color: var(--bad); }
.choices { display: flex; gap: 1rem; flex-wrap: wrap; }
.choices.stacked { flex-direction: column; gap: 0.3rem; }
.choices label { font-weight: 500; display: flex; gap: 0.45rem; align-items: center; cursor: pointer; }

/* --- Buddy --- */
.buddy-canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.buddy-large { width: 192px; height: 256px; }
.buddy-medium { width: 144px; height: 192px; }
.buddy-small { width: 72px; height: 96px; }
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 2rem; align-items: center; padding: 2rem 0; }
.hero h1 { font-size: 2.5rem; }
.hero .actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.hero-buddies { display: flex; justify-content: center; align-items: flex-end; }
.hero-buddies .buddy-canvas { margin-left: -36px; }
.signup { max-width: 820px; margin: 1rem auto; }
.signup-grid { display: grid; grid-template-columns: 1fr 260px; gap: 2rem; }
.buddy-picker { background: var(--surface-2); border-radius: var(--radius); padding: 1rem; }
.buddy-picker canvas { margin: 0 auto 1rem; }
.speech {
  display: inline-block; background: var(--surface-2); padding: 0.35em 0.8em; border-radius: 12px; font-weight: 600;
  position: relative; margin: 0.25rem 0 0.5rem;
}
.react-pass .speech { background: var(--ok-soft); color: var(--ok); }
.react-fail .speech { background: var(--bad-soft); color: var(--bad); }

/* --- Dashboard --- */
.dash { display: grid; gap: 1.25rem; }
.buddy-home { display: flex; gap: 2rem; align-items: center; flex-wrap: wrap; }
.buddy-home > div { flex: 1; min-width: 240px; }
.stat-line { font-size: 1.05rem; margin: 0 0 0.5rem; }
.track h2 { margin-top: 0.5rem; }
.module-list { list-style: none; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.module-card a {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); height: 100%;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.module-card a:hover { transform: translateY(-2px); border-color: var(--accent); }
.module-title { display: block; font-weight: 700; margin-bottom: 0.35rem; }
.module-card.locked a { opacity: 0.6; }
.module-card.done a { border-color: var(--ok); }

/* --- Module page --- */
.module-head { display: grid; gap: 0.75rem; margin-bottom: 1rem; }
.sections { list-style: none; padding: 0; margin: 0; }
.section-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; }
.section-block > header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.9rem 1.2rem; background: var(--surface-2); flex-wrap: wrap; }
.section-block h2 { margin: 0; font-size: 1.1rem; }
.section-block .num {
  display: inline-grid; place-items: center; width: 1.7em; height: 1.7em; border-radius: 6px; margin-right: 0.4em;
  background: var(--accent); color: var(--accent-ink); font-size: 0.85em;
}
.section-block.done .num { background: var(--ok); }
.section-block.locked { opacity: 0.55; }
.section-block.locked .num { background: var(--muted); }
.lessons { list-style: none; margin: 0; padding: 0.3rem 0; }
.lessons li { display: flex; gap: 0.75rem; align-items: center; padding: 0.55rem 1.2rem; border-top: 1px solid var(--line); }
.lessons li:first-child { border-top: 0; }
.lessons li > a, .lessons li > span:first-child { flex: 1; }
.lessons .check { color: var(--ok); font-weight: 800; }
.kind { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.kind-sql { color: #2b7bb9; }
.kind-excel { color: #1f7a44; }
.kind-vba { color: #8a55c9; }
.kind-test { color: var(--coin); }
.test-row { background: color-mix(in srgb, var(--coin) 7%, transparent); }

/* --- Lesson --- */
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 1.5rem; align-items: start; }
.buddy-panel {
  position: sticky; top: 5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; text-align: center; box-shadow: var(--shadow);
}
.buddy-panel canvas { margin: 0 auto; width: 144px; height: 192px; }
.buddy-panel h2 { font-size: 1.05rem; margin: 0.5rem 0 0.2rem; }
.buddy-panel p { margin: 0.2rem 0; font-size: 0.9rem; }
.lesson-head { display: flex; gap: 1rem; align-items: baseline; flex-wrap: wrap; margin-bottom: 1rem; }
.lesson-head h1 { margin: 0; }
.steps { list-style: none; padding: 0; counter-reset: step; }
.step {
  counter-increment: step; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.step-text::before {
  content: "Step " counter(step); display: block; font-size: 0.75rem; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem;
}
.step-text > :first-child { margin-top: 0; }
.step-text pre { white-space: pre-wrap; word-break: break-word; }
.shot { margin: 0; }
.shot-frame { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.shot-frame img { display: block; width: 100%; height: auto; }
.shot-frame.placeholder {
  aspect-ratio: 16 / 10; display: grid; place-items: center; color: var(--muted); font-size: 0.9rem;
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, var(--surface) 10px, var(--surface) 20px);
}
.shot-frame.placeholder span { background: var(--surface); padding: 0.3em 0.8em; border-radius: 999px; border: 1px dashed var(--line); }
.shot figcaption { font-size: 0.85rem; color: var(--muted); margin-top: 0.4rem; }
.callout { position: absolute; transform: translate(-50%, -50%); }
.callout b {
  display: grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--bad); color: #fff;
  font-size: 0.8rem; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.callout > span { display: none; }
.callout-key { font-size: 0.85rem; margin: 0.4rem 0 0; padding-left: 1.3rem; }
blockquote { margin: 1em 0; padding: 0.6em 1em; border-left: 4px solid var(--line); background: var(--surface-2); border-radius: 0 8px 8px 0; }
blockquote.note { border-left-color: var(--coin); }
blockquote > :first-child { margin-top: 0; }
blockquote > :last-child { margin-bottom: 0; }
.prompt > :first-child { margin-top: 0; }
.hints details { margin: 0.5rem 0; }
.hints summary, .dataset summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.dataset { margin: 1rem 0; min-width: 0; }
.exercise, .result, .lesson { min-width: 0; }
.table-wrap { overflow-x: auto; margin: 0.5rem 0; }
.table-wrap h4 { margin: 0.75rem 0 0.35rem; }
table.grid { border-collapse: collapse; font-size: 0.88rem; min-width: 50%; }
.grid th, .grid td { border: 1px solid var(--line); padding: 0.3em 0.6em; text-align: left; white-space: nowrap; }
.grid th { background: var(--surface-2); }
.grid th small { display: block; font-weight: 400; color: var(--muted); font-size: 0.72rem; }
.grid em { color: var(--muted); }
table.grid.wide { width: 100%; }
.grid tr.locked { opacity: 0.55; }
.pip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); margin-right: 3px; }
.pip.ok { background: var(--ok); border-color: var(--ok); }
textarea.sql-editor {
  font-family: var(--mono); font-size: 0.95rem; line-height: 1.5; min-height: 140px; resize: vertical;
  background: #1f1b2b; color: #f1edf8; border-color: #1f1b2b; padding: 0.8em 1em; tab-size: 2;
}
.form-actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: 0.75rem; }
.excel-steps { padding-left: 1.3rem; }
.excel-steps li { margin-bottom: 0.4rem; }
.result.pass { border-color: var(--ok); }
.result.pass > h2 { color: var(--ok); }
.result.fail { border-color: var(--bad); }
.result.fail > h2 { color: var(--bad); }
.checks { list-style: none; padding: 0; margin: 0 0 1rem; }
.checks li { display: flex; gap: 0.25rem; align-items: baseline; padding: 0.3rem 0; }
.checks li.bad { color: var(--bad); }
.result-compare { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; }
.sql-error { background: var(--bad-soft); color: var(--bad); white-space: pre-wrap; }
.payout { background: color-mix(in srgb, var(--coin) 12%, var(--surface)); border-radius: 8px; padding: 0.8rem 1rem; margin: 1rem 0; }
.payout h3 { margin: 0 0 0.3rem; color: var(--coin); }
.payout ul { margin: 0; padding-left: 1.2rem; }
.level-up { font-weight: 700; color: var(--accent); margin: 0.4rem 0 0; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; }
.q-result { border-top: 1px solid var(--line); padding-top: 0.75rem; margin-top: 0.75rem; }
.finish { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; }

/* --- Shop --- */
.shop-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.shop-item { display: flex; gap: 0.75rem; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem; background: var(--surface-2); }
.shop-item.equipped { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.shop-item p { margin: 0.1rem 0 0.4rem; }
.shop-item form { margin: 0; }

@media (max-width: 860px) {
  .lesson-layout { grid-template-columns: minmax(0, 1fr); }
  .buddy-panel { position: static; order: -1; display: flex; gap: 1rem; align-items: center; text-align: left; }
  .buddy-panel canvas { width: 72px; height: 96px; margin: 0; }
  .step { grid-template-columns: minmax(0, 1fr); }
  .result-compare { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2rem; }
  .signup-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .topbar { gap: 0.6rem 1rem; padding: 0.6rem 1rem; }
  .nav { order: 3; flex-basis: 100%; }
  .page { padding: 1rem; }
  .buddy-large { width: 144px; height: 192px; }
  .hero-buddies .buddy-canvas { margin-left: -28px; }
}

/* --- Passkeys --- */
.passkey-status { margin: 0.75rem 0 0; color: var(--muted); }
.passkey-status.passkey-error { color: var(--bad); }
.passkey-list { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.passkey-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.passkeys h2 { font-size: 1.15rem; margin-top: 1.5rem; }
