/* ==========================================================================
   theMatura
   Dvije teme s istom idejom:
     ploča  (tamna, zadana)  — školska ploča, kreda, napola obrisane formule
     papir  (svijetla)       — ispitni papir, tinta, flomaster
   ========================================================================== */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a2320;
  --bg-deep: #141b18;
  --ink: #ebe7da;          /* kreda */
  --ink-2: #c3c2b6;
  --muted: #8f9a93;
  --rule: rgba(235, 231, 218, 0.14);
  --rule-strong: rgba(235, 231, 218, 0.28);
  --mark: #f0d36a;         /* žuta kreda */
  --mark-ink: #1a2320;     /* tekst na žutom */
  --link: #f0d36a;
  --note: #9fc8dc;         /* plava kreda za bilješke */
  --row-hover: rgba(235, 231, 218, 0.045);
  --ghost: rgba(235, 231, 218, 0.075);
  --smudge: rgba(235, 231, 218, 0.035);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 -.18'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --grain-opacity: 0.5;
  --paper: #f3eedf;
  --paper-ink: #232a45;
  --tape: rgba(240, 211, 106, 0.55);
  --logo-mark: #f0d36a;
  --header-bg: rgba(26, 35, 32, 0.86);
  --chalk-filter: url(#chalk);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f0e6;
  --bg-deep: #ebe5d6;
  --ink: #1f2440;          /* tinta */
  --ink-2: #3c425c;
  --muted: #6b6f80;
  --rule: rgba(31, 36, 64, 0.14);
  --rule-strong: rgba(31, 36, 64, 0.3);
  --mark: #ffe15a;         /* flomaster */
  --mark-ink: #1f2440;
  --link: #2c45b0;         /* plava kemijska */
  --note: #2c45b0;
  --row-hover: rgba(255, 225, 90, 0.22);
  --ghost: rgba(58, 62, 84, 0.2);   /* trag olovke */
  --smudge: rgba(31, 36, 64, 0);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .2 0 0 0 .5 -.15'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --grain-opacity: 0.35;
  --paper: #fffdf6;
  --paper-ink: #1f2440;
  --tape: rgba(200, 190, 160, 0.5);
  --logo-mark: #2c45b0;
  --header-bg: rgba(244, 240, 230, 0.9);
  --chalk-filter: none;
}

/* ---------- Base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Source Sans 3", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Papir: diskretne kockice kao u bilježnici */
:root[data-theme="light"] body {
  background-image:
    linear-gradient(rgba(44, 69, 176, 0.075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 69, 176, 0.075) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -1px -1px;
}

/* Zrno ploče/papira + tragovi brisanja spužvom */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
body::before {
  background:
    radial-gradient(38% 22% at 18% 30%, var(--smudge), transparent 70%),
    radial-gradient(30% 26% at 82% 18%, var(--smudge), transparent 70%),
    radial-gradient(44% 20% at 60% 78%, var(--smudge), transparent 70%),
    radial-gradient(120% 90% at 50% 40%, transparent 55%, var(--bg-deep) 100%);
}
body::after {
  background-image: var(--grain);
  opacity: var(--grain-opacity);
}

h1, h2, h3 {
  margin: 0;
  font-family: "STIX Two Text", "Iowan Old Style", Georgia, serif;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.01em;
}
p { margin: 0; }
a { color: inherit; }
svg { display: block; }
button { font: inherit; color: inherit; }
.num { font-family: "STIX Two Text", Georgia, serif; font-variant-numeric: lining-nums; }

::selection { background: var(--mark); color: var(--mark-ink); }

:focus-visible { outline: 2px dashed var(--mark); outline-offset: 4px; }

.wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}
@media (min-width: 720px) { .wrap { padding: 0 32px; } }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 16px; top: -60px; z-index: 100;
  padding: 8px 14px; background: var(--mark); color: var(--mark-ink);
  font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* Ručno crtane linije: crtaju se kad se pojave */
.draw path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.9s cubic-bezier(0.6, 0.1, 0.3, 1) forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.site-header.scrolled { border-bottom-color: var(--rule); }

.header-inner {
  display: flex;
  align-items: center;
  gap: 8px 20px;
  min-height: 64px;
}
.brand { display: inline-flex; color: var(--ink); text-decoration: none; }
.logo { height: 28px; width: auto; aspect-ratio: 370 / 92; }

