:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1c20;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #d81f26;
  --accent-dark: #a8151b;
  --header-bg: #14161a;
  --header-text: #f4f5f7;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: var(--header-bg);
  color: var(--header-text);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 20px;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}
.logo span { color: var(--accent); }
.logo:hover { text-decoration: none; }

.nav-toggle {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

.main-nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  flex: 1;
}

.main-nav a {
  color: #d1d5db;
  font-weight: 600;
  font-size: 0.92rem;
}
.main-nav a:hover { color: #fff; text-decoration: none; }

.search-form {
  display: flex;
  gap: 6px;
}
.search-form input {
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #33363d;
  background: #1f2126;
  color: #fff;
  min-width: 160px;
}
.search-form button {
  padding: 7px 12px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.search-form button:hover { background: var(--accent-dark); }

.account-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  font-weight: 600;
}
.account-nav a { color: #d1d5db; }
.account-nav a:hover { color: #fff; text-decoration: none; }
.logout-inline { margin: 0; }
.logout-inline button {
  background: none;
  border: none;
  color: #d1d5db;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.logout-inline button:hover { color: #fff; text-decoration: underline; }

/* Page */
.page-title {
  font-size: 1.7rem;
  margin: 28px 0 20px;
}

.empty-state {
  color: var(--text-muted);
  padding: 40px 0;
  text-align: center;
}

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 22px;
  margin-bottom: 30px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.card-thumb {
  display: block;
  aspect-ratio: 16 / 9;
  background: #e5e7eb;
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  color: #9ca3af;
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.card-category {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  align-self: flex-start;
}

.card-title {
  font-size: 1.05rem;
  margin: 0;
  line-height: 1.35;
}
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); text-decoration: none; }

.card-summary {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
  flex: 1;
}

.card-date {
  color: #9ca3af;
  font-size: 0.78rem;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 20px 0 40px;
  font-size: 0.9rem;
}
.pagination-status { color: var(--text-muted); }

/* Article */
.article-page {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 28px;
  margin-top: 24px;
}
.article-title {
  font-size: 1.9rem;
  margin: 10px 0 8px;
  line-height: 1.25;
}
.article-meta {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 18px;
}
.article-body {
  font-size: 1.03rem;
}
.article-body p { margin: 0 0 16px; }
.article-body h2, .article-body h3, .article-body h4 {
  margin: 28px 0 12px;
  line-height: 1.3;
}
.article-body h2 { font-size: 1.4rem; }
.article-body h3 { font-size: 1.2rem; }
.article-body h4 { font-size: 1.08rem; }
.article-body ul, .article-body ol {
  margin: 0 0 16px;
  padding-left: 22px;
}
.article-body li { margin-bottom: 6px; }
.article-body a { color: var(--accent); text-decoration: underline; }
.article-body blockquote {
  margin: 0 0 16px;
  padding: 4px 16px;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}
.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0 16px;
  display: block;
}
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 0.92rem;
}
.article-body table td, .article-body table th {
  border: 1px solid var(--border);
  padding: 8px 10px;
}
.article-gallery button,
.lightbox button,
.lightbox-trigger {
  appearance: none;
  -webkit-appearance: none;
}
.lightbox-trigger {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  font: inherit;
}

/* Gallery: big image + slider arrows + thumbnail strip, above the article text */
.article-gallery {
  margin-bottom: 20px;
}
.gallery-main {
  position: relative;
}
.gallery-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  border-radius: var(--radius);
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
}
.gallery-slide img {
  width: 100%;
  aspect-ratio: 16/9;
  max-height: 460px;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
}
.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(20, 22, 26, 0.55);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-nav:hover { background: rgba(20, 22, 26, 0.8); }
.gallery-prev { left: 12px; }
.gallery-next { right: 12px; }

.gallery-thumbs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.gallery-thumbs::-webkit-scrollbar { display: none; }
.gallery-thumb {
  flex: 0 0 80px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  opacity: 0.6;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.gallery-thumb img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.gallery-thumb:hover { opacity: 0.85; }
.gallery-thumb.active {
  opacity: 1;
  border-color: var(--accent);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  /* Solid, not translucent: a semi-transparent fill on a full-viewport fixed
     layer triggers a compositor bug in some browsers where the background only
     paints in a narrow band instead of the full screen. */
  background: #0b0c0e;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 50px 20px;
}
.lightbox[hidden] { display: none; }
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-prev:hover,
.lightbox-next:hover,
.lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-counter {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 0.85rem;
  opacity: 0.85;
}

@media (max-width: 560px) {
  .lightbox-prev, .lightbox-next { width: 38px; height: 38px; font-size: 1.3rem; }
}

/* Comments */
.comments-section {
  margin: 32px 0 60px;
}
.comments-section h2 {
  font-size: 1.3rem;
}
.comment-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
}
.comment {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.comment-author { font-weight: 700; font-size: 0.92rem; }
.comment-text { margin: 6px 0; white-space: pre-wrap; }
.comment-date { color: #9ca3af; font-size: 0.78rem; }

.comment-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 520px;
}
.comment-form h3 { margin: 0 0 4px; font-size: 1.05rem; }
.comment-form input,
.comment-form textarea {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.95rem;
}
.comment-form button {
  align-self: flex-start;
  padding: 9px 18px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.comment-form button:hover { background: var(--accent-dark); }

.flash-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
}
.flash-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
}

/* Footer */
.site-footer {
  margin-top: 60px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.footer-links a { color: var(--text-muted); }

/* 404 */
.not-found {
  text-align: center;
  padding: 80px 0;
}
.not-found h1 {
  font-size: 5rem;
  margin: 0;
  color: var(--accent);
}

/* Auth pages */
.auth-page {
  max-width: 420px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.auth-page h1 { font-size: 1.4rem; margin: 0 0 6px; text-align: center; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin: 0 0 20px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; color: #374151; }
.auth-form input {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 400;
}
.auth-form button {
  margin-top: 4px;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
}
.auth-form button:hover { background: var(--accent-dark); }
.auth-links { text-align: center; margin-top: 16px; font-size: 0.88rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.hint-text { color: var(--text-muted); font-size: 0.88rem; }
.account-page {
  max-width: 520px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.account-page dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 20px 0; }
.account-page dt { color: var(--text-muted); font-size: 0.88rem; }
.account-page dd { margin: 0; font-weight: 600; }
.account-page h2 { font-size: 1.05rem; margin: 28px 0 12px; }
.account-page .auth-form { gap: 10px; max-width: none; }
.account-page .form-actions { margin-top: 28px; }
.form-actions { display: flex; gap: 10px; }
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: var(--bg); text-decoration: none; }

@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .main-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 10px;
    padding-top: 10px;
  }
  .main-nav.open { display: flex; }
  .search-form { width: 100%; }
  .search-form input { flex: 1; min-width: 0; }
  .article-page { padding: 18px; }
}
