/* === Reset === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* === Light Theme (default) === */
:root,
[data-theme="light"] {
  --bg: rgb(255 249 238);
  --surface: rgb(244 237 223);
  --surface-high: rgb(238 232 218);
  --text: rgb(30 27 19);
  --text-secondary: rgb(75 71 57);
  --accent: rgb(109 94 15);
  --accent-container: rgb(248 226 135);
  --accent-on-container: rgb(83 70 0);
  --tertiary: rgb(67 102 78);
  --tertiary-container: rgb(197 236 206);
  --outline: rgb(124 119 103);
  --outline-variant: rgb(205 198 180);
  --tag-bg: rgb(238 232 218);
  --tag-text: rgb(75 71 57);
}

/* === Dark Theme === */
[data-theme="dark"] {
  --bg: rgb(21 19 11);
  --surface: rgb(34 32 23);
  --surface-high: rgb(45 42 33);
  --text: rgb(232 226 212);
  --text-secondary: rgb(205 198 180);
  --accent: rgb(219 198 110);
  --accent-container: rgb(83 70 0);
  --accent-on-container: rgb(248 226 135);
  --tertiary: rgb(169 208 179);
  --tertiary-container: rgb(44 78 56);
  --outline: rgb(150 144 128);
  --outline-variant: rgb(75 71 57);
  --tag-bg: rgb(45 42 33);
  --tag-text: rgb(205 198 180);
}

/* === Base === */
html { font-size: 16px; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
}

