/* ── CSS Variables & Reset ─────────────────────────────────────────────── */
:root {
  --bg:          #f8f8f5;
  --bg-card:     #ffffff;
  --bg-hover:    #f0f0eb;
  --bg-tts:      #fff8e1;
  --border:      #e4e4df;
  --text:        #1a1a1a;
  --text-muted:  #6b6b6b;
  --text-light:  #999;
  --accent:      #2563eb;
  --accent-dark: #1d4ed8;
  --accent-bg:   #eff6ff;
  --danger:      #dc2626;
  --danger-bg:   #fef2f2;
  --success:     #16a34a;
  --tag-bg:      #e0e7ff;
  --tag-text:    #3730a3;
  --unread-bar:  #2563eb;
  --highlight:   #fef9c3;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #121212;
    --bg-card:     #1e1e1e;
    --bg-hover:    #252525;
    --bg-tts:      #2a2200;
    --border:      #2e2e2e;
    --text:        #e8e8e3;
    --text-muted:  #a0a09a;
    --text-light:  #6b6b6b;
    --accent:      #60a5fa;
    --accent-dark: #93c5fd;
    --accent-bg:   #172554;
    --danger:      #f87171;
    --danger-bg:   #3f1212;
    --success:     #4ade80;
    --tag-bg:      #1e1b4b;
    --tag-text:    #a5b4fc;
    --unread-bar:  #60a5fa;
    --highlight:   #3a3000;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: none; flex-direction: column; flex: 1; }
.screen.active { display: flex; }

/* ── Setup screen ─────────────────────────────────────────────────────────── */
#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  gap: 1.5rem;
}
.setup-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.setup-box h1 { font-size: 1.6rem; margin-bottom: .25rem; }
.setup-box p  { color: var(--text-muted); margin-bottom: 1.5rem; font-size: .95rem; }
.setup-box label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .4rem; }
.setup-box input {
  width: 100%;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
.setup-box input:focus { border-color: var(--accent); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--accent); color: #fff;
  padding: .65rem 1.25rem;
  border-radius: 7px;
  font-size: .95rem; font-weight: 600;
  transition: background .15s, transform .1s;
  width: 100%; margin-top: 1rem;
}
.btn-primary:hover  { background: var(--accent-dark); }
.btn-primary:active { transform: scale(.98); }

/* ── Top bar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-title { font-weight: 700; font-size: 1.1rem; flex: 1; }
.topbar-actions { display: flex; gap: .5rem; }

.btn-icon {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  font-size: 1.1rem;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

/* ── Add URL bar ──────────────────────────────────────────────────────────── */
.add-bar {
  display: flex; gap: .5rem;
  padding: .75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.add-bar input {
  flex: 1;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
  outline: none;
}
.add-bar input:focus { border-color: var(--accent); }
.btn-save {
  padding: .6rem 1rem;
  background: var(--accent); color: #fff;
  border-radius: 7px;
  font-size: .9rem; font-weight: 600;
  transition: background .15s;
  white-space: nowrap;
}
.btn-save:hover { background: var(--accent-dark); }
.btn-save:disabled { opacity: .55; cursor: not-allowed; }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: .3rem .75rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: .82rem; font-weight: 500;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.filter-chip:hover { background: var(--bg-hover); }
.filter-chip.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* ── Article list ─────────────────────────────────────────────────────────── */
.article-list {
  flex: 1;
  padding: .75rem 1rem;
  display: flex; flex-direction: column; gap: .65rem;
  max-width: 760px; width: 100%; margin: 0 auto;
}

.article-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
  position: relative;
}
.article-card:hover { box-shadow: var(--shadow-md); }
.article-card.unread { border-left: 3px solid var(--unread-bar); }
.article-card.unread .card-title { font-weight: 700; }

.card-meta {
  display: flex; align-items: center; gap: .5rem;
  font-size: .78rem; color: var(--text-muted);
  margin-bottom: .35rem;
}
.card-domain { font-weight: 500; }
.card-dot { opacity: .5; }

.card-title {
  font-size: 1rem; font-weight: 600; color: var(--text);
  margin-bottom: .4rem; line-height: 1.35;
}

.card-summary {
  font-size: .875rem; color: var(--text-muted);
  line-height: 1.55; margin-bottom: .6rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .75rem; }
.tag {
  font-size: .73rem; font-weight: 600;
  padding: .18rem .55rem;
  background: var(--tag-bg); color: var(--tag-text);
  border-radius: 4px;
  cursor: pointer;
  transition: opacity .15s;
}
.tag:hover { opacity: .75; }

