/* ============================================================
   История континентов — styles (minimal editorial)
   UI: system sans · Reading: Lora · Display numerals: Playfair
   ============================================================ */

:root {
  --font-read: "Lora", Georgia, "Times New Roman", serif;
  --font-ui: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* light surfaces */
  --paper: #f7f3ec;
  --paper-2: #fdfbf6;
  --ink: #201d18;
  --ink-soft: #5f594e;
  --ink-faint: #9a9384;
  --line: rgba(32, 29, 23, 0.10);
  --line-2: rgba(32, 29, 23, 0.16);

  /* map */
  --land: #e8dfce;
  --land-hover: #ddd2bd;
  --map-line: rgba(32, 29, 23, 0.13);
  --label-ink: #2a261f;
  --label-bg: rgba(247, 243, 236, 0.72);

  /* era accent (muted; overridden by [data-era]) */
  --accent: #a86a4a;
  --accent-ink: #fff;

  --maxw: 1120px;
  --read: 47rem;
  --radius: 8px;
}

[data-era="antiquity"]   { --accent:#a86a4a; }
[data-era="medieval"]    { --accent:#9c5a61; }
[data-era="renaissance"] { --accent:#3f867a; }
[data-era="industrial"]  { --accent:#5b748f; }
[data-era="modern"]      { --accent:#5b66b8; }

[data-theme="dark"] {
  --paper: #14151a;
  --paper-2: #1a1c22;
  --ink: #ece7dd;
  --ink-soft: #aaa498;
  --ink-faint: #757066;
  --line: rgba(255, 255, 255, 0.10);
  --line-2: rgba(255, 255, 255, 0.18);

  --land: #23262e;
  --land-hover: #2c3038;
  --map-line: rgba(255, 255, 255, 0.08);
  --label-ink: #e7e2d8;
  --label-bg: rgba(20, 21, 26, 0.6);
}
[data-theme="dark"][data-era="antiquity"]   { --accent:#c5896a; }
[data-theme="dark"][data-era="medieval"]    { --accent:#bd7d84; }
[data-theme="dark"][data-era="renaissance"] { --accent:#5aa99b; }
[data-theme="dark"][data-era="industrial"]  { --accent:#82a0bd; }
[data-theme="dark"][data-era="modern"]      { --accent:#8b95e0; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-read);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.72;
  font-size: 1.06rem;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .35s ease, color .25s ease;
}

a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ============================================================ TOPBAR */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px clamp(18px, 5vw, 48px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 9px; height: 9px; flex: none; border-radius: 50%;
  background: var(--accent); transition: background .35s ease;
}
.brand-mark::after { content: none; }
.brand-text {
  font-family: var(--font-ui); font-weight: 600; font-size: .92rem; letter-spacing: .01em;
  color: var(--ink-soft);
}
.icon-btn {
  width: 34px; height: 34px; flex: none; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line-2); background: transparent; color: var(--ink);
  display: grid; place-items: center; transition: border-color .2s, transform .15s;
}
.icon-btn:hover { border-color: var(--ink-soft); }
.icon-btn:active { transform: scale(.92); }
.theme-icon {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--ink-soft);
  background:
    linear-gradient(90deg, var(--ink-soft) 0 50%, transparent 50% 100%);
}
[data-theme="dark"] .theme-icon { background: none; box-shadow: inset -4px -2px 0 0 var(--ink-soft); border-color: transparent; }

/* ============================================================ MAP */
#map-stage {
  padding: clamp(10px, 2vw, 20px) clamp(10px, 4vw, 40px);
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.map-frame { position: relative; max-width: 860px; margin: 0 auto; }
#worldmap { display: block; width: 100%; height: auto; max-height: min(34vh, 300px); overflow: visible; }
.continent {
  fill: var(--land); stroke: var(--map-line); stroke-width: .8; stroke-linejoin: round;
  cursor: pointer; transition: fill .25s ease, opacity .25s ease;
}
.continent:hover { fill: var(--land-hover); }
#worldmap.has-selection .continent { opacity: .5; }
#worldmap.has-selection .continent:hover { opacity: .8; }
.continent.selected { fill: var(--accent); stroke: transparent; opacity: 1 !important; }

/* no selection box on click; keyboard focus still gets a clean indicator */
:focus:not(:focus-visible) { outline: none; }
.continent:focus { outline: none; }
.continent:focus-visible { outline: none; stroke: var(--accent); stroke-width: 1.6; }
.map-label:focus:not(:focus-visible) { outline: none; }
.map-label:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.map-labels { position: absolute; inset: 0; pointer-events: none; }
.map-label {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer;
  font-family: var(--font-ui); font-size: clamp(.6rem, 1.3vw, .76rem); font-weight: 500;
  letter-spacing: .01em; white-space: nowrap; color: var(--label-ink);
  padding: 2px 8px; border-radius: 999px; background: var(--label-bg);
  border: 1px solid var(--line); backdrop-filter: blur(3px);
  transition: color .2s, background .2s, border-color .2s; user-select: none;
}
.map-label:hover { border-color: var(--ink-soft); }
.map-label.selected { color: var(--accent-ink); background: var(--accent); border-color: transparent; }

/* ============================================================ NAVBAR (sticky) */
#navbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.1);
  border-bottom: 1px solid var(--line);
  padding: 6px clamp(18px, 5vw, 48px) 0;
}

/* timeline */
.timeline { max-width: var(--maxw); margin: 4px auto 0; display: flex; align-items: stretch; gap: 2px; }
.tl-arrow {
  flex: none; width: 30px; border: 0; background: none; color: var(--ink-faint);
  cursor: pointer; font-size: 1.25rem; line-height: 1; transition: color .2s;
}
.tl-arrow:hover { color: var(--ink); }
.tl-arrow:disabled { opacity: .25; cursor: default; }
.tl-track { display: flex; gap: 0; overflow-x: auto; scroll-behavior: smooth; padding: 0 2px 8px; flex: 1; scrollbar-width: none; }
.tl-track::-webkit-scrollbar { display: none; }
.tl-chip {
  flex: none; cursor: pointer; border: 0; background: none; color: var(--ink-faint);
  padding: 6px 13px 9px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font-ui); line-height: 1.1; box-shadow: inset 0 -1px 0 var(--line);
  transition: color .18s ease, box-shadow .18s ease;
}
.tl-chip:hover { color: var(--ink); }
.tl-chip .tl-roman { font-weight: 600; font-size: .9rem; letter-spacing: .01em; }
.tl-chip .tl-years { font-size: .64rem; color: var(--ink-faint); transition: color .18s; }
.tl-chip.active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.tl-chip.active .tl-years { color: var(--ink-soft); }
.tl-chip.tl-epilogue .tl-roman { font-size: .8rem; }

/* filters */
.filters { max-width: var(--maxw); margin: 0 auto; display: flex; gap: 4px; overflow-x: auto; padding: 9px 2px 11px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.f-chip {
  flex: none; cursor: pointer; border: 1px solid transparent; background: none; color: var(--ink-faint);
  border-radius: 999px; padding: 4px 12px; font-family: var(--font-ui); font-size: .8rem; font-weight: 500;
  white-space: nowrap; transition: color .16s, background .16s, border-color .16s;
}
.f-chip:hover { color: var(--ink); }
.f-chip.active { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); border-color: var(--line); }
.f-chip .f-ico { margin-right: .4em; font-size: .95em; }

/* ============================================================ CONTENT */
#content { max-width: var(--read); margin: 0 auto; padding: clamp(26px, 5vw, 48px) clamp(20px, 6vw, 24px) 64px; }

.period-head { margin-bottom: 28px; }
.period-title {
  font-family: var(--font-ui); font-weight: 700;
  font-size: clamp(1.9rem, 7vw, 3rem); line-height: 1.0; margin: 0;
  letter-spacing: -.02em; color: var(--ink);
}
.period-title .pt-unit { font-weight: 400; color: var(--ink-faint); }
.period-meta {
  font-family: var(--font-ui); font-size: .86rem; font-weight: 500;
  color: var(--ink-soft); margin-top: 12px; letter-spacing: .005em;
}
.period-era { color: var(--accent); font-weight: 600; }
.period-label {
  font-family: var(--font-read); font-style: italic; font-size: 1.08rem;
  color: var(--ink-soft); margin: 12px 0 0; max-width: 38rem;
}

/* sections — quiet outlined cards */
.section {
  padding: clamp(20px, 3vw, 26px) clamp(20px, 3.2vw, 28px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--paper-2) 65%, transparent);
  margin-bottom: 14px;
  transition: border-color .2s ease, background .2s ease;
}
.section:hover { border-color: var(--line-2); }
.section-title {
  font-family: var(--font-ui); font-weight: 600; font-size: 1.08rem; line-height: 1.35;
  margin: 0 0 2px; letter-spacing: -.01em;
  display: flex; align-items: baseline; gap: .5em;
}
.section-title .sec-ico { font-size: 1.05em; flex: none; }
.section-body { font-size: 1.06rem; color: var(--ink); }
.section-body > *:first-child { margin-top: 14px; }
.section-body p { margin: 0 0 1.05em; }
.section-body strong { font-weight: 600; }
.section-body em { font-style: italic; }
.section-body ul, .section-body ol { margin: 0 0 1.05em; padding-left: 1.2em; }
.section-body li { margin: .4em 0; padding-left: .15em; }
.section-body li::marker { color: var(--ink-faint); }
.section-body hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.section-body .md-h { font-family: var(--font-ui); font-weight: 600; line-height: 1.35; margin: 1.7em 0 .5em; letter-spacing: -.01em; }
.section-body h2.md-h { font-size: 1.3rem; }
.section-body h3.md-h { font-size: 1.12rem; }
.section-body h4.md-h { font-size: 1rem; color: var(--ink-soft); }
.section-body .md-h:first-child { margin-top: 4px; }

/* blockquote callouts — quiet aside */
.section-body blockquote.note {
  margin: 1.5em 0; padding: 2px 0 2px 20px; border-left: 2px solid var(--accent);
  color: var(--ink-soft); font-size: 1rem;
}
.section-body blockquote.note p { margin: 0 0 .6em; }
.section-body blockquote.note p:last-child { margin: 0; }
.section-body blockquote.note strong { color: var(--ink); }

/* tables — minimal ledger */
.table-wrap { overflow-x: auto; margin: 1.6em 0; }
table { border-collapse: collapse; width: 100%; font-family: var(--font-ui); font-size: .88rem; line-height: 1.5; }
thead th {
  text-align: left; font-weight: 600; color: var(--ink-soft); padding: 8px 14px 8px 0;
  border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
tbody td { padding: 10px 14px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
table strong { color: var(--ink); font-weight: 600; }

/* glossary term */
.term { border-bottom: 1px dotted color-mix(in srgb, var(--accent) 70%, transparent); cursor: help; }
.term:hover { color: var(--accent); }

.appendix .section-title { font-weight: 700; font-size: clamp(1.35rem, 5vw, 1.7rem); letter-spacing: -.02em; }

/* ============================================================ TOOLTIP */
#tooltip {
  position: absolute; z-index: 100; max-width: min(320px, 84vw);
  background: var(--ink); color: var(--paper);
  border-radius: 8px; padding: 11px 14px;
  font-family: var(--font-ui); font-size: .84rem; line-height: 1.5;
  box-shadow: 0 14px 36px -14px rgba(0,0,0,.5);
  pointer-events: none; opacity: 0; transform: translateY(3px);
  transition: opacity .15s ease, transform .15s ease;
}
#tooltip.show { opacity: 1; transform: translateY(0); }
#tooltip .tip-term { display: block; font-weight: 700; color: var(--accent); margin-bottom: 3px; font-size: .8rem; letter-spacing: .01em; }
[data-theme="dark"] #tooltip { background: #2a2d35; color: var(--ink); }

/* ============================================================ FOOTER + misc */
#footer {
  max-width: var(--read); margin: 0 auto; padding: 28px clamp(20px, 6vw, 24px) 72px;
  border-top: 1px solid var(--line); color: var(--ink-faint);
  font-family: var(--font-ui); font-size: .76rem; line-height: 1.6;
}
#footer p { margin: 0 0 6px; }
.term-demo { border-bottom: 1px dotted var(--accent); }

.to-top {
  position: fixed; right: 18px; bottom: 18px; z-index: 40;
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--paper-2); color: var(--ink);
  font-size: 1.1rem; box-shadow: 0 6px 20px -10px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .25s, transform .25s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }

/* ============================================================ RESPONSIVE */
@media (max-width: 720px) {
  body { font-size: 1.02rem; }
  #worldmap { max-height: 34vh; }
  .section { padding: 22px 20px; }
  .section-title { font-size: 1.22rem; }
  .to-top { right: 12px; bottom: 12px; }
}
@media (max-width: 440px) {
  .brand-text small { display: none; }
  .map-label { font-size: .58rem; padding: 2px 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, html { scroll-behavior: auto !important; }
}
