:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1b1f22;
  --ink-2: #5b6266;
  --line: #dcd8cf;
  --accent: #0b7a86;
  --accent-ink: #ffffff;
  --accent-soft: #d9eef0;
  --warn: #b5541c;
  --warn-soft: #f8e4d6;
  --ok: #2e7d4f;
  --ok-soft: #dcefe3;
  --radius: 14px;
  --nav-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181b;
    --surface: #1d2226;
    --surface-2: #262c31;
    --ink: #eef0f1;
    --ink-2: #a3abb0;
    --line: #333a40;
    --accent: #3fb6c2;
    --accent-ink: #0d1416;
    --accent-soft: #1b3a3e;
    --warn: #f0a070;
    --warn-soft: #3c2a1f;
    --ok: #6fcf97;
    --ok-soft: #1d3527;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }

/* nagłówek */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { border: 0; background: none; font-size: 30px; line-height: 1; padding: 0 6px 2px 0; color: var(--accent); cursor: pointer; }
.group { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
  outline: none;
}

/* dolna nawigacja */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; text-decoration: none; color: var(--ink-2);
}
.tabs a .ico { font-size: 19px; line-height: 1.2; }
.tabs a.on { color: var(--accent); }

/* karty */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card.hero { border: 0; background: var(--accent); color: var(--accent-ink); }
.card.hero .muted { color: inherit; opacity: .8; }
.card.hero .btn { background: var(--accent-ink); color: var(--accent); }
.card.exam { border-color: var(--warn); background: var(--warn-soft); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; opacity: .75; margin: 0 0 4px; }
h2 { font-size: 22px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.01em; }
h3 { font-size: 17px; margin: 0 0 8px; }
.muted { color: var(--ink-2); font-size: 14px; }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 22px 4px 8px; }
.big-when { font-size: 15px; font-weight: 600; margin: 2px 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* pasek postępu */
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.card.hero .bar { background: color-mix(in srgb, var(--accent-ink) 25%, transparent); }
.card.hero .bar > i { background: var(--accent-ink); }

/* lista harmonogramu */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; color: inherit; text-decoration: none; }
.date { flex: 0 0 52px; text-align: center; line-height: 1.1; }
.date b { display: block; font-size: 20px; }
.date span { font-size: 11px; text-transform: uppercase; color: var(--ink-2); font-weight: 600; }
.item-main { flex: 1; min-width: 0; }
.item-main .t { font-weight: 600; }
.item-main .s { font-size: 13px; color: var(--ink-2); }
.chev { color: var(--ink-2); font-size: 20px; }
.past { opacity: .5; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; margin-left: 4px; vertical-align: 1px; }
.tag.next { background: var(--accent); color: var(--accent-ink); }
.tag.today { background: var(--warn); color: #fff; }
.tag.kol { background: var(--warn-soft); color: var(--warn); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }

/* siatka tematów */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { display: block; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: inherit; text-decoration: none; }
.tile .n { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.tile .t { font-weight: 700; margin: 2px 0 10px; line-height: 1.25; min-height: 2.5em; }

/* przełącznik zakładek tematu */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin: 0 0 16px; position: sticky; top: calc(env(safe-area-inset-top) + 56px); z-index: 5; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* treść teorii */
.prose { overflow-wrap: anywhere; }
.prose p { margin: 0 0 10px; }
.prose ul { padding-left: 20px; margin: 6px 0 10px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.prose th { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: 8px 0 !important; }
.katex { font-size: 1.05em; }

details.th { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.th summary { padding: 14px 16px; font-weight: 700; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 8px; }
details.th summary::-webkit-details-marker { display: none; }
details.th summary::after { content: "+"; color: var(--ink-2); font-weight: 400; }
details.th[open] summary::after { content: "–"; }
details.th .prose { padding: 0 16px 14px; }

ol.steps { margin: 0; padding-left: 22px; }
ol.steps li { margin-bottom: 6px; }

/* zadania */
.task.done { border-color: var(--ok); }
.task .qh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.task .num { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.reveal { margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.reveal.sol { background: var(--ok-soft); }
.reveal .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin-bottom: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; cursor: pointer; user-select: none; }
.check input { width: 20px; height: 20px; accent-color: var(--ok); }

/* fiszki */
.flash { perspective: 1200px; margin-bottom: 14px; }
.flash .inner { position: relative; min-height: 240px; transition: transform .45s; transform-style: preserve-3d; cursor: pointer; }
.flash.flip .inner { transform: rotateY(180deg); }
.flash .face {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  -webkit-backface-visibility: hidden; backface-visibility: hidden; font-size: 19px; font-weight: 600;
}
.flash .rear { transform: rotateY(180deg); background: var(--accent-soft); font-weight: 500; }
.flash .face small { position: absolute; top: 12px; left: 16px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.counter { text-align: center; font-size: 14px; color: var(--ink-2); margin: 0 0 10px; }

.empty { text-align: center; padding: 30px 10px; color: var(--ink-2); }
.note { font-size: 13px; color: var(--ink-2); margin-top: 6px; }

/* kolory rodzajów wydarzeń */
:root { --k-cw: var(--accent); --k-kol: #d9822b; --k-lab: #7a5cc4; --k-rep: #8a9399; --k-exam: #c2414b; }
@media (prefers-color-scheme: dark) { :root { --k-kol: #f0a050; --k-lab: #a98ef0; --k-rep: #8f989e; --k-exam: #f07a83; } }
.k-cw { background: var(--k-cw); } .k-kol { background: var(--k-kol); } .k-lab { background: var(--k-lab); }
.k-rep { background: var(--k-rep); } .k-exam { background: var(--k-exam); }
.kbar { align-self: stretch; width: 4px; border-radius: 2px; flex: 0 0 4px; margin: -4px -4px -4px -6px; }

/* kalendarz miesięczny */
.cal { padding: 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head b { font-size: 17px; }
.cal-head .btn { min-width: 44px; font-size: 20px; }
.cal-head .btn:disabled { opacity: .3; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid.wd span { text-align: center; font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; padding-bottom: 4px; }
.cell { aspect-ratio: 1 / 1.05; border: 0; border-radius: 10px; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0; cursor: pointer; min-width: 0; }
.cell.empty { visibility: hidden; }
.cell .dn { font-size: 15px; font-weight: 500; line-height: 1; }
.cell.has { background: var(--surface-2); }
.cell.has .dn { font-weight: 700; }
.cell.today .dn { color: var(--accent); font-weight: 800; }
.cell.sel { background: var(--accent); }
.cell.sel .dn { color: var(--accent-ink); }
.dots { display: flex; gap: 3px; height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
.cell.sel .dots i { box-shadow: 0 0 0 1.5px var(--accent-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* laboratoria */
.lab.todo { border-left: 4px solid var(--k-kol); }
.lab.picked { border-left: 4px solid var(--k-lab); }
.lab.report { border-left: 4px solid var(--k-kol); }
.lab.done { border-left: 4px solid var(--ok); }
.lab.skip { opacity: .6; }
.lab-card { border-left: 4px solid var(--k-lab); }
.lbl-s { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 8px; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.slot { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; text-align: left; }
.slot b { font-size: 14px; }
.slot span { font-size: 13px; }
.slot small { font-size: 11px; color: var(--ink-2); }
.slot:active { background: var(--accent-soft); }
.picked { padding: 12px; border-radius: 10px; background: color-mix(in srgb, var(--k-lab) 14%, transparent); }
details.custom summary { font-size: 14px; font-weight: 600; color: var(--accent); cursor: pointer; margin-top: 10px; }
details.custom input { font: inherit; font-size: 15px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.tag.next { white-space: nowrap; }
