/* ==========================================================
   A3j matek – stílusok
   Nyugodt, „egyetemi jegyzet” hangulat: papírszerű háttér,
   serif szövegtörzs a matekhoz, sans-serif a kezelőfelülethez.
   ========================================================== */

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1d1f24;
  --muted: #646872;
  --border: #e2ded4;
  --border-strong: #cfc9bc;
  --accent: #1A4D99;
  --accent-soft: #e6edf8;
  --def: #1A4D99;
  --def-soft: #e8eef8;
  --thm: #3E9A12;
  --thm-soft: #eaf5e3;
  --ok: #2f8a1a;
  --ok-hover: #277415;
  --fail: #c63a32;
  --fail-hover: #a8302a;
  --warn-soft: #fdf3dc;
  --warn: #a86400;
  --shadow: 0 1px 2px rgba(30, 28, 20, .05), 0 6px 24px rgba(30, 28, 20, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --topbar-h: 56px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-text: "Source Serif 4", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --surface: #1f2228;
    --surface-2: #272a31;
    --text: #e7e8ea;
    --muted: #9aa0aa;
    --border: #30343c;
    --border-strong: #3d424b;
    --accent: #7aa7ec;
    --accent-soft: #22324b;
    --def: #6f9de6;
    --def-soft: #1f2c42;
    --thm: #74c24a;
    --thm-soft: #1f3320;
    --ok: #3f9e28;
    --ok-hover: #4aae31;
    --fail: #d24a42;
    --fail-hover: #e05a52;
    --warn-soft: #3a3220;
    --warn: #e0a640;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1f2228;
  --surface-2: #272a31;
  --text: #e7e8ea;
  --muted: #9aa0aa;
  --border: #30343c;
  --border-strong: #3d424b;
  --accent: #7aa7ec;
  --accent-soft: #22324b;
  --def: #6f9de6;
  --def-soft: #1f2c42;
  --thm: #74c24a;
  --thm-soft: #1f3320;
  --ok: #3f9e28;
  --ok-hover: #4aae31;
  --fail: #d24a42;
  --fail-hover: #e05a52;
  --warn-soft: #3a3220;
  --warn: #e0a640;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--topbar-h);
}
main { flex: 1; }
[hidden] { display: none !important; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-family: var(--font-text); font-weight: 700; letter-spacing: -.01em; }
h2 { font-family: var(--font-text); font-weight: 600; }
kbd {
  font-family: var(--font-ui);
  font-size: .72em;
  padding: .1em .45em;
  border: 1px solid currentColor;
  border-radius: 5px;
  opacity: .7;
  margin-left: .4em;
}
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.container.narrow { max-width: 760px; }

/* ---------- Felső sáv ---------- */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.topbar-inner {
  max-width: 1080px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  font-family: var(--font-text);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}
