/* ─────────────────────────────────────────────────────────────
   Newton Kazakhstan · Олимпиадалық есептер
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:        #f7f7fb;
  --bg-soft:   #eeeef6;
  --surface:   #ffffff;
  --surface-2: #fafaff;
  --ink:       #0c0c14;
  --ink-2:     #45455a;
  --muted:     #74748c;
  --line:      #e4e4ef;
  --line-2:    #d3d3e4;

  --brand:     #3716ff;
  --brand-ink: #2a10c9;
  --brand-tint:#f0edff;
  --grad: linear-gradient(135deg, #1f7bde 0%, #3716ff 52%, #9e2d95 100%);

  --ok:        #0f8f5b;
  --ok-tint:   #e7f7ef;
  --bad:       #d0364a;
  --bad-tint:  #fdedef;

  --shadow-1: 0 1px 2px rgba(16,16,40,.05), 0 2px 8px rgba(16,16,40,.05);
  --shadow-2: 0 4px 12px rgba(16,16,40,.07), 0 18px 40px rgba(16,16,40,.09);
  --shadow-brand: 0 6px 20px rgba(55,22,255,.28);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --topbar-h: 60px;
  --col: 760px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          "Noto Sans", "Liberation Sans", Arial, sans-serif;
}

html[data-theme="dark"] {
  --bg:        #08080d;
  --bg-soft:   #101018;
  --surface:   #14141d;
  --surface-2: #191924;
  --ink:       #f3f3f9;
  --ink-2:     #c3c3d6;
  --muted:     #8f8fa8;
  --line:      #262633;
  --line-2:    #34344a;

  --brand:     #7c62ff;
  --brand-ink: #a998ff;
  --brand-tint:#1b1735;

  --ok:        #35c98a;
  --ok-tint:   #0e2a1f;
  --bad:       #ff707f;
  --bad-tint:  #2c1218;

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 6px 18px rgba(0,0,0,.45), 0 20px 48px rgba(0,0,0,.4);
  --shadow-brand: 0 6px 22px rgba(80,50,255,.4);
}

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

/* The UA rule for [hidden] is display:none, but any author rule that sets
   display beats it — .topbar, .sheet and .btn all do. Every screen, the
   palette sheet and the resume/finish buttons are toggled via the hidden
   attribute, so it has to win outright. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; height: auto; display: block; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ── brand lockup ───────────────────────────────────────────── */
.brand { display: inline-flex; align-items: center; gap: .6em; text-decoration: none; }
.brand__mark { flex: none; }
.brand__word { width: auto; }

.brand--sm .brand__mark { width: 30px; height: 30px; }
.brand--sm .brand__word { height: 26px; }

.brand--lg { gap: .72em; }
.brand--lg .brand__mark { width: 58px; height: 58px; }
.brand--lg .brand__word { height: 50px; }

html[data-theme="dark"] .brand__word--light,
html:not([data-theme="dark"]) .brand__word--dark { display: none; }

/* ── topbar ─────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__meta {
  justify-self: center;
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-variant-numeric: tabular-nums;
}
.counter { font-weight: 650; font-size: 15px; }
.timer { color: var(--muted); font-size: 14px; }

.topbar__actions { display: flex; align-items: center; gap: 8px; }

.progress {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--line);
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--grad);
  transition: width .35s cubic-bezier(.4,0,.2,1);
}

/* ── controls ───────────────────────────────────────────────── */
.iconbtn {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}
.iconbtn:hover { background: var(--bg-soft); color: var(--ink); }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

html[data-theme="dark"] .only-light,
html:not([data-theme="dark"]) .only-dark { display: none; }

.langswitch {
  display: inline-flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--bg-soft);
}
.langswitch button {
  padding: 5px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background .18s, color .18s, box-shadow .18s;
}
.langswitch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: transform .12s, background .18s, border-color .18s, box-shadow .18s, opacity .18s;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { border-color: var(--line-2); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: default; transform: none; }

.btn--primary {
  border-color: transparent;
  background: var(--grad);
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn--primary:hover { background: var(--grad); filter: brightness(1.06); }

.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--bg-soft); }

.btn--lg { padding: 15px 30px; font-size: 16px; border-radius: var(--r-lg); }
.btn--block { width: 100%; }
.btn--icon { padding: 12px; }

