:root {
  --bg: #fbfaf7;
  --fg: #1c1b19;
  --muted: #6b6760;
  --line: #e4e0d8;
  --accent: #1f5fa8;
  --panel: #f3f1ec;
  --side: 210px;
  --top: 52px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #141413;
  --fg: #e8e6e1;
  --muted: #9a958c;
  --line: #2c2b28;
  --accent: #7fb0e8;
  --panel: #1b1b19;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --fg: #e8e6e1;
    --muted: #9a958c;
    --line: #2c2b28;
    --accent: #7fb0e8;
    --panel: #1b1b19;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.6 Charter, "Iowan Old Style", Georgia, "Noto Serif", serif;
}

button {
  font: inherit;
  color: var(--fg);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  width: 36px;
  height: 36px;
}

/* верхня смуга: місце під майбутнє + перемикач теми */
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.reserved { flex: 1; }
.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--fg);
  text-decoration: none;
}

/* «Як читати дайджест»: <details>, без JS */
.howto { position: static; font: 14px/1.4 system-ui, sans-serif; }
.howto summary {
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
}
.howto summary::-webkit-details-marker { display: none; }
.howto summary:hover, .howto[open] summary { background: var(--panel); color: var(--fg); }
.howto-panel {
  position: absolute;
  top: var(--top);
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, 100vw);
  max-height: calc(100vh - var(--top) - 16px);
  overflow-y: auto;
  padding: 16px 24px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.15);
  font: 16px/1.6 Charter, "Iowan Old Style", Georgia, "Noto Serif", serif;
}
.legend p { margin: 0 0 10px; }

