/**
 * Global design tokens and theme definitions for petarpetrov.org.
 *
 * Dark Mode: Danube Teal on Mineral Slate (WCAG AA/AAA verified).
 * Light Mode: Graphite Ink on Warm Sand (WCAG AAA verified).
 */
:root {
  --bg: #0e1114;
  --bg-elevated: #15191e;
  --text: #eceff1;       /* 15.6:1 contrast on --bg (AAA) */
  --text-muted: #9ba7b2; /* 7.3:1 contrast on --bg (AAA), 6.5:1 on --bg-elevated */
  --border: #262e36;
  --accent: #2dd4bf;     /* 10.1:1 contrast on --bg (AAA) */
  --accent-soft: rgba(45, 212, 191, 0.1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-serif: "Newsreader", "Charter", "Iowan Old Style", Georgia, serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
}

html.light,
body.light {
  --bg: #f4f1ea;
  --bg-elevated: #e8e3d7;
  --text: #141413;       /* 16.2:1 contrast on --bg (AAA) */
  --text-muted: #403e39; /* 9.1:1 contrast on --bg (AAA), 8.2:1 on --bg-elevated (AAA) */
  --border: #cfc8b8;
  --accent: #141413;     /* 16.2:1 contrast on --bg (AAA) */
  --accent-soft: rgba(20, 20, 19, 0.07);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.theme-ready {
  transition: background 0.25s ease, color 0.25s ease;
}

.page {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 64px 24px 120px;
}

/* Header & Identity */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 64px;
  gap: 16px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 16px;
}

.avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.identity-text strong {
  display: block;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.identity-text span {
  font-size: 13.5px;
  color: var(--text-muted);
}

/* Sun / Moon Theme Toggle Button */
.theme-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.theme-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
  transform: scale(1.04);
}

.theme-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-moon {
  display: none;
}

html.light .icon-sun,
body.light .icon-sun {
  display: none;
}

html.light .icon-moon,
body.light .icon-moon {
  display: block;
}

/* Hero Section */
.hero {
  margin-bottom: 64px;
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: 44px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 24px;
}

.hero h1 em {
  font-style: italic;
  color: var(--accent);
  transition: color 0.2s;
}

.hero p {
  font-size: 17.5px;
  color: var(--text-muted);
  margin-bottom: 18px;
  max-width: 650px;
}

.hero p strong {
  color: var(--text);
  font-weight: 500;
}

.hero a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
}

/* Interactive Signal Waveform Divider */
.signal-wrap {
  margin: 48px 0 56px;
  position: relative;
  width: 100%;
}

.signal-wrap canvas {
  width: 100%;
  max-width: 100%;
  height: 68px;
  display: block;
  cursor: crosshair;
}

.signal-caption {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* 4-Chapter Navigation */
.chapters-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 36px;
}

.chapter-tab {
  min-width: 0;
  background: transparent;
  border: none;
  text-align: left;
  padding: 18px 14px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.chapter-tab:hover {
  color: var(--text);
}

.chapter-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.chapter-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.chapter-year {
  font-family: var(--font-mono);
  font-size: 11px;
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.chapter-tab.active .chapter-year {
  color: var(--accent);
  font-weight: 600;
}

.chapter-name {
  font-size: 14.5px;
  font-weight: 600;
  display: block;
}

/* Chapter Story Articles */
.chapter-story {
  padding: 8px 4px 32px;
  min-height: 230px;
}

.chapter-panel {
  display: none;
}

.chapter-panel.active {
  display: block;
}

.story-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 18px;
}

.story-header h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.2;
}

.story-role {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent);
}

.story-body p {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 16px;
  max-width: 660px;
}

.story-body strong {
  color: var(--text);
  font-weight: 500;
}

.story-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.pill {
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Footer */
.footer-bar {
  margin-top: 64px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-meta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: color 0.15s, border-color 0.15s;
}

.links a:hover {
  color: var(--text);
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .page {
    padding: 40px 20px 80px;
  }
  header {
    margin-bottom: 40px;
  }
  .hero {
    margin-bottom: 40px;
  }
  .hero h1 {
    font-size: 30px;
  }
  .hero p {
    font-size: 16px;
  }
  .signal-wrap {
    margin: 32px 0 40px;
  }
  .chapters-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .story-header h2 {
    font-size: 24px;
  }
}