/* ── screens ────────────────────────────────────────────────── */
.screen {
  max-width: var(--col);
  margin: 0 auto;
  padding: 32px max(18px, env(safe-area-inset-left)) 120px;
}

/* ── start ──────────────────────────────────────────────────── */
.screen--start { padding-top: 6vh; }

.hero { text-align: center; display: grid; justify-items: center; gap: 22px; }

.eyebrow {
  margin: 6px 0 -8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero__title { font-size: clamp(30px, 6.4vw, 46px); }
.hero__lede { max-width: 46ch; color: var(--muted); font-size: 17px; }

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.stats li {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  font-size: 14px;
}
.stats b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); }

.langpick {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 460px;
  margin-top: 4px;
}
.langpick button {
  display: grid;
  gap: 3px;
  padding: 16px 18px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color .18s, background .18s, box-shadow .18s, transform .12s;
}
.langpick button:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); }
.langpick button b { font-size: 16px; }
.langpick button span { color: var(--muted); font-size: 13px; line-height: 1.35; }
.langpick button[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-tint);
  box-shadow: var(--shadow-1);
}

.hero__cta { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.hero__note { max-width: 42ch; color: var(--muted); font-size: 13.5px; }

/* ── question card ──────────────────────────────────────────── */
.qcard {
  padding: 30px 30px 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  animation: rise .32s cubic-bezier(.2,.7,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) { .qcard { animation: none; } }

.qcard__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.qcard__num {
  display: grid;
  place-items: center;
  min-width: 40px; height: 40px;
  padding: 0 10px;
  border-radius: 13px;
  background: var(--grad);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-brand);
}
.qcard__topic { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .02em; }

.qtext { font-size: 17.5px; line-height: 1.62; color: var(--ink); }

.qformula {
  margin: 20px 0 4px;
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  overflow-x: auto;
}
.qformula .katex-display { margin: 0; }

.qfigure {
  margin: 20px auto 0;
  max-width: 340px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
}
.qfigure img { border-radius: 8px; margin: 0 auto; }

/* ── options ────────────────────────────────────────────────── */
.options { display: grid; gap: 10px; margin-top: 24px; }

.option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color .16s, background .16s, transform .12s, box-shadow .16s;
}
.option:hover { border-color: var(--line-2); background: var(--surface-2); transform: translateX(2px); }
.option:active { transform: translateX(2px) scale(.995); }

.option__key {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px; height: 30px;
  border: 1.5px solid var(--line-2);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  transition: inherit;
}
.option__body { flex: 1; min-width: 0; overflow-x: auto; font-size: 16px; }

.option[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-tint);
}
.option[aria-pressed="true"] .option__key {
  border-color: transparent;
  background: var(--grad);
  color: #fff;
}

