:root {
  --paper: #F7F9FC;
  --tint: #E4E9F2;
  --ink: #1B2A4A;
  --pencil: #5E6880;
  --line: #CDD5E3;
  --surface: #FFFFFF;
  --marker: #FFE45C;
  --marker-ink: #1B2A4A;
  --done: #1E7F5C;
  --focus: #2F6FEB;
  --error: #C0392B;
  --radius-s: 6px;
  --radius-l: 14px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --text: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131A29;
    --tint: #1B2436;
    --ink: #E6EAF2;
    --pencil: #9AA4BA;
    --line: #2C374D;
    --surface: #1A2233;
    --marker: #E8C93A;
    --marker-ink: #131A29;
    --done: #4CC495;
    --focus: #7FA8FF;
    --error: #FF8A7A;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font: 400 17px/1.6 var(--text);
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* Felső sáv */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font: 700 18px/1 var(--display); flex-shrink: 0; }
.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.crumbs { display: flex; gap: 6px; overflow-x: auto; white-space: nowrap; font-size: 14px; color: var(--pencil); scrollbar-width: none; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs span.sep { opacity: .5; }

/* A main csak programból kap fókuszt (képernyőolvasóknak), keret nem kell köré. */
main:focus, main:focus-visible { outline: none; }
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; outline: none; }
.foot { max-width: 760px; margin: 0 auto; padding: 16px 16px 32px; color: var(--pencil); font-size: 13px; }

/* Tipográfia */
h1 { font: 700 clamp(30px, 7vw, 44px)/1.08 var(--display); letter-spacing: -.01em; margin: 8px 0 12px; }
h2 { font: 700 24px/1.2 var(--display); margin: 40px 0 12px; }
h3 { font: 600 19px/1.3 var(--text); margin: 28px 0 8px; }
p { margin: 0 0 14px; max-width: 68ch; }
.lead { font-size: 19px; color: var(--pencil); }
ul, ol { padding-left: 22px; margin: 0 0 14px; }
li { margin-bottom: 6px; }
li > ul, li > ol { margin-top: 6px; }
.muted { color: var(--pencil); }
code { font: 500 .9em/1.4 ui-monospace, "SF Mono", Menlo, monospace; background: var(--tint); padding: .1em .35em; border-radius: 4px; white-space: nowrap; }
mark, .hl {
  background: linear-gradient(transparent 12%, var(--marker) 12%, var(--marker) 88%, transparent 88%);
  color: var(--marker-ink);
  padding: 0 .2em;
  border-radius: 2px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}

/* Kezdőlap */
.semester { margin-top: 32px; }
.semester h2 { margin-top: 0; font-size: 18px; color: var(--pencil); font-family: var(--text); font-weight: 600; }
.subject {
  display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 18px 18px 16px; margin-bottom: 12px;
}
.subject:hover { border-color: var(--pencil); }
.subject .t { font: 700 22px/1.2 var(--display); display: block; }
.subject .c { font-size: 14px; color: var(--pencil); display: block; margin-top: 4px; }
.meter { height: 6px; background: var(--tint); border-radius: 3px; margin-top: 14px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--done); border-radius: 3px; }
.meter-label { font-size: 13px; color: var(--pencil); margin-top: 6px; }
.empty { border: 1.5px dashed var(--line); border-radius: var(--radius-l); padding: 18px; color: var(--pencil); }

/* Hetek listája */
.weeks { list-style: none; padding: 0; margin: 20px 0 0; border-left: 2px solid var(--line); }
.weeks li { margin: 0; }
.week {
  display: grid; grid-template-columns: 44px 1fr; gap: 0 12px; align-items: start;
  text-decoration: none; padding: 12px 0 12px 0; position: relative;
}
.week .n {
  font: 700 15px/1 var(--display);
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; margin-left: -16px;
  background: var(--paper); border: 2px solid var(--line);
}
.week.complete .n { background: var(--done); border-color: var(--done); color: var(--paper); }
.week .t { font-weight: 600; font-size: 18px; }
.week .s { display: block; font-size: 14px; color: var(--pencil); }
.week:hover .t { text-decoration: underline; }
.week.soon { opacity: .55; pointer-events: none; }

/* Lecke */
.tabs {
  display: flex; gap: 4px; padding: 4px; margin: 20px 0 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  position: sticky; top: 60px; z-index: 4;
}
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--ink);
  font: 600 15px/1 var(--text); padding: 11px 8px; border-radius: 999px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); }

