@import url('https://fonts.googleapis.com/css2?family=Alegreya:wght@500;700;900&family=PT+Sans:wght@400;700&family=PT+Mono&display=swap');

:root {
  --paper: #e8e1ce;
  --paper-dark: #dbd0b3;
  --ink: #201d1a;
  --stamp-red: #9c2b26;
  --index-blue: #2a3f5f;
  --gold: #a8823c;
  --line: #6b5a3e;
  --card-bg: #f2ecdb;
  --flag-blue: #0057b7;
  --flag-yellow: #ffd700;
  --teal: #2f6f62;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, rgba(107,90,62,0.035) 0px, rgba(107,90,62,0.035) 1px, transparent 1px, transparent 26px);
  color: var(--ink);
  font-family: 'PT Sans', sans-serif;
  line-height: 1.55;
}

a { color: var(--index-blue); }

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 22px;
}

/* ---------- Drawer tab navigation ---------- */
nav.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ink);
  border-bottom: 4px solid var(--stamp-red);
}
nav.tabs .wrap {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding-top: 0;
  padding-bottom: 0;
}
nav.tabs a {
  flex: 0 0 auto;
  display: block;
  padding: 14px 16px;
  color: var(--paper);
  text-decoration: none;
  font-family: 'PT Mono', monospace;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-right: 1px solid rgba(232,225,206,0.15);
  white-space: nowrap;
}
nav.tabs a:hover { background: var(--stamp-red); color: var(--paper); }

/* ---------- Header / masthead ---------- */
header.masthead {
  padding: 46px 0 26px;
  border-bottom: 3px solid var(--ink);
  position: relative;
  overflow: hidden;
  background-image:
    linear-gradient(100deg, var(--paper) 35%, rgba(232,225,206,0.55) 65%, rgba(232,225,206,0.15) 100%),
    url('assets/Flag_map_of_Ukraine.svg.webp');
  background-repeat: no-repeat;
  background-position: left top, right 12px top 12px;
  background-size: 100% 100%, 210px auto;
}

.flag-ribbon {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: linear-gradient(90deg, var(--flag-blue) 0%, var(--flag-blue) 50%, var(--flag-yellow) 50%, var(--flag-yellow) 100%);
}

/* ---------- Vyshyvanka stitch divider ---------- */
.stitch-divider {
  height: 14px;
  background-image:
    repeating-linear-gradient(45deg, var(--stamp-red) 0, var(--stamp-red) 4px, transparent 4px, transparent 8px),
    repeating-linear-gradient(-45deg, var(--flag-blue) 0, var(--flag-blue) 4px, transparent 4px, transparent 8px);
  background-position: 0 0, 0 7px;
  background-size: 100% 7px, 100% 7px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  opacity: 0.85;
}

header.masthead .wrap { position: relative; z-index: 2; }
header.masthead .kicker {
  font-family: 'PT Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--index-blue);
}
header.masthead h1 {
  font-family: 'Alegreya', serif;
  font-weight: 900;
  font-size: clamp(32px, 6vw, 52px);
  margin: 6px 0 0;
  line-height: 1.05;
}

/* ---------- Section shell ---------- */
section { padding: 46px 0; }
section h2 {
  font-family: 'Alegreya', serif;
  font-weight: 700;
  font-size: 28px;
  margin: 0 0 4px;
  display: inline-block;
  border-bottom: 3px solid var(--stamp-red);
  padding-bottom: 4px;
}
section .section-num {
  font-family: 'PT Mono', monospace;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 0.1em;
}

/* ---------- Library card (hero) ---------- */
.card {
  background: var(--card-bg);
  border: 2px solid var(--ink);
  padding: 26px 28px;
  position: relative;
  box-shadow: 6px 6px 0 rgba(32,29,26,0.12);
}
.card + .card { margin-top: 18px; }

.stamp {
  position: absolute;
  top: 18px;
  right: 22px;
  border: 3px solid var(--stamp-red);
  color: var(--stamp-red);
  font-family: 'PT Mono', monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
  padding: 5px 10px;
  transform: rotate(8deg);
  border-radius: 2px;
  opacity: 0.9;
  background: rgba(156,43,38,0.04);
}

