/* ============ MathQuest — minimalist UI ============ */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #1e293b;
  --ink-soft: #64748b;
  --line: #e2e8f0;
  --accent: #7c3aed;
  --accent-soft: #f5f3ff;
  --amber: #f59e0b;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --red: #ef4444;
  --red-soft: #fef2f2;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 880px; margin: 0 auto; padding: 24px 20px 80px; }

button { font: inherit; cursor: pointer; border: none; }

/* ---------- Header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 28px; gap: 12px; flex-wrap: wrap;
}
[data-quest="art"] .hero h1, [data-quest="art"] .lesson-head h1,
[data-quest="art"] .section h2, [data-quest="art"] .results h2 { font-family: Georgia, "Times New Roman", serif; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: -.02em; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.xp-pill {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 14px; padding: 6px 14px; border-radius: 999px;
}

/* ---------- Home ---------- */
.hero { margin-bottom: 28px; }
.hero h1 { font-size: 32px; font-weight: 800; letter-spacing: -.03em; line-height: 1.2; }
.hero p { color: var(--ink-soft); margin-top: 8px; max-width: 60ch; }

.overall {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 22px; margin-bottom: 28px; box-shadow: var(--shadow);
}
.overall .meta { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-soft); margin-bottom: 8px; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
  display: flex; flex-direction: column; gap: 8px; position: relative;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .emoji { font-size: 28px; }
