:root {
  --bg: #061128;
  --bg-soft: #091734;
  --surface: rgba(10, 21, 46, 0.92);
  --surface-strong: rgba(12, 25, 56, 0.98);
  --surface-muted: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(111, 135, 255, 0.28);
  --text: #f5f7ff;
  --text-muted: #9ca8cb;
  --text-soft: #7985ab;
  --primary: #6f87ff;
  --primary-strong: #88a0ff;
  --primary-glow: rgba(111, 135, 255, 0.24);
  --success: #6dd6a6;
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --shadow: 0 24px 60px rgba(2, 8, 24, 0.52);
}

[data-theme="light"] {
  --bg: #f3f5fb;
  --bg-soft: #ffffff;
  --surface: rgba(255, 255, 255, 0.95);
  --surface-strong: rgba(255, 255, 255, 0.98);
  --surface-muted: rgba(20, 22, 31, 0.035);
  --border: #e6e8f0;
  --border-strong: rgba(61, 90, 254, 0.28);
  --text: #14161f;
  --text-muted: #5b5f6d;
  --text-soft: #7b8194;
  --primary: #3d5afe;
  --primary-strong: #2a3ecf;
  --primary-glow: rgba(61, 90, 254, 0.16);
  --success: #1fb774;
  --shadow: 0 20px 48px rgba(20, 22, 31, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Manrope", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(111, 135, 255, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(44, 184, 255, 0.08), transparent 24%),
    linear-gradient(180deg, #030817 0%, var(--bg) 48%, #040a18 100%);
  color: var(--text);
}

button, select { font: inherit; }
button { cursor: pointer; }

.container {
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
}

.articles-page {
  min-height: 100vh;
  padding: 40px 0 72px;
}

.articles-shell {
  position: relative;
}

.articles-hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 28px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(13, 24, 53, 0.94), rgba(8, 16, 36, 0.9));
  box-shadow: var(--shadow);
}

.eyebrow {
  margin-bottom: 12px;
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-title {
  margin: 0;
  max-width: 780px;
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.05;
}

.page-subtitle {
  margin: 16px 0 0;
  max-width: 760px;
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1.68;
}

.hero-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  min-width: 220px;
}

.write-btn {
  border: 0;
  border-radius: 18px;
  padding: 16px 22px;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(135deg, #5f7bff, #6f87ff 58%, #7e95ff);
  box-shadow: 0 18px 36px rgba(111, 135, 255, 0.32);
}

.articles-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.articles-feed,
.sidebar-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(10, 19, 42, 0.95), rgba(7, 14, 32, 0.92));
  box-shadow: var(--shadow);
}

.articles-feed {
  padding: 28px;
}

.feed-head,
.sidebar-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.section-title,
.sidebar-title {
  margin: 0;
  font-size: 26px;
  line-height: 1.12;
}

.section-subtitle,
.sidebar-subtitle {
  margin: 10px 0 0;
  color: var(--text-muted);
  line-height: 1.6;
}

.feed-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.meta-chip,
.filter-chip,
.pagination__btn {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}

.meta-chip {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
}

.meta-chip.is-active {
  color: #fff;
  border-color: rgba(111, 135, 255, 0.35);
  background: rgba(111, 135, 255, 0.12);
}

.articles-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.article-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(13, 24, 53, 0.7), rgba(8, 16, 34, 0.88));
  min-height: 100%;
}

.article-card__cover {
  height: 164px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.article-card__cover--gradient {
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 255, 255, 0.18), transparent 18%),
    radial-gradient(circle at 78% 20%, rgba(111, 135, 255, 0.5), transparent 24%),
    linear-gradient(135deg, rgba(83, 104, 255, 0.88), rgba(27, 55, 117, 0.66));
}

.article-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 20px;
}

.article-card__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.article-card__tag {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
}

.article-card__save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  min-width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  color: #f0f4ff;
  line-height: 1;
}

.article-card__save.is-saved {
  border-color: rgba(111, 135, 255, 0.42);
  background: rgba(111, 135, 255, 0.16);
  color: #fff;
}