.nav { display: flex; gap: 22px; margin-left: auto; }
.nav a {
  position: relative;
  padding: 6px 0;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 16px;
}
.nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  height: 2px;
  background: var(--mark);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}
.nav a:hover { color: var(--ink); }
.nav a:hover::after { transform: scaleX(1); }

.theme-switch {
  display: flex;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  font-family: "Caveat", cursive;
  font-size: 19px;
  line-height: 1;
}
.theme-switch button {
  padding: 5px 9px 6px;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.theme-switch button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

@media (max-width: 640px) {
  .header-inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 8px; }
  .logo { height: 22px; }
  .theme-switch { margin-left: auto; }
  .nav { order: 3; width: 100%; margin: 0; gap: 18px; font-size: 15px; }
  .nav a { font-size: 15px; }
  .nav .nav-about { margin-left: auto; }
}

/* ---------- Hero ---------- */

.hero {
  position: relative;
  padding: 72px 0 64px;
  overflow: hidden;
}
@media (min-width: 960px) { .hero { padding: 104px 0 96px; } }

/* Napola obrisane formule umjesto mreže */
.ghosts span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: rotate(var(--r));
  font-family: "Caveat", cursive;
  font-size: clamp(26px, 3.4vw, 40px);
  color: var(--ghost);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  filter: blur(0.4px);
}
:root[data-theme="light"] .ghosts span {
  filter: none;
  font-weight: 500;
}
@media (max-width: 720px) { .ghosts .g-wide { display: none; } }

.hero-inner {
  position: relative;
  display: grid;
  gap: 56px;
  align-items: start;
}
@media (min-width: 960px) {
  .hero-inner { grid-template-columns: minmax(0, 1fr) 280px; gap: 64px; }
}

.margin-note {
  position: relative;
  display: inline-block;
  margin-bottom: 14px;
  font-family: "Caveat", cursive;
  font-size: 25px;
  line-height: 1;
  color: var(--note);
  transform: rotate(-3deg);
  transform-origin: left;
}
.note-arrow {
  position: absolute;
  left: calc(100% + 4px);
  top: 4px;
  width: 64px;
  height: 46px;
  color: var(--note);
  filter: var(--chalk-filter);
}
.note-arrow path { stroke-width: 2.4; animation-delay: 0.9s; }
@media (max-width: 520px) { .note-arrow { display: none; } }

.hero h1 {
  max-width: 17ch;
  font-size: clamp(2.7rem, 8.4vw, 5.4rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 0.98;
}

.nowrap { white-space: nowrap; }
.circled { position: relative; display: inline-block; font-style: italic; }
.circled svg {
  position: absolute;
  left: -7%;
  top: -12%;
  width: 116%;
  height: 128%;
  color: var(--mark);
  overflow: visible;
  filter: var(--chalk-filter);
  pointer-events: none;
}
.circled path { stroke-width: 3; vector-effect: non-scaling-stroke; animation-delay: 0.35s; animation-duration: 1.1s; }

.lead {
  margin-top: 28px;
  max-width: 33rem;
  font-size: clamp(1.1rem, 2.3vw, 1.3rem);
  line-height: 1.55;
  color: var(--ink-2);
}

/* Statistika kao račun: 35 + 25 = 60 */
.equation {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-top: 40px;
  font-family: "STIX Two Text", Georgia, serif;
}
.equation .term { display: flex; flex-direction: column; align-items: center; }
.equation b {
  font-weight: 400;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  line-height: 1;
  font-variant-numeric: lining-nums;
}
.equation i {
  position: relative;
  margin-top: 12px;
  padding-top: 6px;
  font-family: "Caveat", cursive;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
}
/* vitičasta zagrada ispod broja */
.equation i::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -6px;
  width: 44px;
  height: 9px;
  transform: translateX(-50%);
  border: 1.5px solid var(--rule-strong);
  border-top: 0;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.equation .op {
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 1.1;
  color: var(--muted);
}
.equation .term:last-child b { color: var(--mark); }
:root[data-theme="light"] .equation .term:last-child b {
  color: var(--ink);
  background: linear-gradient(transparent 58%, var(--mark) 58%, var(--mark) 92%, transparent 92%);
  padding: 0 4px;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; margin-top: 44px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 0 22px;
  border: 1.5px solid var(--mark);
  border-radius: 3px;
  background: var(--mark);
  color: var(--mark-ink);
  font-weight: 600;
  font-size: 16.5px;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: 3px 3px 0 var(--ink); }
.btn:active { transform: none; box-shadow: none; }
.btn-line {
  background: transparent;
  border-color: var(--rule-strong);
  color: var(--ink);
}
.btn-line:hover { border-color: var(--ink); box-shadow: 3px 3px 0 var(--rule-strong); }

/* Zalijepljena cedulja s novostima */
.pinned {
  position: relative;
  padding: 26px 22px 20px;
  background: var(--paper);
  color: var(--paper-ink);
  transform: rotate(1.8deg);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12), 0 12px 24px -12px rgba(0, 0, 0, 0.45);
  margin-top: 8px;
  max-width: 340px;
}
@media (min-width: 960px) { .pinned { margin-top: 64px; } }
.tape {
  position: absolute;
  top: -12px;
  left: 50%;
  width: 96px;
  height: 26px;
  transform: translateX(-50%) rotate(-4deg);
  background: var(--tape);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}