.card .meta-row {
  font-family: 'PT Mono', monospace;
  font-size: 12px;
  color: var(--line);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
.card h3 {
  font-family: 'Alegreya', serif;
  font-size: 24px;
  margin: 0 0 6px;
}
.card .subtitle { color: var(--index-blue); font-weight: 700; margin: 0 0 12px; }

/* ---------- Quiz ---------- */
.quiz-q { margin-bottom: 22px; }
.quiz-q p.q-text { font-weight: 700; margin: 0 0 8px; }
.quiz-q .opt {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card-bg);
  border: 1.5px solid var(--line);
  padding: 10px 14px;
  margin-bottom: 6px;
  cursor: pointer;
  font-family: 'PT Sans', sans-serif;
  font-size: 15px;
  color: var(--ink);
}
.quiz-q .opt:hover { border-color: var(--index-blue); }
.quiz-q .opt.correct { background: #dfe8d6; border-color: #4c7a3f; }
.quiz-q .opt.wrong { background: #ecd7d4; border-color: var(--stamp-red); }
.quiz-q .opt[disabled] { cursor: default; }

#quiz-result {
  font-family: 'PT Mono', monospace;
  font-size: 15px;
  margin-top: 16px;
  padding: 12px 16px;
  border: 2px dashed var(--line);
  display: none;
}
button.reset-btn {
  font-family: 'PT Mono', monospace;
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 12px;
}

/* ---------- Archive list ---------- */
.archive-item {
  display: flex;
  gap: 16px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.archive-item .num {
  font-family: 'PT Mono', monospace;
  color: var(--gold);
  font-size: 13px;
  flex: 0 0 60px;
}
.archive-item .date {
  font-family: 'PT Mono', monospace;
  font-size: 12px;
  color: var(--line);
  flex: 0 0 90px;
}
.archive-item a { font-weight: 700; text-decoration: none; }
.archive-item a:hover { text-decoration: underline; }

/* ---------- Leaderboard ---------- */
table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-family: 'PT Mono', monospace;
  font-size: 13px;
  background: var(--card-bg);
  border: 2px solid var(--ink);
}
table.ledger th, table.ledger td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: center;
}
table.ledger th {
  background: var(--ink);
  color: var(--paper);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
}
table.ledger td:first-child, table.ledger th:first-child { text-align: left; }
table.ledger tr.total td { font-weight: 700; background: #ded2ad; }

/* ---------- Materials ---------- */
.materials-group { margin-bottom: 26px; }
.materials-group h3 {
  font-family: 'PT Mono', monospace;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--index-blue);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.materials-group ul { padding-left: 0; list-style: none; }
.materials-group li { padding: 7px 0; border-bottom: 1px dotted var(--line); }
.materials-group li:before { content: "→ "; color: var(--stamp-red); }

/* ---------- Statistics ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--card-bg);
  border: 2px solid var(--ink);
  padding: 18px 14px;
  text-align: center;
  box-shadow: 4px 4px 0 rgba(32,29,26,0.1);
}
.stat-value {
  font-family: 'Alegreya', serif;
  font-weight: 900;
  font-size: 34px;
  color: var(--flag-blue);
  line-height: 1;
}
.stat-label {
  font-family: 'PT Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--line);
  margin-top: 8px;
}

/* ---------- Figures carousel ---------- */
.section-lead { color: var(--line); margin-top: -4px; }
.carousel {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}
.carousel-track {
  position: relative;
  flex: 1;
  min-height: 240px;
}
.figure-card {
  display: none;
  background: var(--card-bg);
  border: 2px solid var(--ink);
  border-top-width: 6px;
  padding: 24px 26px;
  box-shadow: 6px 6px 0 rgba(32,29,26,0.12);
  text-align: center;
}
.figure-card.active { display: block; }
.figure-card.accent-blue { border-top-color: var(--flag-blue); }
.figure-card.accent-yellow { border-top-color: var(--flag-yellow); }
.figure-card.accent-terracotta { border-top-color: var(--stamp-red); }
.figure-card.accent-teal { border-top-color: var(--teal); }

.figure-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Alegreya', serif;
  font-weight: 900;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(135deg, var(--flag-blue), var(--teal));
}
.figure-card.accent-yellow .figure-avatar { background: linear-gradient(135deg, var(--gold), var(--flag-yellow)); color: var(--ink); }
.figure-card.accent-terracotta .figure-avatar { background: linear-gradient(135deg, var(--stamp-red), var(--gold)); }
.figure-card.accent-teal .figure-avatar { background: linear-gradient(135deg, var(--teal), var(--flag-blue)); }

.figure-card h3 { font-family: 'Alegreya', serif; font-size: 22px; margin: 0 0 4px; }
.figure-years {
  font-family: 'PT Mono', monospace;
  font-size: 12px;
  color: var(--line);
  margin-bottom: 12px;
}
.figure-note { margin: 0 0 8px; }
.figure-quote {
  font-style: italic;
  color: var(--index-blue);
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  margin-top: 10px;
}

.carousel-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.carousel-btn:hover { background: var(--stamp-red); }

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.dot.active { background: var(--flag-blue); border-color: var(--flag-blue); }

/* ---------- Footer ---------- */
footer {
  border-top: 3px solid var(--ink);
  padding: 22px 0 40px;
  font-family: 'PT Mono', monospace;
  font-size: 12px;
  color: var(--line);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .card { box-shadow: 4px 4px 0 rgba(32,29,26,0.12); }
  .stamp { position: static; display: inline-block; margin-bottom: 10px; transform: rotate(-3deg); }
  .archive-item { flex-wrap: wrap; }
  .map-watermark { width: 85%; opacity: 0.07; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .carousel-btn { width: 34px; height: 34px; font-size: 17px; }
}
