/* ============================================================
   Marcin Słowik @ W04N/K68 — clean minimal academic theme
   Accents: PWr red #b4312c, faculty (WIT/K2) orange #de4a2a
   ============================================================ */

:root {
  --accent: #b4312c;
  --accent-2: #de4a2a;
  --accent-contrast: #ffffff;

  --bg: #ffffff;
  --bg-alt: #f6f5f4;
  --surface: #ffffff;
  --border: #e3e0dd;
  --text: #1f1d1c;
  --text-soft: #5f5c58;
  --heading: #141312;

  --code-bg: #f4f2f0;
  --mark-bg: #fdf0d5;

  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --radius: 8px;

  --max-width: 76ch;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --accent: #e0705f;
  --accent-2: #f0804f;
  --accent-contrast: #1a0e0c;

  --bg: #16130f;
  --bg-alt: #1e1a16;
  --surface: #1c1815;
  --border: #322d27;
  --text: #e2ded9;
  --text-soft: #a49e95;
  --heading: #f5f2ee;

  --code-bg: #26211c;
  --mark-bg: #4a3a1f;

  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h, 64px) + 1rem);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

::selection { background: var(--accent); color: var(--accent-contrast); }

a { color: var(--accent); }
a:hover { color: var(--accent-2); }

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: .5rem 1rem;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  height: 64px; /* matches --header-h fallback */
}

.site-header-inner {
  max-width: calc(var(--max-width) + 4rem);
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-title {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 600;
  color: var(--heading);
  text-decoration: none;
  font-size: 1.05rem;
  white-space: nowrap;
}
.site-title:hover { color: var(--accent); }
.site-logo { display: block; }
.site-subtitle { color: var(--text-soft); font-weight: 400; font-size: .85em; }

.site-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav::-webkit-scrollbar { display: none; }

.site-nav a {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .8rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-soft);
  font-size: .92rem;
  white-space: nowrap;
  transition: color .15s, background .15s;
}
.site-nav a svg { width: 16px; height: 16px; flex: none; }
.site-nav a:hover { color: var(--text); background: var(--bg-alt); }
.site-nav a.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-weight: 600;
}

.site-actions { display: flex; align-items: center; gap: .25rem; margin-left: .25rem; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-alt); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

[data-theme="light"] #theme-icon-moon { display: none; }
[data-theme="dark"]  #theme-icon-sun  { display: none; }

/* ---------- page layout ---------- */

.page { min-height: calc(100vh - 64px - 80px); }
.page-inner {
  max-width: calc(var(--max-width) + 4rem);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.5rem;
}

@media (min-width: 1100px) {
  .page-inner:has(.toc:not(:empty)) {
    grid-template-columns: minmax(0, 1fr) 220px;
  }
  .toc-container { order: 2; }
}

.view { max-width: 100%; min-height: 40vh; }

/* ---------- markdown content ---------- */

.view h1, .view h2, .view h3, .view h4 {
  color: var(--heading);
  line-height: 1.25;
  scroll-margin-top: calc(var(--header-h, 64px) + 1rem);
}

.view h1 {
  font-size: 1.9rem;
  margin: 0 0 1.25rem;
  padding-bottom: .6rem;
  border-bottom: 2px solid var(--accent);
}
.view h2 { font-size: 1.45rem; margin: 2.5rem 0 1rem; }
.view h3 { font-size: 1.2rem;  margin: 2rem 0 .8rem; }
.view h4 { font-size: 1.05rem; margin: 1.6rem 0 .6rem; }

.view p { margin: .9rem 0; }

.view ul, .view ol { margin: .9rem 0; padding-left: 1.5rem; }
.view li { margin: .3rem 0; }
.view li > ul, .view li > ol { margin: .3rem 0; }

.view hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.view img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.view table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: .92em;
}
.view th, .view td {
  border: 1px solid var(--border);
  padding: .45rem .7rem;
  text-align: left;
}
.view th {
  background: var(--bg-alt);
  color: var(--heading);
  font-weight: 600;
}
.view tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-alt) 55%, transparent); }

.view blockquote {
  margin: 1.25rem 0;
  padding: .35rem 1.1rem;
  border-left: 3px solid var(--accent-2);
  background: var(--bg-alt);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-soft);
}

.view code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: var(--code-bg);
  border-radius: 4px;
  padding: .15em .35em;
}

.view pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 1.25rem 0;
  line-height: 1.5;
}
.view pre code {
  background: none;
  padding: 0;
  font-size: .85rem;
}