.article-card__save svg {
  width: 16px;
  height: 16px;
}

.article-card__save.is-saved svg {
  fill: currentColor;
}

.article-card__title {
  margin: 16px 0 10px;
  font-size: 24px;
  line-height: 1.2;
}

.article-card__text {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.68;
}

.article-card__meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: auto;
  padding-top: 20px;
}

.article-card__author {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.article-card__author-meta {
  min-width: 0;
}

.article-card__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(111, 135, 255, 0.95), rgba(58, 84, 190, 0.9));
  box-shadow: 0 10px 18px rgba(111, 135, 255, 0.22);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  overflow: hidden;
}

.article-card__name,
.article-card__date {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.article-card__name {
  margin-bottom: 2px;
  font-size: 14px;
  font-weight: 800;
}

.article-card__date,
.article-card__stats {
  color: var(--text-soft);
  font-size: 13px;
}

.article-card__stats {
  flex-shrink: 0;
  text-align: right;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.article-card__stats svg {
  width: 13px;
  height: 13px;
  color: #ff6b81;
  flex-shrink: 0;
}

.articles-sidebar {
  min-width: 0;
}

.sidebar-card {
  padding: 24px;
}

.sidebar-card--sticky {
  position: static;
}

.filter-group {
  margin-top: 22px;
}

.filter-label {
  display: block;
  margin-bottom: 12px;
  color: #f3f6ff;
  font-size: 14px;
  font-weight: 800;
}

.filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-chip {
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 700;
}

.filter-chip.is-active,
.filter-chip.is-soft-active:hover,
.filter-chip:hover,
.pagination__btn:hover {
  color: #fff;
  border-color: rgba(111, 135, 255, 0.38);
  background: rgba(111, 135, 255, 0.14);
}

.filter-chip.is-soft-active {
  color: var(--primary-strong);
  background: rgba(111, 135, 255, 0.1);
}

.sort-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 40px 14px 16px;
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca8cb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 16px;
  transition: border-color var(--transition, 0.2s ease);
}

.sort-select:focus {
  border-color: var(--border-strong);
}

.sort-select option {
  background: var(--bg-soft);
  color: var(--text);
}

.sidebar-note {
  margin-top: 22px;
  padding: 16px 18px;
  border: 1px solid rgba(111, 135, 255, 0.18);
  border-radius: 18px;
  background: rgba(111, 135, 255, 0.08);
  color: var(--text-muted);
  line-height: 1.6;
}

.sidebar-note strong {
  color: #fff;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 28px;
}

.pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
}

.pagination__btn.is-active {
  color: #fff;
  border-color: rgba(111, 135, 255, 0.42);
  background: linear-gradient(135deg, rgba(95, 123, 255, 0.92), rgba(111, 135, 255, 0.85));
  box-shadow: 0 12px 26px rgba(111, 135, 255, 0.22);
}

.pagination__btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  margin-top: 24px;
  padding: 24px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
}

.article-card {
  cursor: pointer;
  transition: border-color var(--transition, 0.2s ease), transform var(--transition, 0.2s ease);
}

.article-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

/* ---------------- Recently viewed sidebar ---------------- */
.sidebar-title--sm {
  font-size: 18px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  text-align: left;
  transition: border-color var(--transition, 0.2s ease), background var(--transition, 0.2s ease);
}

.history-item:hover {
  border-color: var(--border-strong);
  background: rgba(111, 135, 255, 0.08);
}

.history-item__title {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item__meta {
  font-size: 12px;
  color: var(--text-soft);
}

/* ---------------- Article reading modal ---------------- */
.article-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 20px;
  background: rgba(3, 8, 20, 0.68);
  overflow-y: auto;
  z-index: 1000;
}

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

.article-modal {
  width: min(720px, 100%);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.article-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.article-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
}

.article-modal__close:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.article-modal__close svg {
  width: 15px;
  height: 15px;
}

.article-modal__title {
  margin: 18px 0 16px;
  font-size: 28px;
  line-height: 1.2;
}