/* === Header === */
.header {
  padding: 48px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Home page carries a two-line brand block; top-align the toggle to the title.
   The single-line detail-page header stays centered (default above). */
.header:has(.header-brand) {
  align-items: flex-start;
}

.header-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

.header-subtitle {
  font-size: 0.9rem;
  font-style: italic;
  letter-spacing: normal;
  color: var(--text-secondary);
}

/* === Theme Toggle === */
.theme-toggle {
  position: relative;
  color: var(--text-secondary);
  background: var(--surface);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
  overflow: hidden;
}

.theme-toggle:hover {
  background: var(--surface-high);
}

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

/* Icon container for animation */
.theme-icon {
  position: absolute;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light theme: show sun, hide moon */
:root .theme-icon--sun,
[data-theme="light"] .theme-icon--sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

:root .theme-icon--moon,
[data-theme="light"] .theme-icon--moon {
  opacity: 0;
  transform: rotate(-45deg) scale(0.8);
}

/* Dark theme: show moon, hide sun */
[data-theme="dark"] .theme-icon--sun {
  opacity: 0;
  transform: rotate(45deg) scale(0.8);
}

[data-theme="dark"] .theme-icon--moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* === Stats Bar === */
.stats-bar {
  padding: 32px 0;
  display: flex;
  gap: 32px;
  border-bottom: 2px solid var(--text);
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-number {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* === Filter Bar === */
.filter-bar {
  padding: 32px 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.tag-chip {
  flex: 0 0 auto;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 9999px;
  border: none;
  background: var(--tag-bg);
  color: var(--tag-text);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tag-chip:hover {
  background: var(--outline-variant);
}

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

.tag-chip.active {
  background: var(--accent-container);
  color: var(--accent-on-container);
  font-weight: 700;
}

/* === Search === */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.search-block { padding: 32px 0 0; }

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  padding: 0 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.search-field > svg { flex: none; color: var(--text-secondary); }

.search-field input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: none;
  border: none;
  outline: none;
  padding: 13px 0;
}

.search-field input::placeholder { color: var(--text-secondary); }
.search-field input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.search-clear {
  flex: none;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.search-clear:hover { background: var(--surface-high); color: var(--text); }
.search-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-clear[hidden] { display: none; }

.search-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 10px;
  min-height: 1.2em;
}
.search-count:empty { margin-top: 0; }
.search-count b { color: var(--text); font-weight: 700; }

mark {
  background: var(--accent-container);
  color: var(--accent-on-container);
  border-radius: 3px;
  padding: 0 1px;
}

.body-hit {
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-secondary);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  max-width: 62ch;
}
.body-hit[hidden] { display: none; }
.body-hit::before {
  content: "In text";
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-right: 8px;
  vertical-align: 1px;
}

/* === Empty / no-results === */
.no-results { padding: 56px 0 80px; text-align: center; }
.no-results[hidden] { display: none; }
.no-results h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  color: var(--text);
}
.no-results p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 46ch;
  margin: 0 auto 20px;
  text-wrap: pretty;
}
.no-results .reset {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 9px 18px;
  border-radius: 9999px;
  transition: opacity 0.15s ease;
}
.no-results .reset:hover { opacity: 0.88; }
.no-results .reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* === Article List === */
.article-list {
  padding: 0 0 80px;
}

.article-item {
  padding: 28px 0;
  border-bottom: 1px solid var(--outline-variant);
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 24px;
  align-items: start;
}

.article-item[hidden] {
  display: none;
}

.article-date-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-top: 4px;
}

.article-date-day {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  letter-spacing: -0.02em;
}

.article-date-month {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-top: 2px;
}

.article-content {}

.article-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  text-decoration: none;
  display: block;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.article-title:hover {
  color: var(--accent);
}

.article-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.article-excerpt {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 60ch;
  margin-bottom: 12px;
  text-wrap: pretty;
}

.article-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.article-tag {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 10px;
  border-radius: 9999px;
  background: var(--surface-high);
  color: var(--text-secondary);
}

a.article-tag {
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

a.article-tag:hover {
  opacity: 0.85;
}

/* Tag color variants — light mode */
[data-theme="light"] .article-tag.finance { background: #e8f5e9; color: #2e4e38; }
[data-theme="light"] .article-tag.corruption { background: #fce4ec; color: #5d1a2a; }
[data-theme="light"] .article-tag.governance { background: #e3f2fd; color: #1a3a5c; }
[data-theme="light"] .article-tag.judiciary { background: #f3e5f5; color: #4a1e5e; }
[data-theme="light"] .article-tag.media { background: #fff3e0; color: #5c3a0a; }

/* Tag color variants — dark mode */
[data-theme="dark"] .article-tag.finance { background: #1b3d25; color: #a5d6b0; }
[data-theme="dark"] .article-tag.corruption { background: #3d1520; color: #f5a0b0; }
[data-theme="dark"] .article-tag.governance { background: #152a3d; color: #90c4f0; }
[data-theme="dark"] .article-tag.judiciary { background: #2d153d; color: #d0a0f0; }
[data-theme="dark"] .article-tag.media { background: #3d2a10; color: #f0c070; }

/* === Back Link === */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 32px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.back-link:hover {
  color: var(--accent);
}

.back-link svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* === Article Detail Page === */
.header-title {
  text-decoration: none;
}

.header-title:hover {
  color: var(--accent);
}

a.header-title {
  color: var(--text);
}

.article-header {
  margin-top: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--outline-variant);
}

.article-page-title {
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  text-wrap: balance;
  max-width: 70ch;
}

.article-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.article-date {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--outline);
  letter-spacing: 0.01em;
}

.article-authors {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.article-meta-separator {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--outline-variant);
}

.article-meta-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* === Article Body (rendered Markdown) === */
.article-body {
  margin-top: 48px;
  max-width: 70ch;
}

.article-body p {
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--text);
  text-wrap: pretty;
  margin-bottom: 1.5em;
}

.article-body p:last-child {
  margin-bottom: 0;
}

.article-body h2 {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-top: 2.5em;
  margin-bottom: 0.75em;
  color: var(--text);
  text-wrap: balance;
}

.article-body h3 {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.4;
  margin-top: 2em;
  margin-bottom: 0.5em;
  color: var(--text);
}

.article-body blockquote {
  border-left: 2px solid var(--outline-variant);
  padding-left: 20px;
  margin: 1.5em 0;
  font-style: italic;
}

.article-body blockquote p {
  color: var(--text-secondary);
}

.article-body ul,
.article-body ol {
  font-size: 1.125rem;
  line-height: 1.7;
  margin-bottom: 1.5em;
  padding-left: 1.5em;
}

.article-body li {
  margin-bottom: 0.5em;
}

.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.article-body a:hover {
  text-decoration: none;
}

.article-body code {
  font-size: 0.9em;
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
}

.article-body pre {
  background: var(--surface);
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.5em;
}

.article-body pre code {
  background: none;
  padding: 0;
}

/* === Article Footer === */
.article-footer {
  margin-top: 64px;
  padding: 32px 0;
  border-top: 1px solid var(--outline-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--tertiary);
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.source-link:hover {
  opacity: 0.8;
}

.source-link svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--outline-variant);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.share-btn:hover {
  background: var(--surface);
  border-color: var(--outline);
}

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

.share-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.share-btn.copied .share-btn-label::after {
  content: " ✓";
}

/* === Footer === */
.footer {
  margin-top: 48px;
  padding: 40px 0;
  border-top: 2px solid var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer p {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.footer-updated {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--outline);
}

/* === Responsive === */
@media (max-width: 600px) {
  .header { padding: 32px 0 0; }

  .article-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .article-date-block {
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
  }

  .article-date-day { font-size: 1.25rem; }

  .stats-bar { gap: 20px; }
  .stat-number { font-size: 1.5rem; }

  /* Article detail responsive */
  .article-header { margin-top: 32px; }
  .article-body { margin-top: 32px; }
  .article-footer { margin-top: 48px; }
  .footer { margin-top: 64px; }
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
