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

:root {
  --paper: #faf7f2;
  --ink: #241f31;
  --muted: #6f6a7d;
  --card: #ffffff;
  --line: #e8e2d9;
  --accent: #5b3df5;
  --accent2: #8b5cf6;
  --good: #16a34a;
  --bad: #dc2626;
  --gold: #f59e0b;
  --p3: #0ea5e9;
  --p4: #8b5cf6;
  --p5: #f43f5e;
}

body {
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(120deg, #2c2154, #4c2fb8);
  color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.brand {
  font-size: 1.35rem; font-weight: 800; letter-spacing: .3px;
  background: none; border: none; color: #fff; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-family: inherit;
}
.brand em { font-style: normal; color: #ffd166; }
.topbar-right { font-weight: 700; font-size: .95rem; opacity: .95; }

main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 26px 18px 60px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 14px; border-top: 1px solid var(--line); }

h1 { font-size: 1.7rem; margin-bottom: 6px; }
.sub { color: var(--muted); margin-bottom: 22px; max-width: 640px; }

/* ── home: grade grid ── */
.grade-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px;
}
.grade-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px; cursor: pointer; text-align: left; font-family: inherit;
  transition: transform .12s, box-shadow .12s;
  box-shadow: 0 1px 3px rgba(36,31,49,.06);
}
.grade-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(76,47,184,.16); }
.grade-card .gname { font-size: 1.15rem; font-weight: 800; }
.grade-card .gtheme { color: var(--muted); font-size: .85rem; margin: 4px 0 12px; min-height: 2.1em; }
.gc-top { display: flex; justify-content: space-between; align-items: baseline; }
.sat-chip {
  background: #fff3d6; color: #92600a; border-radius: 999px;
  font-size: .68rem; font-weight: 800; padding: 3px 9px; letter-spacing: .4px;
}
.pbar { height: 8px; border-radius: 999px; background: #eee7dc; overflow: hidden; }
.pbar > div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.gstat { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; margin-top: 7px; }

/* ── grade screen ── */
.crumbs { margin-bottom: 14px; }
.crumbs button {
  background: none; border: none; color: var(--accent); font-weight: 700;
  cursor: pointer; font-size: .92rem; font-family: inherit; padding: 0;
}
.grade-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 6px; }
.olymp-btn {
  margin-left: auto;
  background: linear-gradient(120deg, #f59e0b, #f43f5e); color: #fff;
  border: none; border-radius: 12px; padding: 11px 18px;
  font-weight: 800; font-size: .95rem; cursor: pointer; font-family: inherit;
  box-shadow: 0 4px 12px rgba(244,63,94,.25);
}
.olymp-btn:hover { filter: brightness(1.06); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 20px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 14px; font-size: .85rem; font-weight: 700; color: var(--muted);
  cursor: pointer; font-family: inherit;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: #efeaff; }

.tier { margin-bottom: 26px; }
.tier-title { display: flex; align-items: center; gap: 10px; font-weight: 800; margin-bottom: 10px; font-size: 1.02rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.p3 { background: var(--p3); } .dot.p4 { background: var(--p4); } .dot.p5 { background: var(--p5); }
.tier-sub { color: var(--muted); font-weight: 500; font-size: .8rem; }

.task-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.task-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; cursor: pointer; text-align: left; font-family: inherit;
  display: flex; flex-direction: column; gap: 8px; font-size: .92rem;
  transition: transform .1s, box-shadow .1s;
}
.task-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(36,31,49,.1); }
.task-card.done { border-color: #bfe6cc; background: #f4fbf6; }
.tc-top { display: flex; align-items: center; gap: 8px; }
.pts-badge { font-size: .72rem; font-weight: 800; color: #fff; border-radius: 8px; padding: 3px 8px; }
.pts-badge.p3 { background: var(--p3); } .pts-badge.p4 { background: var(--p4); } .pts-badge.p5 { background: var(--p5); }
.strand-tag { font-size: .72rem; font-weight: 700; color: var(--muted); }
.tc-check { margin-left: auto; color: var(--good); font-weight: 800; }
.tc-q { color: var(--ink); line-height: 1.45; }
.sat-mini { font-size: .68rem; font-weight: 800; color: #92600a; }

/* ── problem screen ── */
.prob-wrap { max-width: 760px; margin: 0 auto; }
.prob-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 26px 28px; box-shadow: 0 2px 10px rgba(36,31,49,.06);
}
.prob-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.prob-q { font-size: 1.18rem; line-height: 1.6; margin-bottom: 22px; font-weight: 600; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1.5px solid var(--line); background: #fdfcfa; border-radius: 12px;
  padding: 12px 16px; font-size: 1rem; cursor: pointer; font-family: inherit; color: var(--ink);
  transition: border-color .1s, background .1s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: #f6f3ff; }
.choice:disabled { cursor: default; }
.choice .letter {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px;
  display: flex; align-items: center; justify-content: center;
  background: #efeaff; color: var(--accent); font-weight: 800; font-size: .85rem;
}
.choice.correct { border-color: var(--good); background: #eefaf1; }
.choice.correct .letter { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: #fdf0ef; }
.choice.wrong .letter { background: var(--bad); color: #fff; }

.prob-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn {
  border: none; border-radius: 11px; padding: 11px 18px; font-weight: 800;
  font-size: .92rem; cursor: pointer; font-family: inherit;
}
/* Some buttons are real links now (print, teachers, the SEO landing pages) — a link is what
   a crawler follows and what a middle-click opens in a new tab. Strip the link underline and
   the visited colour so they still read as buttons. */
a.btn { display: inline-block; text-decoration: none; line-height: 1.2; }
a.btn:visited { color: inherit; }
a.btn.primary, a.btn.primary:visited { color: #fff; }
a.btn.ghost, a.btn.ghost:visited { color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: #efeaff; color: var(--accent); }
.btn.warn { background: #fff3d6; color: #92600a; }
.btn:hover { filter: brightness(1.05); }

.hint-box, .sol-box {
  margin-top: 18px; border-radius: 12px; padding: 14px 18px; line-height: 1.55; font-size: .95rem;
}
.hint-box { background: #fff8e8; border: 1px solid #f3dfae; }
.sol-box { background: #eefaf1; border: 1px solid #bfe6cc; }
.sol-box.reveal { background: #f6f3ff; border-color: #d6c9ff; }
.sol-box h4 { margin-bottom: 6px; }
.skill-banner {
  margin-top: 14px; display: flex; gap: 10px; align-items: flex-start;
  background: linear-gradient(120deg, #2c2154, #4c2fb8); color: #fff;
  border-radius: 12px; padding: 13px 17px; font-size: .93rem; line-height: 1.5;
}
.skill-banner .ico { font-size: 1.3rem; }
.feedback { margin-top: 14px; font-weight: 800; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.earned { color: var(--gold); }

/* ── quiz ── */
.quiz-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.timer { font-weight: 800; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }
.quiz-progress { color: var(--muted); font-weight: 700; }
.quiz-nav { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.result-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px; text-align: center; max-width: 620px; margin: 0 auto;
}
.result-score { font-size: 3rem; font-weight: 800; color: var(--accent); margin: 8px 0; }
.result-detail { color: var(--muted); margin-bottom: 18px; }
.review-list { text-align: left; margin: 18px 0; display: grid; gap: 8px; }
.review-item { display: flex; gap: 10px; align-items: baseline; font-size: .9rem; padding: 8px 12px; border-radius: 10px; background: #fdfcfa; border: 1px solid var(--line); }
.review-item .mark { font-weight: 800; }
.review-item .mark.ok { color: var(--good); }
.review-item .mark.no { color: var(--bad); }
.review-item .mark.skip { color: var(--muted); }

/* ── how others did (C15, 2026-10-19): the numbers per problem, and how others answered once finished ── */
.prob-stats { color: var(--muted); font-size: .82rem; font-weight: 600; margin: -6px 0 14px; }
.tc-stats { color: var(--muted); font-size: .74rem; font-weight: 600; }
.others { margin-top: 18px; border-radius: 12px; padding: 14px 18px; background: #f6f3ff; border: 1px solid #d6c9ff; font-size: .92rem; }
.others[hidden] { display: none; }
.others h4 { margin-bottom: 8px; }
.others-row { display: grid; grid-template-columns: 26px minmax(40px, 1fr) 44px 92px; align-items: center; gap: 10px; margin: 7px 0; }
.others-row .letter {
  width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: #efeaff; color: var(--accent); font-weight: 800; font-size: .78rem;
}
.others-row.right .letter { background: var(--good); color: #fff; }
.others-bar { height: 10px; border-radius: 999px; background: #e6e0f7; overflow: hidden; }
.others-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent2); }
.others-row.right .others-bar > span { background: var(--good); }
.others-pct { font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.others-tags { display: flex; gap: 4px; }
.others-tag { font-size: .68rem; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
.others-tag.right { background: #eefaf1; color: var(--good); border: 1px solid #bfe6cc; }
.others-tag.you { background: #fff3d6; color: #92600a; border: 1px solid #f3dfae; }
.others-foot { color: var(--muted); font-size: .8rem; margin-top: 8px; }
.others-mini { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; font-weight: 600; }

@media (max-width: 640px) {
  .prob-card { padding: 20px 16px; }
  h1 { font-size: 1.35rem; }
  .olymp-btn { margin-left: 0; }
}

/* problem illustrations + sharing */
.prob-img {
  display: block; max-width: 100%; max-height: 240px;
  margin: 0 auto 14px; border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  cursor: zoom-in;
}
/* the full-screen view of a picture (app.js openZoom) */
.zoom {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 12px; background: rgba(20, 16, 40, .92); cursor: zoom-out;
}
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; border-radius: 10px; }
.zoom-close {
  position: absolute; top: 10px; right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: #fff; color: var(--ink); font-size: 1.7rem; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.crumbs { display: flex; justify-content: space-between; align-items: center; }
.share-btn {
  background: none; border: 1px solid rgba(127,127,127,.35); border-radius: 8px;
  padding: 4px 12px; cursor: pointer; font: inherit; color: inherit; opacity: .85;
}
.share-btn:hover { opacity: 1; }

/* ── grade infographics, tags, search, auth, stats ── */
.diffbar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; margin: 8px 0 6px; width: 100%; }
.diffbar span { display: block; height: 100%; }
.gc-infobox { text-align: left; }
.gc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip.mini { font-size: .68rem; padding: 2px 8px; margin: 0; border-radius: 999px; opacity: .9; }
.gc-cum { font-size: .72rem; color: var(--gold); margin-top: 4px; font-weight: 700; }
.tag-mini { display: inline-block; font-size: .66rem; color: var(--accent); background: #efeaff; border-radius: 999px; padding: 1px 8px; margin-right: 4px; }
.tc-tags { display: block; margin: 2px 0 6px; }
.search-row { display: flex; gap: 8px; margin: 12px 0 0; align-items: center; }
.search-row input { flex: 1; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; font: inherit; }
.tagchips { margin-top: 4px; }
.auth-card { max-width: 460px; margin: 24px auto; }
.tb-user { font-weight: 700; margin-right: 2px; }
.tb-btn { padding: 4px 10px; font-size: .82rem; }
.prob-q-row { display: flex; gap: 10px; align-items: flex-start; }
.prob-q-row .prob-q { flex: 1; }
.tts-btn { padding: 6px 10px; border-radius: 10px; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 18px 0; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 12px; text-align: center; }
.sc-num { font-size: 1.9rem; font-weight: 800; color: var(--accent); }
.sc-label { color: var(--muted); font-size: .8rem; }
.stat-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.stat-row:last-child { border-bottom: none; }
.stat-label { width: 110px; font-weight: 700; }
.stat-row .pbar { flex: 1; }
.stat-val { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.admin-row.sub { margin-left: 22px; border-left: 2px solid var(--line); font-size: .85rem; }

/* ── phone rotation / landscape / small viewports ── */
@media (orientation: landscape) and (max-height: 520px) {
  .topbar { padding: 6px 14px; }
  .brand { font-size: 1.05rem; }
  main { padding: 10px 14px 30px; max-width: 100%; }
  h1 { font-size: 1.15rem; }
  .grade-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .grade-card .gtheme { display: none; }
  .gc-infobox { display: none; }
  .prob-card { padding: 12px 14px; }
  .prob-img { max-height: 120px; }
  .prob-q { font-size: .95rem; }
  .choice { padding: 8px 10px; font-size: .92rem; }
  .quiz-top { margin-bottom: 8px; }
  .review-item { font-size: .78rem; padding: 5px 8px; }
  .stat-cards { grid-template-columns: repeat(4, 1fr); }
  .result-score { font-size: 2rem; }
  .search-row input { padding: 6px 10px; }
}
@media (max-width: 640px) and (orientation: portrait) {
  .topbar { padding: 10px 14px; }
  .brand { font-size: 1.12rem; }
  .tb-user { display: none; }
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
  .stat-label { width: 84px; }
}
@media (max-width: 400px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .tc-tags .tag-mini { display: none; }
  .olymp-btn { font-size: .85rem; padding: 8px 10px; }
}

/* Public problem lists on the grade landing pages (gen_seo_pages.py) */
.seo-prob { background: #fff; border: 1px solid #e6e1f5; border-radius: 14px; padding: 14px 18px; margin: 14px 0; }
.seo-prob h3 { margin: 0 0 6px; font-size: 1rem; color: var(--accent); }
.seo-prob ol { margin: 8px 0 10px 1.4em; }
.seo-prob details { margin: 6px 0; }
.seo-prob summary { cursor: pointer; font-weight: 600; }

/* "Every puzzle has its own page" on the home screen (gen_seo_pages.py writes it into index.html) */
.browse { margin-top: 32px; }
.browse a.chip { text-decoration: none; display: inline-block; }
.browse details.seo-prob { padding: 10px 18px; }

/* How the content was made (owner, 2026-10-31: AI notices and annotations) */
.quiz-disclaimer { font-size: .76rem; color: var(--muted); margin: 0 0 12px; }
.ai-foot { display: inline-block; margin-top: 4px; opacity: .85; }
.foot-ai { font-weight: 700; }
.quiz-view .foot-ai { display: none; }   /* the quiz on screen carries it: one per view */

/* ── spacing (owner, 2026-10-31: "do proper padding on quizzes and hints and the rest and the whole page buttons") ── */
/* header: a gap between the buttons, each on one line */
.topbar { gap: 12px; }
.topbar-right { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.topbar-right a { white-space: nowrap; }
.tb-btn { padding: 7px 13px; border-radius: 999px; white-space: nowrap; line-height: 1.2; }
/* button rows: one gap everywhere, text centred */
.btn { line-height: 1.25; text-align: center; }
.prob-actions, .quiz-nav { gap: 10px; margin-top: 22px; }
/* the quiz boxes: room inside and between */
.feedback { margin-top: 16px; }
.hint-box, .sol-box, .others { margin-top: 16px; padding: 16px 20px; }
.sol-box h4 { margin-bottom: 8px; }
.skill-banner { margin-top: 16px; padding: 15px 20px; }
/* footer */
.foot { padding: 22px 18px 26px; line-height: 1.7; }
.ai-foot { margin-top: 8px; line-height: 1.55; max-width: 920px; }
/* public problem pages: the problem, its options, the hints and the answer */
.seo-prob { padding: 18px 22px; margin: 18px 0; }
.seo-prob h3 { margin: 0 0 4px; }
.seo-prob > p { line-height: 1.6; margin: 8px 0; }
.seo-prob ol { margin: 10px 0 14px 1.8em; }
.seo-prob ol li { padding: 3px 0 3px 4px; }
.seo-prob details { margin: 12px 0 0; border-radius: 12px; border: 1px solid #f3dfae; background: #fff8e8; }
.seo-prob details:last-of-type { border-color: #d6c9ff; background: #f6f3ff; }   /* the answer and solution */
.seo-prob summary { padding: 11px 16px; font-weight: 700; }
.seo-prob details > :not(summary) { margin: 0 18px 14px; line-height: 1.6; }
.seo-prob details ul { padding-left: 1.2em; }
.seo-prob details li { margin: 4px 0; }
.prob-actions + .sub { margin: 14px auto 22px; }
@media (max-width: 640px) {
  .prob-actions .btn, .quiz-nav .btn { flex: 1 1 auto; padding: 12px 16px; }
  .hint-box, .sol-box, .others { padding: 14px 16px; }
  .skill-banner { padding: 14px 16px; }
  .seo-prob { padding: 16px; }
  .seo-prob details > :not(summary) { margin: 0 14px 12px; }
}
@media (max-width: 480px) {
  .tb-long { display: none; }
  .tb-btn { padding: 7px 11px; }
  .topbar-right a:not(.btn) { font-size: .8rem; }   /* "Free teacher downloads" beside the longer name (2026-11-01) */
  .brand { font-size: 1.05rem; }
}
