/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

/* ── CSS Variables (light mode defaults) ─────────────────────────────────── */
:root {
  --bg:                    #ffffff;
  --bg-secondary:          #f2f2f7;
  --bg-hover:              #e5e5ea;
  --text-primary:          #000000;
  --text-secondary:        #6d6d72;
  --separator:             #c6c6c8;
  --accent:                #007aff;
  --banner-bg:             #000000;
  --banner-text:           #ffffff;
  --banner-text-secondary: rgba(255, 255, 255, 0.58);
  --unread-dot:            #007aff;
  --read-dot:              rgba(142, 142, 147, 0.35);
  --read-image-opacity:    0.72;
  --header-height:         56px;
  --thumbnail-sm:          110px;
  --thumbnail-md:          176px;
  --header-title-color:    #141628;
}

/* Dark mode — OS preference */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:                    #1c1c1e;
    --bg-secondary:          #2c2c2e;
    --bg-hover:              #3a3a3c;
    --text-primary:          #ffffff;
    --text-secondary:        rgba(235, 235, 245, 0.6);
    --separator:             #38383a;
    --banner-bg:             #ffffff;
    --banner-text:           #000000;
    --banner-text-secondary: rgba(0, 0, 0, 0.55);
    --header-title-color:    #ffffff;
  }
}

/* Dark mode — manual toggle override */
html[data-theme="dark"] {
  --bg:                    #1c1c1e;
  --bg-secondary:          #2c2c2e;
  --bg-hover:              #3a3a3c;
  --text-primary:          #ffffff;
  --text-secondary:        rgba(235, 235, 245, 0.6);
  --separator:             #38383a;
  --banner-bg:             #ffffff;
  --banner-text:           #000000;
  --banner-text-secondary: rgba(0, 0, 0, 0.55);
  --header-title-color:    #ffffff;
}
html[data-theme="light"] {
  --bg:                    #ffffff;
  --bg-secondary:          #f2f2f7;
  --bg-hover:              #e5e5ea;
  --text-primary:          #000000;
  --text-secondary:        #6d6d72;
  --separator:             #c6c6c8;
  --banner-bg:             #000000;
  --banner-text:           #ffffff;
  --banner-text-secondary: rgba(255, 255, 255, 0.58);
  --header-title-color:    #141628;
}

/* ── Logo: light/dark variants ───────────────────────────────────────────── */
.logo-dark  { display: none; }
.logo-light { display: block; }
@media (prefers-color-scheme: dark) {
  .logo-light { display: none; }
  .logo-dark  { display: block; }
}
html[data-theme="dark"]  .logo-light { display: none; }
html[data-theme="dark"]  .logo-dark  { display: block; }
html[data-theme="light"] .logo-light { display: block; }
html[data-theme="light"] .logo-dark  { display: none; }

/* ── Header ──────────────────────────────────────────────────────────────── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
  height: var(--header-height);
  max-width: 1200px;
  margin: 0 auto;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}
.header-logo img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}
.header-title {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 24px;
  color: var(--header-title-color);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.header-nav {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 8px 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}
#app-header.is-open .header-nav {
  display: flex;
}
.header-nav-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.header-nav-link:hover  { background: var(--bg-secondary); color: var(--text-primary); }
.header-nav-link.active { color: var(--accent); font-weight: 600; }
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-primary);
  transition: background 0.15s;
}
.header-btn:hover { background: var(--bg-secondary); }
.header-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.header-menu-btn { display: flex; }

/* ── Loading overlay ─────────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  top: var(--header-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  z-index: 50;
}
#loading-overlay.hidden { display: none; }
#loading-overlay p { font-size: 15px; color: var(--text-secondary); }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Day banner ──────────────────────────────────────────────────────────── */
.day-banner-wrap { padding: 8px 16px; }
.day-banner {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--banner-bg);
  color: var(--banner-text);
  border-radius: 12px;
  user-select: none;
  -webkit-user-select: none;
}
.day-banner-title { font-size: 17px; font-weight: 600; line-height: 1; }

/* ── Article row ─────────────────────────────────────────────────────────── */
.article-row {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  transition: background 0.1s;
}
.article-row:hover  { background: var(--bg-hover); }
.article-row:active { background: var(--bg-secondary); }

.thumb-wrap {
  flex-shrink: 0;
  width: var(--thumbnail-sm);
  height: var(--thumbnail-sm);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary);
  position: relative;
}
.article-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  transition: opacity 0.15s;
}
.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: 8px;
}
.thumb-placeholder svg {
  width: 36px;
  height: 36px;
  opacity: 0.25;
  fill: var(--text-secondary);
  stroke: none;
}
.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  pointer-events: none;
}
.video-overlay svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
}
.type-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  margin-left: 6px;
  vertical-align: middle;
}

.article-content {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  align-self: stretch;
}
.article-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}
.article-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.action-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.action-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.action-btn.is-active { color: var(--accent); }
.action-btn.is-active svg { fill: currentColor; }
.source-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.source-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.source-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}
.article-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-description {
  display: none;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.article-date {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1;
}

/* Read state */
.article-row.is-read .article-thumbnail { opacity: var(--read-image-opacity); }
.article-row.is-read .article-title     { color: var(--text-secondary); }
.article-row.is-read .article-date      { opacity: 0.75; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
#site-footer {
  margin-top: 40px;
  padding: 24px 16px 32px;
  border-top: 1px solid var(--separator);
  text-align: center;
}
.footer-inner { max-width: 1200px; margin: 0 auto; }
.footer-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 12px;
}
.footer-links a { font-size: 13px; color: var(--text-secondary); text-decoration: none; }
.footer-links a:hover { color: var(--text-primary); }
.footer-copy { font-size: 12px; color: var(--text-secondary); }

/* ── Toast (transient bottom message) ────────────────────────────────────── */
#share-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(8px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text-primary);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
  white-space: nowrap;
}
#share-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Tablet / Desktop ────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .header-logo img { width: 42px; height: 42px; border-radius: 10px; }
  .header-logo     { flex: 0 0 auto; gap: 18px; }
  .header-title    { font-size: 30px; }
  .header-nav {
    display: flex;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 0;
    background: transparent;
    border-bottom: 0;
    box-shadow: none;
  }
  .header-nav-link {
    min-height: 0;
    padding: 6px 12px;
    font-size: 15px;
  }
  .header-menu-btn { display: none; }

  .article-row     { padding: 12px 32px; gap: 20px; }
  .thumb-wrap      { width: var(--thumbnail-md); height: var(--thumbnail-md); }
  .thumb-placeholder svg { width: 52px; height: 52px; }

  .article-content { gap: 8px; padding: 4px 0; }
  .source-name     { font-size: 19px; }
  .article-title   { font-size: 19px; font-weight: 500; -webkit-line-clamp: 4; }
  .article-description { display: -webkit-box; font-size: 15px; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .article-date    { font-size: 13px; }

  .day-banner-wrap { padding: 8px 32px; }
}