/* syntax highlight (lazy-loaded theme) */
.hljs { color: var(--text); }
.hljs-comment, .hljs-quote { color: var(--text-soft); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-meta { color: var(--accent); }
.hljs-string, .hljs-regexp, .hljs-addition { color: #47824a; }
[data-theme="dark"] .hljs-string, [data-theme="dark"] .hljs-regexp { color: #8fc98f; }
.hljs-number, .hljs-literal { color: var(--accent-2); }
.hljs-title, .hljs-section, .hljs-name, .hljs-built_in { color: #9a5a12; }
[data-theme="dark"] .hljs-title, [data-theme="dark"] .hljs-section, [data-theme="dark"] .hljs-built_in { color: #d9a45f; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: #3d6699; }
[data-theme="dark"] .hljs-attr, [data-theme="dark"] .hljs-variable { color: #8fb4e8; }
.hljs-deletion { color: #b32017; }

.view mark { background: var(--mark-bg); color: inherit; padding: 0 .15em; border-radius: 3px; }

.heading-anchor {
  opacity: 0;
  margin-left: .35rem;
  font-size: .7em;
  text-decoration: none;
  vertical-align: middle;
  transition: opacity .15s;
}
h1:hover > .heading-anchor,
h2:hover > .heading-anchor,
h3:hover > .heading-anchor,
h4:hover > .heading-anchor,
.heading-anchor:focus-visible { opacity: .55; }

/* ---------- course index (teaching) ---------- */

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0 2rem;
}

.course-card {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.course-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.course-card h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--heading);
}
.course-card.archived { opacity: .72; }
.course-card.archived:hover { opacity: 1; }

.badge {
  display: inline-block;
  align-self: flex-start;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .15rem .55rem;
  border-radius: 999px;
}
.badge.active   { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.badge.archived { background: var(--bg-alt); color: var(--text-soft); }

.course-banner {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: -0.5rem 0 1.25rem;
  font-size: .85rem;
  color: var(--text-soft);
}
.course-banner .badge { align-self: center; }

/* ---------- TOC ---------- */

.toc {
  position: sticky;
  top: calc(var(--header-h, 64px) + 1.5rem);
  max-height: calc(100vh - var(--header-h, 64px) - 3rem);
  overflow-y: auto;
  font-size: .85rem;
  line-height: 1.45;
  padding: .25rem 0 .25rem 1rem;
  border-left: 2px solid var(--border);
}
.toc-title {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin: 0 0 .5rem;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: .1rem 0; }
.toc a {
  display: block;
  padding: .15rem .4rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--text-soft);
  border-left: 2px solid transparent;
  margin-left: -12px; /* overlap the parent border */
}
.toc a:hover { color: var(--text); background: var(--bg-alt); }
.toc a.active {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}
.toc .lvl-3 { padding-left: 1rem; }

/* ---------- search ---------- */

.search-modal { position: fixed; inset: 0; z-index: 100; }
.search-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }

.search-dialog {
  position: relative;
  max-width: 640px;
  margin: 12vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#search-input {
  width: 100%;
  padding: 1rem 1.25rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1.05rem;
  font-family: var(--font);
}
#search-input:focus { outline: none; }
#search-input::placeholder { color: var(--text-soft); }

.search-results { max-height: 50vh; overflow-y: auto; padding: .4rem; }

.search-result {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: .6rem .8rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: .92rem;
  text-decoration: none;
}
.search-result:hover, .search-result.selected { background: var(--bg-alt); }
.search-result.selected { box-shadow: inset 2px 0 0 var(--accent); }
.search-result .sr-card { color: var(--text-soft); font-size: .78rem; }
.search-result .sr-heading { font-weight: 600; color: var(--heading); }
.search-result .sr-context {
  display: block;
  color: var(--text-soft);
  font-size: .82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-hint {
  margin: 0;
  padding: .6rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: .75rem;
}

/* ---------- misc ---------- */

.loading {
  color: var(--text-soft);
  font-style: italic;
  padding: 2rem 0;
}

.error-card {
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1rem 0;
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: .85rem;
}
.site-footer .page-inner { padding: 1.25rem; }

@media (max-width: 720px) {
  .site-subtitle { display: none; }
  .page-inner { padding-top: 1.25rem; }
  .view h1 { font-size: 1.55rem; }
}

@media print {
  .site-header, .site-footer, .toc-container, .search-modal, .heading-anchor, .skip-link { display: none !important; }
  body { font-size: 11pt; }
  .view pre, .view table, .view blockquote { break-inside: avoid; }
  a { color: inherit; text-decoration: underline; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}