.pinned-title {
  font-family: "Caveat", cursive;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}
.pinned-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  background-image: repeating-linear-gradient(transparent 0 33px, rgba(44, 69, 176, 0.16) 33px 34px);
}
.pinned-list a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  height: 34px;
  padding-top: 6px;
  text-decoration: none;
  font-size: 16px;
  line-height: 24px;
}
.pinned-list .p-lvl {
  font-family: "STIX Two Text", serif;
  font-style: italic;
  font-weight: 600;
  min-width: 18px;
}
.pinned-list .p-arrow { margin-left: auto; opacity: 0.5; transition: transform 0.15s ease, opacity 0.15s ease; }
.pinned-list a:hover { text-decoration: underline; text-decoration-color: rgba(44, 69, 176, 0.5); text-underline-offset: 4px; }
.pinned-list a:hover .p-arrow { opacity: 1; transform: translateX(3px); }

/* ---------- Arhiva ---------- */

.archive { padding: 40px 0 72px; }
@media (min-width: 960px) { .archive { padding: 56px 0 104px; } }

.archive-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px 40px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--ink);
}
.archive h2 { font-size: clamp(2.2rem, 5.5vw, 3.4rem); }

.level-tabs { display: flex; gap: 26px; }
.level-tabs button {
  position: relative;
  padding: 4px 0 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: "STIX Two Text", Georgia, serif;
  font-size: clamp(1.1rem, 2.6vw, 1.35rem);
  cursor: pointer;
  transition: color 0.15s ease;
}
.level-tabs button:hover { color: var(--ink-2); }
.level-tabs .lvl { font-style: italic; font-weight: 600; }
.level-tabs svg {
  position: absolute;
  left: -4px;
  right: -4px;
  bottom: 0;
  width: calc(100% + 8px);
  height: 10px;
  color: var(--mark);
  overflow: visible;
  filter: var(--chalk-filter);
  visibility: hidden;
}
.level-tabs path { stroke-width: 3; vector-effect: non-scaling-stroke; }
.level-tabs [aria-selected="true"] { color: var(--ink); }
.level-tabs [aria-selected="true"] svg { visibility: visible; }
.level-tabs [aria-selected="true"] svg path { animation: draw 0.5s ease forwards; stroke-dasharray: 1; stroke-dashoffset: 1; fill: none; stroke: currentColor; stroke-linecap: round; }