.card-actions {
  display: flex; align-items: center; gap: .5rem;
  flex-wrap: wrap;
}
.btn-read {
  padding: .38rem .85rem;
  background: var(--accent-bg); color: var(--accent);
  border-radius: 6px;
  font-size: .85rem; font-weight: 600;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn-read:hover { background: var(--accent); color: #fff; }
.btn-original {
  font-size: .82rem; color: var(--text-muted);
  padding: .38rem .6rem;
  border-radius: 6px;
  transition: background .15s;
}
.btn-original:hover { background: var(--bg-hover); color: var(--text); }
.btn-toggle-read {
  font-size: .82rem; color: var(--text-muted);
  padding: .38rem .6rem;
  border-radius: 6px;
  transition: background .15s;
}
.btn-toggle-read:hover { background: var(--bg-hover); color: var(--text); }
.btn-delete {
  font-size: .82rem; color: var(--danger);
  padding: .38rem .6rem;
  border-radius: 6px;
  margin-left: auto;
  transition: background .15s;
}
.btn-delete:hover { background: var(--danger-bg); }

.read-badge {
  font-size: .72rem; padding: .15rem .5rem;
  background: var(--bg-hover); color: var(--text-light);
  border-radius: 4px; font-weight: 600;
  letter-spacing: .02em;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; flex: 1; gap: .75rem;
  color: var(--text-muted); text-align: center; padding: 3rem 1rem;
}
.empty-state svg { opacity: .3; }
.empty-state p { font-size: .95rem; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #1a1a1a; color: #fff;
  padding: .6rem 1.1rem;
  border-radius: 8px;
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  transition: opacity .25s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden; text-overflow: ellipsis;
}
#toast.hidden { opacity: 0; }
@media (prefers-color-scheme: dark) {
  #toast { background: #333; }
}

/* ── Article view ─────────────────────────────────────────────────────────── */
#article-screen .topbar { gap: .5rem; }
.topbar-back {
  color: var(--accent); font-size: .9rem; font-weight: 600;
  padding: .3rem .5rem; border-radius: 6px;
  transition: background .15s;
  white-space: nowrap;
}
.topbar-back:hover { background: var(--accent-bg); }

.article-wrapper {
  flex: 1; overflow-y: auto;
  padding: 1.25rem 1rem 4rem;
}
.article-content {
  max-width: 680px; margin: 0 auto;
}
.article-header { margin-bottom: 1.5rem; }
.article-header h1 {
  font-size: clamp(1.3rem, 4vw, 1.75rem);
  line-height: 1.25; margin-bottom: .6rem;
}
.article-header-meta {
  display: flex; align-items: center; gap: .5rem;
  font-size: .8rem; color: var(--text-muted);
  flex-wrap: wrap;
}

.article-body {
  font-size: clamp(1rem, 2.5vw, 1.1rem);
  line-height: 1.8;
  color: var(--text);
}
.article-paragraph {
  margin-bottom: 1.2em;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background .2s;
}
.article-paragraph.tts-active {
  background: var(--highlight);
}

/* ── TTS bar ──────────────────────────────────────────────────────────────── */
#tts-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: .65rem 1rem;
  display: none;
  flex-direction: column;
  gap: .5rem;
  z-index: 200;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
#tts-bar.visible { display: flex; }

.tts-row1 { display: flex; align-items: center; gap: .6rem; }
.tts-row2 { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.btn-tts {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 1rem;
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.btn-tts:hover  { background: var(--accent-dark); }
.btn-tts:active { transform: scale(.93); }
.btn-tts.secondary {
  background: var(--bg-hover); color: var(--text);
  border: 1px solid var(--border);
}
.btn-tts.secondary:hover { background: var(--border); }

.tts-progress {
  flex: 1;
  font-size: .8rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.tts-label { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }
.tts-select {
  padding: .25rem .5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: .82rem;
  outline: none;
}

/* ── Loading spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.dark {
  border-color: rgba(0,0,0,.15);
  border-top-color: var(--accent);
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem; z-index: 500;
  color: #fff; font-size: .95rem;
}
#loading-overlay.hidden { display: none; }
#loading-overlay .spinner { width: 32px; height: 32px; border-width: 3px; }

/* ── Share screen ─────────────────────────────────────────────────────────── */
#share-screen {
  align-items: center; justify-content: center;
  padding: 2rem 1.5rem; gap: 1rem;
}
.share-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%; max-width: 400px;
  text-align: center; box-shadow: var(--shadow-md);
}
.share-box h2 { margin-bottom: .5rem; }
.share-box p  { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }
.share-url {
  font-size: .8rem; color: var(--text-light);
  word-break: break-all; margin-bottom: 1rem;
  padding: .5rem; background: var(--bg); border-radius: 6px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .add-bar { padding: .75rem 1.5rem; }
  .filter-bar { padding: .5rem 1.5rem; }
  .article-list { padding: 1rem 1.5rem; }
}
@media (min-width: 900px) {
  .article-list { padding: 1.25rem 2rem; }
}