/* review states */
.option--correct { border-color: var(--ok); background: var(--ok-tint); }
.option--correct .option__key { border-color: transparent; background: var(--ok); color: #fff; }
.option--wrong { border-color: var(--bad); background: var(--bad-tint); }
.option--wrong .option__key { border-color: transparent; background: var(--bad); color: #fff; }
.option--static { cursor: default; }
.option--static:hover { transform: none; }

/* ── bottom nav ─────────────────────────────────────────────── */
.qnav {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(calc(100% - 32px), var(--col));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  box-shadow: var(--shadow-2);
}
.qnav .btn { flex: 1; }
.qnav .btn--icon { flex: none; }

/* ── palette sheet ──────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 60; display: grid; }
.sheet__scrim {
  position: absolute; inset: 0;
  background: rgba(10,10,24,.45);
  backdrop-filter: blur(3px);
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }

.sheet__panel {
  position: relative;
  align-self: end;
  justify-self: center;
  width: min(100%, 520px);
  margin: 0 0 max(0px, env(safe-area-inset-bottom));
  padding: 22px 22px calc(22px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  animation: slideup .28s cubic-bezier(.2,.8,.3,1);
}
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } }

@media (min-width: 560px) {
  .sheet__panel {
    align-self: center;
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    margin-bottom: 0;
  }
}

.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet__head h2 { font-size: 17px; }

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
  max-height: 44vh;
  overflow-y: auto;
  padding: 2px;
}
.palette button {
  aspect-ratio: 1;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: border-color .16s, background .16s, color .16s, transform .12s;
}
.palette button:hover { transform: translateY(-1px); border-color: var(--line-2); }
.palette button.is-done { border-color: transparent; background: var(--brand-tint); color: var(--brand-ink); }
.palette button.is-current { border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 0 0 3px var(--brand-tint); }
.palette button.is-correct { border-color: transparent; background: var(--ok-tint); color: var(--ok); }
.palette button.is-wrong { border-color: transparent; background: var(--bad-tint); color: var(--bad); }

.sheet__legend {
  display: flex;
  gap: 18px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 13px;
}
.sheet__legend span { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot--done { background: var(--brand); }
.dot--todo { border: 1.5px solid var(--line-2); }

/* ── result ─────────────────────────────────────────────────── */
.scorecard {
  display: grid;
  gap: 22px;
  justify-items: center;
  padding: 34px 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  text-align: center;
}

.ring { position: relative; width: 176px; height: 176px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring .ring__track { stroke: var(--line); }
.ring .ring__value { stroke: url(#nGrad); transition: stroke-dasharray .9s cubic-bezier(.3,.9,.3,1); }
.ring__label {
  position: absolute; inset: 0;
  display: grid; place-content: center; gap: 2px;
}
.ring__pct { font-size: 40px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.ring__of { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

.verdict { font-size: 22px; }
.scorecard__sub { color: var(--muted); font-size: 15px; }

.breakdown {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.breakdown li {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 14px;
  background: var(--bg-soft);
}
.breakdown b { font-variant-numeric: tabular-nums; }
.breakdown .is-ok  { background: var(--ok-tint);  color: var(--ok); }
.breakdown .is-bad { background: var(--bad-tint); color: var(--bad); }

.result__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 40px 0 18px; }
.filters button {
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .16s, color .16s, background .16s;
}
.filters button[aria-pressed="true"] { border-color: var(--brand); color: var(--brand-ink); background: var(--brand-tint); }

.review { display: grid; gap: 14px; }

.review__item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.review__item.is-ok  { border-left-color: var(--ok); }
.review__item.is-bad { border-left-color: var(--bad); }

.review__head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 15px 18px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.review__n {
  display: grid; place-items: center;
  flex: none;
  min-width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--bg-soft);
  font-size: 13px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.review__status { flex: 1; font-size: 14.5px; font-weight: 600; }
.review__item.is-ok  .review__status { color: var(--ok); }
.review__item.is-bad .review__status { color: var(--bad); }
.review__chev { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.review__item[open] .review__chev { transform: rotate(90deg); }

.review__body { padding: 0 18px 20px; border-top: 1px solid var(--line); padding-top: 18px; }
.review__body .qtext { font-size: 16px; }
.review__body .options { margin-top: 16px; }

.solution {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: var(--r-md);
  background: var(--bg-soft);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink-2);
}
.solution h4 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ── footer ─────────────────────────────────────────────────── */
.sitefoot {
  max-width: var(--col);
  margin: 60px auto 0;
  padding: 24px 18px 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.sitefoot a { color: var(--brand-ink); text-decoration: none; }
.sitefoot a:hover { text-decoration: underline; }

/* ── katex tuning ───────────────────────────────────────────── */
.katex { font-size: 1.06em; }
.qformula .katex { font-size: 1.24em; }
.katex-display > .katex { white-space: normal; }
.option__body .katex { font-size: 1.05em; }
.math-error { color: var(--bad); font-family: ui-monospace, monospace; font-size: .9em; }

/* ── responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar__meta { gap: 10px; font-size: 14px; }
  .topbar__actions { gap: 2px; }
  .topbar__actions .iconbtn { width: 34px; height: 34px; }
  #paletteBtn { display: none; }
  .langswitch button { padding: 5px 8px; font-size: 11px; }
  .brand--sm .brand__word { display: none; }
  .screen { padding: 22px 14px 110px; }
  .qcard { padding: 22px 18px 24px; border-radius: var(--r-lg); }
  .qtext { font-size: 16.5px; }
  .qnav { width: calc(100% - 24px); }
  .qnav .btn span { font-size: 14px; }
  .langpick { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  .qnav .btn span { display: none; }
}