.mainnav { display: flex; gap: 4px; }
.mainnav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
}
.mainnav a:hover { color: var(--text); background: var(--surface-2); }
.mainnav a.active { color: var(--text); background: var(--surface-2); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.menu-btn { display: none; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}

@media (max-width: 640px) {
  .menu-btn { display: inline-grid; }
  .mainnav {
    position: absolute;
    top: var(--topbar-h);
    left: 0; right: 0;
    flex-direction: column;
    gap: 0;
    padding: 8px 12px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: none;
  }
  .mainnav.open { display: flex; }
  .mainnav a { padding: 12px 14px; font-size: 1.05rem; }
}

/* ---------- Gombok ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  padding: 10px 18px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
:root[data-theme="dark"] .btn-primary { color: #0f1a2c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0f1a2c; } }
.btn-lg { min-height: 52px; font-size: 1.02rem; padding: 12px 22px; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: var(--ok-hover); }
.btn-fail { background: var(--fail); border-color: var(--fail); color: #fff; }
.btn-fail:hover { background: var(--fail-hover); }
.link-btn {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 2px;
}
.link-btn:hover { text-decoration: underline; }
.tag {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--muted);
  vertical-align: middle;
}

.eyebrow {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 .6em;
}
.lead { font-family: var(--font-text); font-size: 1.15rem; color: var(--muted); margin: 0 0 1.4em; }
.notice {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  font-size: .95rem;
}

/* ---------- Főoldal ---------- */
.home { padding-top: 56px; padding-bottom: 64px; }
.home h1 { font-size: clamp(2rem, 6vw, 2.6rem); margin-bottom: .3em; }
.instructor { margin: 0 0 40px; color: var(--muted); }
.instructor a { word-break: break-word; }
.home-list { margin: 0; font-family: var(--font-text); font-size: 1.1rem; }
.home-list dt { font-family: var(--font-ui); font-weight: 600; font-size: 1.05rem; }
.home-list dd { margin: 2px 0 24px; color: var(--muted); }
.home-list dd:last-child { margin-bottom: 0; }

/* ---------- Kártya beállítások ---------- */
.page-title { font-size: 2rem; margin: 32px 0 20px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.panel-title {
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 12px;
}
.quick { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.hint { margin: 10px 0 0; font-size: .87rem; color: var(--muted); }
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { flex: 1 1 140px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}
.segmented span:hover { background: var(--surface-2); }
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.week-group + .week-group { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.week-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.week-head label { font-weight: 600; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.cat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px 7px 28px;
  cursor: pointer;
  border-radius: 8px;
}
.cat:hover { background: var(--surface-2); }
.cat .count, .week-head .count {
  margin-left: auto;
  font-size: .82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: 999px;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0; }

.startbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  margin-bottom: 20px;
}
.selcount { font-weight: 600; }
.resume {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px 18px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  border: 1px solid var(--border-strong);
}
.resume p { margin: 2px 0 0; font-size: .9rem; }
.resume-actions { display: flex; gap: 8px; }

/* ---------- Gyakorlás ---------- */
.practice {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  height: calc(100dvh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.practice-meta { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .95rem; margin-bottom: 8px; }
.practice-meta .spacer { flex: 1; }
.practice-meta .muted { font-weight: 500; font-size: .88rem; }
.dot { color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress.big { height: 10px; margin: 18px 0 24px; }
.progress-bar { height: 100%; width: 0; background: var(--ok); border-radius: 999px; transition: width .35s ease; }

.card-stage { flex: 1; min-height: 0; perspective: 1600px; }
.flashcard { position: relative; width: 100%; height: 100%; cursor: pointer; outline: none; border-radius: var(--radius); }
.flashcard:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.flashcard-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform .5s cubic-bezier(.3, .7, .3, 1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard.no-anim .flashcard-inner { transition: none; }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 6px solid var(--kind, var(--def));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.face.back { transform: rotateY(180deg); }
.flashcard[data-kind="tétel"] { --kind: var(--thm); --kind-soft: var(--thm-soft); }
.flashcard[data-kind="definíció"] { --kind: var(--def); --kind-soft: var(--def-soft); }
.face-label {
  flex: none;
  padding: 14px 20px 0;
  font-size: .82rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}
.face-label .kind {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .72rem;
  color: var(--kind);
  background: var(--kind-soft);
  padding: 2px 8px;
  border-radius: 999px;
}
.face-label .id { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.face-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 24px 22px;
  display: flex;
  flex-direction: column;
}
.face.front .face-body > .md { margin: auto 0; }
.face-foot { flex: none; text-align: center; font-size: .8rem; padding: 0 16px 14px; }
@media (hover: none) { .face-foot { font-size: 0; } .face-foot::after { content: "Érintsd meg a megfordításhoz"; font-size: .8rem; } }

.md { font-family: var(--font-text); font-size: 1.12rem; line-height: 1.6; overflow-wrap: break-word; }
.md.question { font-size: clamp(1.25rem, 3.2vw, 1.6rem); font-weight: 600; text-align: center; line-height: 1.4; }
.md p { margin: 0 0 .8em; }
.md > :last-child { margin-bottom: 0; }
.md ol, .md ul { margin: 0 0 .8em; padding-left: 1.5em; }
.md li { margin-bottom: .35em; }
.md li > p { margin-bottom: .35em; }
.md strong { font-weight: 700; }
.md .katex { font-size: 1.06em; }
.md .katex-display {
  position: relative; /* a KaTeX rejtett MathML-je ne lógjon ki a görgethető dobozból */
  margin: .7em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px;
  -webkit-overflow-scrolling: touch;
}
.md .katex-display > .katex { white-space: nowrap; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }

.answer-bar { flex: none; }
.btn-flip { width: 100%; }
.grade-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) {
  .practice { padding-left: 12px; padding-right: 12px; gap: 10px; }
  .face-body { padding: 12px 16px 18px; }
  .face-label { padding: 12px 16px 0; }
  .md { font-size: 1.05rem; }
  kbd { display: none; }
  .practice-meta { font-size: .88rem; }
}

/* ---------- Köztes és záróképernyő ---------- */
.screen {
  margin: 40px 0;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.screen h2 { font-size: 1.7rem; }
.screen-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 20px 0; }
.stats div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.stats dt { font-size: .8rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr 1fr; } .screen { padding: 24px 18px; } }
.worst { list-style: none; padding: 0; margin: 8px 0 0; }
.worst li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .93rem; align-items: baseline; }
.worst li:last-child { border-bottom: 0; }
.worst .id { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.worst .q { flex: 1; }
.worst .n { flex: none; color: var(--fail); font-weight: 600; white-space: nowrap; }
.soon p { color: var(--muted); }

/* ---------- Feladatok ---------- */
.tasks-page { max-width: 1120px; }
.tasks-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; padding-bottom: 48px; }
.toc { position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 32px); overflow-y: auto; }
.toc summary {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 4px 0 10px;
  cursor: pointer;
  list-style: none;
}
.toc summary::-webkit-details-marker { display: none; }
.toc-link {
  display: flex;
  gap: 8px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: .88rem;
  line-height: 1.35;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 7px 8px;
  cursor: pointer;
}
.toc-link:hover { background: var(--surface-2); }
.toc-link .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (min-width: 900px) { .toc summary { pointer-events: none; } }
@media (max-width: 899px) {
  .tasks-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc { position: static; max-height: none; overflow: visible; margin-bottom: 14px; }
  .toc details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 14px; }
  .toc summary { padding: 10px 0; display: flex; justify-content: space-between; }
  .toc summary::after { content: "▾"; }
  .toc details[open] summary::after { content: "▴"; }
  .toc nav { padding-bottom: 8px; }
}

.task-filters { display: flex; flex-direction: column; gap: 10px; }
.task-filters input[type="search"] {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-row select { flex: 1 1 180px; width: auto; min-width: 0; }
.filter-row .spacer { flex: 1; }
.filter-row.actions .muted { font-size: .9rem; }
select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.task-group { margin-top: 32px; scroll-margin-top: calc(var(--topbar-h) + 16px); }
.task-group-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.task-group-head h2 { font-size: 1.35rem; margin: 0; }
.task-group-head .count { font-size: .85rem; color: var(--muted); }
.tip {
  margin-bottom: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
}
.tip .md { font-size: 1rem; }
.lbl { display: block; font-family: var(--font-ui); font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.tip .lbl { color: var(--accent); }

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.task.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 30% { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); } 100% { border-color: var(--border); box-shadow: none; } }
.task h3 { margin: 0 0 2px; font-size: 1.05rem; }
.task-meta { font-size: .83rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.task-meta .pts { font-weight: 600; color: var(--text); }
.task .md { font-size: 1.05rem; }
.task .sol-btn { margin-top: 14px; }
.task-images { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.task-images img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); background: #fff; }
.task-solution { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.task-answer, .task-note { margin-top: 14px; padding: 12px 16px; border-radius: var(--radius-sm); }
.task-answer { background: var(--thm-soft); border-left: 4px solid var(--thm); }
.task-answer .lbl { color: var(--thm); }
.task-note { background: var(--warn-soft); border-left: 4px solid var(--warn); }
.task-note .lbl { color: var(--warn); }
.task-note .md, .task-answer .md { font-size: 1rem; }

.md table { position: relative; border-collapse: collapse; margin: .4em 0 1em; font-size: .95em; display: block; max-width: 100%; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border-strong); padding: 6px 10px; text-align: center; white-space: nowrap; }
.md th { background: var(--surface-2); font-weight: 600; }
.md blockquote { margin: 0 0 .8em; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  .flashcard-inner, .progress-bar { transition: none; }
  .task.flash { animation: none; }
}