/* бейджі біля джерел */
.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 4px;
  font: 600 11px/18px system-ui, sans-serif;
  vertical-align: 1px;
  text-decoration: none !important;
  color: #fff !important;
}
.badge-state_controlled { background: #b3261e; }
.badge-state_agency { background: #8a5a00; }
.badge-state_funded { background: #b8650a; }
.badge-public_broadcaster { background: #2e6b4f; }
.badge-contrarian { background: #6b4fa0; }

/* футер під дайджестом */
.center { min-width: 0; }
.footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 24px 48px;
  border-top: 1px solid var(--line);
  font: 13px/1.8 system-ui, sans-serif;
  color: var(--muted);
}
.footer p { margin: 0 0 6px; }
.footer a { color: var(--accent); }


/* /about/sources */
.about { max-width: 960px; }
.about table { width: 100%; border-collapse: collapse; font: 14px/1.5 system-ui, sans-serif; }
.about th, .about td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.about th { position: sticky; top: var(--top); background: var(--bg); }
.about .badge-defs dt { margin-top: 12px; }
.about .badge-defs dd { margin: 4px 0 0; color: var(--muted); }
.about .table-wrap { overflow-x: auto; }
.days-toggle { display: none; }

/* три колонки: дні | новини | порожньо (дзеркало лівої) */
.layout {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr) var(--side);
}

.days {
  position: sticky;
  top: var(--top);
  height: calc(100vh - var(--top));
  overflow-y: auto;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  font-family: system-ui, sans-serif;
  font-size: 14px;
}
.days ul { list-style: none; margin: 0; padding: 0; }
.days a {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
}
.days a:hover { background: var(--panel); }
.days a[aria-current="page"] { background: var(--panel); font-weight: 600; }
.days .count { color: var(--muted); }
.days .rss { display: inline-block; margin: 16px 10px 0; color: var(--muted); }

.right { border-left: 1px solid var(--line); }

main {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 40px;
}

.day-title {
  font: 600 14px/1 system-ui, sans-serif;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  margin: 8px 0 8px;
}

/* розділи: колір задає клас .sec-<key> (key — section_key у config/topics.yaml) */
.sec-ukraine { --sec: #2f6bc4; }
.sec-geo     { --sec: #12807a; }
.sec-tech    { --sec: #b03a78; }
:root[data-theme="dark"] .sec-ukraine { --sec: #6fa3f0; }
:root[data-theme="dark"] .sec-geo     { --sec: #4cc2b8; }
:root[data-theme="dark"] .sec-tech    { --sec: #e57bb4; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sec-ukraine { --sec: #6fa3f0; }
  :root:not([data-theme="light"]) .sec-geo     { --sec: #4cc2b8; }
  :root:not([data-theme="light"]) .sec-tech    { --sec: #e57bb4; }
}

h2.section {
  text-align: center;
  font-size: 26px;
  color: var(--sec);
  margin: 48px 0 8px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--sec);
}

/* маркер розділу на початку заголовка сюжету */
article h3::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 10px;
  border-radius: 2px;
  background: var(--sec, var(--muted));
  vertical-align: 2px;
}

article { padding: 20px 0; border-bottom: 1px solid var(--line); }
article:last-child { border-bottom: none; }
article h3 { font-size: 21px; line-height: 1.3; margin: 0 0 10px; }
article p { margin: 0 0 10px; }
article .framing {
  font-style: italic;
  color: var(--muted);
  border-left: 3px solid var(--line);
  padding-left: 12px;
}
article .sources {
  font: 14px/1.7 system-ui, sans-serif;
  color: var(--muted);
}
article .sources a { color: var(--accent); text-decoration: none; }
article .sources a:hover { text-decoration: underline; }
article:target h3 { color: var(--accent); }

.loading, .empty { color: var(--muted); text-align: center; margin-top: 64px; }

/* планшет: права колонка зникає */
@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--side) minmax(0, 1fr); }
  .right { display: none; }
}

/* телефон: дні — висувна панель */
@media (max-width: 760px) {
  html, body { font-size: 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .days-toggle { display: block; }
  .days {
    position: fixed;
    left: 0;
    top: var(--top);
    width: 240px;
    background: var(--bg);
    z-index: 3;
    transform: translateX(-100%);
    transition: transform .2s;
  }
  .days.open { transform: none; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  main { padding: 16px 16px 64px; }
  h2.section { font-size: 22px; margin-top: 36px; }
  .brand { display: none; }
  .howto-panel { left: 0; transform: none; width: 100vw; border-radius: 0; }
  .footer { padding: 16px 16px 40px; }
  article h3 { font-size: 19px; }
}

/* значок перемикача: у світлій темі — місяць, у темній — сонце */
.theme-toggle::before { content: "☾"; font-size: 18px; }
:root[data-theme="dark"] .theme-toggle::before { content: "☀"; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle::before { content: "☀"; }
}

/* якір на сюжет не ховається під липкою шапкою */
article { scroll-margin-top: calc(var(--top) + 12px); }

.i-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 6px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font: 700 11px/13px Georgia, serif;
  font-style: italic;
  text-align: center;
  vertical-align: -3px;
}

/* легенда бейджів у шапці */
.badges-menu { position: relative; }
.badges-toggle {
  width: auto;
  height: auto;
  padding: 6px 10px;
  border: none;
  color: var(--muted);
  font: 14px/1.4 system-ui, sans-serif;
}
.badges-toggle:hover, .badges-toggle[aria-expanded="true"] { background: var(--panel); color: var(--fg); }
.badges-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 4;
  width: 300px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.15);
  font: 14px/1.4 system-ui, sans-serif;
}
.badges-panel p { margin: 0 0 8px; }
.badges-panel .badge { margin: 0 6px 0 0; }
.badges-panel .more { margin: 10px 0 0; }
.badges-panel .more a { color: var(--accent); }

/* зміст дня */
.toc {
  margin: 8px 0 24px;
  padding: 12px 0 16px;
  border-bottom: 3px double var(--line);
  font: 14px/1.4 system-ui, sans-serif;
}
.toc ul { list-style: none; margin: 0 0 16px; padding: 0; }
.toc li { position: relative; padding-left: 18px; }
.toc li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: .42em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sec, var(--muted));
}
.toc ul:last-child { margin-bottom: 0; }
.toc-section {
  margin: 0 0 8px;
  color: var(--sec);
  font: 700 20px/1.3 Charter, "Iowan Old Style", Georgia, "Noto Serif", serif;
}
.toc li { margin: 0 0 6px; }
.toc a { color: var(--sec, var(--fg)); text-decoration: none; }
.toc a:hover { text-decoration: underline; }

@media (max-width: 760px) {
  .badges-panel { position: fixed; top: var(--top); left: 0; width: 100vw; border-radius: 0; }
}

/* неповний день (дозібраний пізніше з того, що лишилось у фідах) */
.partial-note {
  margin: 0 0 16px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font: 13px/1.5 system-ui, sans-serif;
  text-align: center;
}
.partial-mark { color: var(--muted); }

.header-link {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font: 14px/1.4 system-ui, sans-serif;
}
.header-link:hover { background: var(--panel); color: var(--fg); }
@media (max-width: 900px) { .header-link { display: none; } }