.exam-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16.5px;
}
.exam-table th {
  padding: 18px 12px 10px;
  text-align: left;
  font-family: "Caveat", cursive;
  font-weight: 500;
  font-size: 21px;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
}
.exam-table th:first-child { padding-left: 0; }
.exam-table td {
  padding: 0 12px;
  height: 58px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.exam-table td:first-child { padding-left: 0; width: 34%; }
.exam-table tbody tr { transition: background-color 0.15s ease; animation: row-in 0.35s ease both; }
.exam-table tbody tr:hover { background: var(--row-hover); }
@keyframes row-in { from { opacity: 0; transform: translateY(4px); } }

.year {
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.45rem;
  font-variant-numeric: lining-nums;
}
.year small { font-size: 0.72em; color: var(--muted); }
.new {
  display: inline-block;
  margin-left: 10px;
  font-family: "Caveat", cursive;
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  color: var(--mark);
  transform: rotate(-6deg) translateY(-2px);
}
:root[data-theme="light"] .new { color: var(--link); }

.pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 5px;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}
.pdf-link .arr { font-size: 0.9em; color: var(--muted); transition: transform 0.15s ease, color 0.15s ease; }
.pdf-link:hover { color: var(--link); text-decoration-color: currentColor; }
.pdf-link:hover .arr { color: currentColor; transform: translate(2px, -2px); }
.pdf-link .lbl-m { display: none; }
.none { color: var(--rule-strong); }

/* Mobitel: svaki red postaje mali blok */
@media (max-width: 640px) {
  .exam-table thead { display: none; }
  .exam-table, .exam-table tbody, .exam-table tr, .exam-table td { display: block; }
  .exam-table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 20px;
    padding: 14px 0 12px;
    border-bottom: 1px solid var(--rule);
  }
  .exam-table td { height: auto; padding: 0; border: 0; width: auto !important; }
  .exam-table td:first-child { width: 100% !important; margin-bottom: 2px; }
  .exam-table td.empty { display: none; }
  .pdf-link .lbl-m { display: inline; }
  .pdf-link .lbl-d { display: none; }
  .pdf-link .arr { display: none; }
}

.aside-note {
  margin-top: 22px;
  font-family: "Caveat", cursive;
  font-size: 23px;
  color: var(--muted);
  transform: rotate(-1deg);
}
.aside-note a { color: var(--note); }

/* ---------- O nama ---------- */

.about { padding: 72px 0 88px; border-top: 1px solid var(--rule); }

.about-inner { display: grid; gap: 56px; }
@media (min-width: 960px) { .about-inner { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 96px; } }

.letter h2 { font-size: clamp(2.2rem, 5.5vw, 3.4rem); margin-bottom: 26px; }
.letter p:not(.signature):not(.ps) {
  max-width: 36rem;
  margin-top: 14px;
  font-size: 1.12rem;
  color: var(--ink-2);
}
.letter em { font-family: "STIX Two Text", serif; color: var(--ink); }
.signature {
  margin-top: 26px;
  font-family: "Caveat", cursive;
  font-size: 32px;
  line-height: 1.1;
  color: var(--ink);
  transform: rotate(-2deg);
  transform-origin: left;
}
.ps { margin-top: 22px; color: var(--muted); font-size: 0.98rem; }
.ps span { font-family: "Caveat", cursive; font-size: 22px; color: var(--note); margin-right: 4px; }

.contact { align-self: center; }
.contact-label { font-family: "Caveat", cursive; font-size: 25px; line-height: 1.15; color: var(--note); }
.email {
  display: inline-block;
  margin-top: 14px;
  font-family: "STIX Two Text", Georgia, serif;
  font-size: clamp(1.45rem, 4.6vw, 2.3rem);
  line-height: 1.2;
  text-decoration: none;
  word-break: break-all;
  background: linear-gradient(var(--mark), var(--mark)) no-repeat 0 100% / 100% 3px;
  padding-bottom: 4px;
  transition: background-size 0.25s ease, color 0.25s ease;
}
.email:hover { background-size: 100% 100%; color: var(--mark-ink); }
.copy-btn {
  display: block;
  margin-top: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
.copy-btn:hover { color: var(--ink); }

/* ---------- Footer ---------- */

.site-footer { padding: 32px 0 44px; border-top: 2px solid var(--ink); }
.footer-inner { display: grid; gap: 16px; }
@media (min-width: 860px) { .footer-inner { grid-template-columns: auto 1fr auto; align-items: center; gap: 48px; } }
.site-footer .logo { height: 22px; }
.disclaimer, .copyright { color: var(--muted); font-size: 14px; }
.disclaimer { max-width: 36rem; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  padding: 8px 16px 10px;
  background: var(--paper);
  color: var(--paper-ink);
  font-family: "Caveat", cursive;
  font-size: 22px;
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 16px) rotate(-1deg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) rotate(-1deg); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .draw path, .level-tabs path { stroke-dashoffset: 0 !important; }
}