.toc { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.toc a { display: inline-block; font-size: 14px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; background: var(--surface); }

.scroll { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; background: var(--tint); }
tr:last-child td { border-bottom: 0; }

.recipe {
  border-left: 4px solid var(--ink); background: var(--surface);
  padding: 14px 16px 4px; margin: 0 0 16px; border-radius: 0 var(--radius-s) var(--radius-s) 0;
}
.recipe h3 { margin-top: 0; }
.rule { background: var(--tint); padding: 10px 14px; border-radius: var(--radius-s); margin: 0 0 14px; overflow-x: auto; }
.warn { border-left: 4px solid var(--marker); padding: 2px 0 2px 12px; }

.picker { list-style: none; padding: 0; }
.picker li { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); margin: 0; }
.picker li span:last-child { font-weight: 600; text-align: right; }

/* Feladatok */
.filter { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0; font-size: 15px; color: var(--pencil); }
.filter label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.filter input { width: 18px; height: 18px; accent-color: var(--done); }

.group-title { margin: 32px 0 10px; }
.problem {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  margin: 0 0 12px; overflow: hidden;
}
.problem.done { border-color: color-mix(in srgb, var(--done) 55%, var(--line)); }
.problem .head { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 0; }
.problem .id { font: 700 18px/1 var(--display); }
.stars { color: var(--pencil); font-size: 13px; letter-spacing: 1px; }
.problem .statement { padding: 8px 16px 4px; overflow-x: auto; }
.problem .statement .katex-display { margin: 6px 0; }
.actions { display: flex; gap: 8px; padding: 8px 16px 14px; flex-wrap: wrap; }
.btn {
  font: 600 15px/1 var(--text); padding: 11px 14px; min-height: 44px;
  border-radius: 999px; cursor: pointer; border: 1.5px solid var(--ink);
  background: transparent; color: var(--ink);
}
.btn.primary { background: var(--ink); color: var(--paper); }
a.btn { display: inline-block; text-decoration: none; }
.next { margin-top: 32px; }
.btn.check[aria-pressed="true"] { background: var(--done); border-color: var(--done); color: #fff; }
.hint { font-size: 14px; color: var(--pencil); padding: 0 16px 12px; margin: 0; }
.solution { border-top: 1px dashed var(--line); padding: 14px 16px 6px; overflow-x: auto; }
.solution[hidden] { display: none; }
.solution ol { padding-left: 20px; }
.answer { font-weight: 600; margin-top: 4px; }

@media (min-width: 640px) {
  main { padding-top: 40px; }
  .tabs { max-width: 360px; }
}
@media (prefers-reduced-motion: no-preference) {
  .solution:not([hidden]) { animation: open .18s ease-out; }
  @keyframes open { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
}
@media print {
  body { background: #fff; }
  .bar, .tabs, .actions, .filter, .foot, .toast { display: none; }
  .solution[hidden] { display: block; }
}

/* Fejléc: bejelentkezett felhasználó */
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; flex-shrink: 0; }
.user .who { color: var(--pencil); max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Telefonon a morzsamenü külön sorba kerül, hogy ne nyomja össze a név és a Kilépés */
@media (max-width: 560px) {
  .bar { flex-wrap: wrap; row-gap: 6px; }
  .crumbs { order: 3; flex-basis: 100%; }
  .crumbs:empty { display: none; }
  .tabs { top: 88px; }
}
.linkish { font: inherit; color: var(--ink); background: none; border: 0; padding: 4px 0; text-decoration: underline; cursor: pointer; }

/* Belépés */
.login { display: grid; gap: 6px; max-width: 420px; margin-top: 8px; }
.login label { font-weight: 600; margin-top: 10px; }
.login input:not([type="checkbox"]) {
  font: 400 17px/1.3 var(--text); color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--pencil); border-radius: var(--radius-s); padding: 11px 12px; min-height: 44px;
}
.login .btn { margin-top: 18px; justify-self: start; }
.login .btn:disabled { opacity: .6; cursor: progress; }
.form-who { margin: 0; color: var(--pencil); }
.form-help { margin: 0; font-size: 14px; color: var(--pencil); }
.form-error { margin: 0 0 6px; padding: 10px 12px; border-left: 4px solid var(--error); background: var(--surface); color: var(--ink); }

/* Állapotüzenet (mentési hiba, üdvözlés) */
.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  max-width: min(520px, calc(100% - 32px)); margin: 0;
  background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: var(--radius-s);
}
.toast:empty { padding: 0; }