.article-modal__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.article-modal__body {
  color: var(--text);
  line-height: 1.8;
  font-size: 15px;
}

.article-modal__body p {
  margin: 0 0 16px;
}

.article-modal__body h4 {
  margin: 22px 0 8px;
  font-size: 16px;
  color: var(--text);
}

.article-modal__body ul {
  margin: 0 0 16px;
  padding-left: 22px;
}

.article-modal__body li {
  margin-bottom: 6px;
}

@media (max-width: 620px) {
  .article-modal {
    padding: 24px;
  }

  .article-modal__title {
    font-size: 22px;
  }
}

@media (max-width: 1080px) {
  .articles-layout {
    grid-template-columns: 1fr;
  }

  .sidebar-card--sticky {
    position: static;
  }
}

@media (max-width: 760px) {
  .container {
    width: min(100% - 24px, 1280px);
  }

  .articles-page {
    padding: 20px 0 40px;
  }

  .articles-hero,
  .articles-feed,
  .sidebar-card {
    padding: 20px;
    border-radius: 22px;
  }

  .articles-hero,
  .feed-head,
  .sidebar-head,
  .article-card__meta {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-actions {
    min-width: 0;
    justify-content: flex-start;
  }

  .write-btn {
    width: 100%;
  }

  .articles-grid {
    grid-template-columns: 1fr;
  }

  .page-title {
    font-size: 30px;
  }

  .page-subtitle {
    font-size: 15px;
  }

  .article-card__meta {
    gap: 12px;
  }

  .article-card__stats {
    text-align: left;
  }
}

/* ---------------- Light theme overrides ----------------
   Most components read colors from the variables above, but a few
   backgrounds are hardcoded washes tuned for a dark surface and need
   an explicit light counterpart. */
[data-theme="light"] body {
  background:
    radial-gradient(circle at top left, rgba(61, 90, 254, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(44, 130, 255, 0.05), transparent 24%),
    linear-gradient(180deg, #f8f9fd 0%, var(--bg) 48%, #eef1fb 100%);
}

[data-theme="light"] .articles-hero {
  background: #ffffff;
}

[data-theme="light"] .articles-feed,
[data-theme="light"] .sidebar-card {
  background: #ffffff;
}

[data-theme="light"] .meta-chip,
[data-theme="light"] .filter-chip,
[data-theme="light"] .pagination__btn {
  border-color: var(--border);
  background: #f6f7fb;
  color: var(--text-muted);
}

[data-theme="light"] .meta-chip.is-active,
[data-theme="light"] .filter-chip.is-active,
[data-theme="light"] .filter-chip.is-soft-active:hover,
[data-theme="light"] .filter-chip:hover,
[data-theme="light"] .pagination__btn:hover {
  color: var(--primary-strong);
  border-color: rgba(61, 90, 254, 0.35);
  background: #e9eeff;
}

[data-theme="light"] .filter-chip.is-soft-active {
  color: var(--primary-strong);
  background: #eef1fb;
}

[data-theme="light"] .pagination__btn.is-active {
  color: #fff;
  border-color: #3d5afe;
  background: linear-gradient(135deg, #4f6bff, #3d5afe);
}

[data-theme="light"] .article-card {
  border: 1px solid var(--border);
  background: #ffffff;
}

[data-theme="light"] .article-card__tag {
  background: #eef1fb;
  color: var(--primary-strong);
}

[data-theme="light"] .article-card__save {
  border: 1px solid var(--border);
  background: #f6f7fb;
  color: #14161f;
}

[data-theme="light"] .article-card__save.is-saved {
  border-color: #3d5afe;
  background: #e9eeff;
  color: #2a3ecf;
}

[data-theme="light"] .sort-select {
  border: 1px solid var(--border);
  background-color: #ffffff;
  color: #14161f;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b5f6d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="light"] .filter-label {
  color: var(--text);
}

[data-theme="light"] .sidebar-note strong {
  color: var(--text);
}

[data-theme="light"] .empty-state {
  border: 1px dashed var(--border);
}