.card h3 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; line-height: 1.3; }
.card .sub { font-size: 13px; color: var(--ink-soft); flex: 1; }
.card .status { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.status.todo { color: var(--ink-soft); }
.status.doing { color: var(--amber); }
.status.done { color: var(--green); }
.card .num {
  position: absolute; top: 14px; right: 16px; font-size: 12px; font-weight: 700;
  color: var(--ink-soft); background: var(--bg); padding: 2px 9px; border-radius: 999px;
}

.reset-row { text-align: center; margin-top: 36px; }
.reset-btn { background: none; color: var(--ink-soft); font-size: 13px; text-decoration: underline; }
.reset-btn:hover { color: var(--red); }

/* ---------- Lesson view ---------- */
.lesson-top { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.back-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--ink);
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

.lesson-head { margin: 18px 0 22px; }
.lesson-head .kicker { font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }
.lesson-head h1 { font-size: 30px; font-weight: 800; letter-spacing: -.03em; margin-top: 4px; }
.lesson-head p { color: var(--ink-soft); margin-top: 6px; }

.section-bar { display: flex; gap: 6px; margin-bottom: 26px; }
.section-bar .seg { flex: 1; height: 6px; border-radius: 999px; background: var(--line); cursor: pointer; transition: background .2s; }
.section-bar .seg.done { background: var(--accent); }
.section-bar .seg.current { background: var(--amber); }

.section {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 34px; box-shadow: var(--shadow); animation: fadein .3s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 14px; }
.section h3 { font-size: 17px; font-weight: 700; margin: 22px 0 8px; }
.section p { margin: 12px 0; }
.section ul, .section ol { margin: 12px 0 12px 24px; }
.section li { margin: 6px 0; }
.section strong { font-weight: 700; }
.section svg { display: block; width: 100%; height: auto; margin: 20px auto; max-width: 640px; }
.section .formula {
  background: var(--accent-soft); border-radius: 12px; padding: 14px 20px;
  font-size: 18px; text-align: center; margin: 16px 0; font-weight: 600;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.section .callout {
  border-left: 4px solid var(--amber); background: #fffbeb;
  border-radius: 0 12px 12px 0; padding: 12px 18px; margin: 16px 0; font-size: 15px;
}
.section .example {
  border: 1px dashed var(--line); border-radius: 12px; padding: 16px 20px; margin: 16px 0;
  background: var(--bg);
}
.section .example .tag { font-size: 12px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }
.section .widget {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 22px; margin: 18px 0; text-align: center;
}
.section .widget input[type=range] { width: 80%; accent-color: var(--accent); margin: 8px 0; }
.section .widget .readout { font-size: 18px; font-weight: 700; }
.section table { border-collapse: collapse; margin: 16px auto; }
.section th, .section td { border: 1px solid var(--line); padding: 8px 16px; text-align: center; }
.section th { background: var(--accent-soft); }

.nav-row { display: flex; justify-content: space-between; margin-top: 22px; gap: 12px; }
.btn {
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
  padding: 12px 26px; border-radius: 12px; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }

/* ---------- Quiz ---------- */
.quiz-progress { font-size: 14px; font-weight: 700; color: var(--ink-soft); margin-bottom: 14px; }
.question { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 20px; line-height: 1.45; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  background: var(--bg); border: 2px solid var(--line); border-radius: 12px;
  padding: 14px 18px; text-align: left; font-size: 16px; color: var(--ink);
  transition: border-color .15s, background .15s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.choice.correct { border-color: var(--green); background: var(--green-soft); font-weight: 700; }
.choice.wrong { border-color: var(--red); background: var(--red-soft); }
.choice:disabled { cursor: default; }

.feedback { border-radius: 12px; padding: 18px 22px; margin-top: 18px; animation: fadein .25s ease; }
.feedback.good { background: var(--green-soft); border: 1px solid var(--green); }
.feedback.bad { background: var(--red-soft); border: 1px solid var(--red); }
.feedback .verdict { font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.feedback.good .verdict { color: var(--green); }
.feedback.bad .verdict { color: var(--red); }
.feedback p { font-size: 15px; }

/* ---------- Results ---------- */
.results { text-align: center; padding: 40px 20px; }
.results .big { font-size: 64px; }
.results h2 { font-size: 28px; font-weight: 800; margin: 10px 0 6px; }
.results p { color: var(--ink-soft); margin-bottom: 24px; }
.score-ring { margin: 10px auto 20px; }

@media (max-width: 560px) {
  .section { padding: 22px 18px; }
  .hero h1 { font-size: 26px; }
}

/* ---------- Artwork figures ---------- */
.section figure.artwork { margin: 22px auto; max-width: 640px; text-align: center; }
.section figure.artwork img {
  max-width: 100%; height: auto; border-radius: 10px;
  box-shadow: 0 2px 8px rgba(41, 37, 36, .12), 0 8px 28px rgba(41, 37, 36, .10);
  background: var(--line); min-height: 60px;
}
.section figure.artwork figcaption {
  font-size: 13.5px; color: var(--ink-soft); margin-top: 10px; line-height: 1.5; font-style: italic;
}
.section figure.artwork figcaption strong { font-style: normal; color: var(--ink); }
.section figure.artwork.missing img { display: none; }
.section figure.artwork.missing::before {
  content: "🖼 Image needs an internet connection";
  display: block; padding: 26px 10px; border: 1px dashed var(--line);
  border-radius: 10px; color: var(--ink-soft); font-size: 14px; background: var(--bg);
}
.art-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.art-row figure.artwork { flex: 1 1 260px; max-width: 320px; margin: 10px 0; }

/* ---------- External artwork links ---------- */
.section a { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.section a:hover { filter: brightness(1.2); }
.see-real { font-size: 14.5px; margin: 10px 0 18px; }

/* ---------- Language toggle ---------- */
.lang-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 13.5px; font-weight: 700; color: var(--ink);
}
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Per-quest themes ---------- */
[data-quest="math"] { --accent: #6366f1; --accent-soft: #eef2ff; --bg: #f8fafc; --ink: #1e293b; --ink-soft: #64748b; --line: #e2e8f0; }
[data-quest="art"]  { --accent: #be123c; --accent-soft: #fdf2f4; --bg: #faf8f4; --ink: #292524; --ink-soft: #78716c; --line: #e7e5e4; }
[data-quest="code"] { --accent: #0f766e; --accent-soft: #f0fdfa; --bg: #f8fafc; --ink: #1e293b; --ink-soft: #64748b; --line: #e2e8f0; }
[data-quest="physics"] { --accent: #0284c7; --accent-soft: #e0f2fe; --bg: #f8fafc; --ink: #1e293b; --ink-soft: #64748b; --line: #e2e8f0; }
[data-quest="fashion"] { --accent: #db2777; --accent-soft: #fdf2f8; --bg: #fdfcfb; --ink: #292524; --ink-soft: #78716c; --line: #e7e5e4; }
[data-quest="history"] { --accent: #b45309; --accent-soft: #fef3c7; --bg: #fbf9f4; --ink: #292524; --ink-soft: #78716c; --line: #e7e5e4; }
[data-quest="myth"] { --accent: #7e22ce; --accent-soft: #faf5ff; --bg: #fbfafc; --ink: #292524; --ink-soft: #78716c; --line: #e7e5e4; }
[data-quest="arch"] { --accent: #1d4ed8; --accent-soft: #eff6ff; --bg: #f8fafc; --ink: #1e293b; --ink-soft: #64748b; --line: #e2e8f0; }
[data-quest="norse"] { --accent: #334155; --accent-soft: #f1f5f9; --bg: #f8fafc; --ink: #1e293b; --ink-soft: #64748b; --line: #e2e8f0; }
[data-quest="cooking"] { --accent: #ea580c; --accent-soft: #fff7ed; --bg: #fdfaf7; --ink: #292524; --ink-soft: #78716c; --line: #e7e5e4; }
body { background: var(--bg); color: var(--ink); }

/* ---------- Hub landing ---------- */
.quest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.quest-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px 24px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
  display: flex; flex-direction: column; gap: 10px;
}
.quest-card:hover { transform: translateY(-3px); }
.quest-card .q-emoji { font-size: 42px; }
.quest-card h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.quest-card .q-tag { color: var(--ink-soft); font-size: 14.5px; flex: 1; }
.quest-card .q-meta { font-size: 13px; font-weight: 700; }
.quest-card.qc-math:hover { border-color: #6366f1; } .quest-card.qc-math .q-meta { color: #6366f1; }
.quest-card.qc-art:hover  { border-color: #be123c; } .quest-card.qc-art .q-meta { color: #be123c; }
.quest-card.qc-code:hover { border-color: #0f766e; } .quest-card.qc-code .q-meta { color: #0f766e; }
.quest-card.qc-physics:hover { border-color: #0284c7; } .quest-card.qc-physics .q-meta { color: #0284c7; }
.quest-card.qc-fashion:hover { border-color: #db2777; } .quest-card.qc-fashion .q-meta { color: #db2777; }
.quest-card.qc-history:hover { border-color: #b45309; } .quest-card.qc-history .q-meta { color: #b45309; }
.quest-card.qc-myth:hover { border-color: #7e22ce; } .quest-card.qc-myth .q-meta { color: #7e22ce; }
.quest-card.qc-arch:hover { border-color: #1d4ed8; } .quest-card.qc-arch .q-meta { color: #1d4ed8; }
.quest-card.qc-norse:hover { border-color: #334155; } .quest-card.qc-norse .q-meta { color: #334155; }
.quest-card.qc-cooking:hover { border-color: #ea580c; } .quest-card.qc-cooking .q-meta { color: #ea580c; }
.module-head { margin: 30px 0 14px; }
.module-head h2 { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.module-head p { font-size: 13.5px; color: var(--ink-soft); }
.crumb { color: var(--ink-soft); font-size: 14px; margin-bottom: 6px; }

/* ---------- Code blocks & Python runner ---------- */
.section pre.codeblock {
  background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 16px 20px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 14.5px;
  line-height: 1.6; overflow-x: auto; margin: 16px 0; white-space: pre;
}
.section pre.codeblock .kw { color: #93c5fd; }
.pyrun { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 18px 0; background: var(--card); }
.pyrun textarea.pycode {
  display: block; width: 100%; border: none; resize: vertical; padding: 14px 16px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 14.5px;
  line-height: 1.6; color: #0f172a; background: #f8fafc; min-height: 60px; box-sizing: border-box;
}
.pyrun textarea.pycode:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.pyrun-bar { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-top: 1px solid var(--line); }
.run-btn {
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13.5px;
  padding: 7px 18px; border-radius: 8px;
}
.run-btn:hover { filter: brightness(1.1); }
.run-btn:disabled { opacity: .5; }
.py-status { font-size: 12.5px; color: var(--ink-soft); }
.pyrun pre.pyout {
  margin: 0; padding: 12px 16px; background: #0f172a; color: #a7f3d0;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 14px;
  line-height: 1.55; white-space: pre-wrap; min-height: 20px; max-height: 340px; overflow-y: auto;
}
.pyrun pre.pyout:empty::before { content: "▸ output will appear here"; color: #475569; }
.pyrun pre.pyout.err { color: #fca5a5; }

/* ---------- Hub category sections ---------- */
.cat-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 34px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.cat-head:first-of-type { margin-top: 8px; }
.cat-head h2 {
  font-size: 15px; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink);
}
.cat-head span { font-size: 13px; color: var(--ink-soft); }

/* ---------- Recipe cards (Cooking) ---------- */
.recipe {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  margin: 22px 0; background: var(--card); box-shadow: var(--shadow);
}
.recipe-head { padding: 16px 22px 12px; border-bottom: 1px solid var(--line); background: var(--accent-soft); }
.recipe-head h3 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.recipe-meta { font-size: 13px; color: var(--ink-soft); margin-top: 5px; display: flex; gap: 14px; flex-wrap: wrap; }
.recipe-body { padding: 18px 22px 20px; }
.recipe-body h4 {
  font-size: 12.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); margin: 14px 0 8px;
}
.recipe-body h4:first-child { margin-top: 0; }
.recipe-body ul, .recipe-body ol { margin: 0 0 4px 22px; }
.recipe-body li { margin: 5px 0; }
.recipe-body ul li { list-style: none; position: relative; }
.recipe-body ul li::before {
  content: ""; position: absolute; left: -16px; top: 9px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}

/* ---------- Safety callout ---------- */
.callout.safety {
  border-left-color: #dc2626; background: #fef2f2;
}
.callout.safety strong:first-child { color: #b91c1c; }

/* Lists inside centered widgets: keep bullets attached to their text */
.section .widget ul, .section .widget ol {
  display: inline-block; text-align: left; margin: 10px auto;
}

/* ---------- Progress backup row (hub) ---------- */
.backup-row {
  margin: 40px 0 10px; padding-top: 20px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: 13.5px; color: var(--ink-soft);
}
.backup-row span { margin-right: auto; }
.backup-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 15px; font-size: 13.5px; font-weight: 600; color: var(--ink);
}
.backup-btn:hover { border-color: var(--accent); color: var(--accent); }
