/* ── iOS System Tokens ─────────────────────────────────────────── */
:root {
  --bg:            #F2F2F7;
  --surface:       #FFFFFF;
  --surface2:      #EFEFF4;
  --label:         #000000;
  --label2:        rgba(60,60,67,.6);
  --label3:        rgba(60,60,67,.3);
  --tint:          #007AFF;
  --tint-pressed:  #0062CC;
  --sep:           rgba(60,60,67,.29);
  --nav-blur:      rgba(255,255,255,.98);
  --search-fill:   rgba(118,118,128,.12);
  --red:           #FF3B30;
  --font:          -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --font-display:  -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  --nav-h:         calc(env(safe-area-inset-top, 44px) + 52px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #000000;
    --surface:     #1C1C1E;
    --surface2:    #2C2C2E;
    --label:       #FFFFFF;
    --label2:      rgba(235,235,245,.6);
    --label3:      rgba(235,235,245,.3);
    --tint:        #0A84FF;
    --tint-pressed:#409CFF;
    --sep:         rgba(84,84,88,.65);
    --nav-blur:    rgba(28,28,30,.98);
    --search-fill: rgba(118,118,128,.24);
  }
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  margin: 0; padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── App shell ─────────────────────────────────────────────────── */
#app {
  position: relative;
  height: 100%;
  overflow: hidden;
}

/* ── Views & navigation animation ─────────────────────────────── */
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  will-change: transform;
}

.view.active { transform: translateX(0); }
.view.prev   { transform: translateX(-28%); }

/* ── Navigation bar ────────────────────────────────────────────── */
.nav-bar {
  position: relative;
  z-index: 20;
  background: var(--nav-blur);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--sep);
  flex-shrink: 0;
}

/* Large title (list view) */
.nav-bar--large {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding:
    calc(env(safe-area-inset-top, 44px) + 8px)
    16px
    8px;
}

.nav-large-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: .37px;
  line-height: 1;
  color: var(--label);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Article nav bar */
.nav-bar--article {
  display: flex;
  align-items: flex-end;
  padding:
    calc(env(safe-area-inset-top, 44px) + 0px)
    16px
    0;
  min-height: var(--nav-h);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 8px 8px 8px 0;
  margin-bottom: 4px;
  background: none;
  border: none;
  color: var(--tint);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.back-btn:active { opacity: .5; }

.back-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* ── Nav bar actions ───────────────────────────────────────────── */
.nav-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-bottom: 4px;
}

.refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--tint);
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
}

.refresh-btn:active { opacity: .5; }
.refresh-btn svg { width: 22px; height: 22px; }

.refresh-btn.hidden { display: none; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.refresh-btn.spinning svg {
  animation: spin .7s linear infinite;
}

/* ── Offline badge ─────────────────────────────────────────────── */
.offline-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--label2);
  padding: 2px 8px;
  background: var(--surface2);
  border-radius: 20px;
  margin-bottom: 4px;
  letter-spacing: .2px;
}

.offline-badge.hidden { display: none; }

/* ── Search bar ────────────────────────────────────────────────── */
.search-wrapper {
  padding: 8px 16px 8px;
  background: var(--nav-blur);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--sep);
  flex-shrink: 0;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--search-fill);
  border-radius: 10px;
  padding: 7px 10px;
}

.search-icon {
  width: 16px;
  height: 16px;
  color: var(--label3);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--label);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  outline: none;
}

#search-input::placeholder { color: var(--label3); }
#search-input::-webkit-search-decoration,
#search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--label3);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.search-clear.visible { display: block; }
.search-clear:active { opacity: .5; }

/* ── Article list ──────────────────────────────────────────────── */
.article-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px 0 calc(env(safe-area-inset-bottom, 16px) + 16px);
}

.article-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  padding: 13px 16px;
  cursor: pointer;
  border-bottom: .5px solid var(--sep);
  -webkit-user-select: none;
  user-select: none;
}

.article-row:first-child { border-top: .5px solid var(--sep); }

.article-row:active { background: var(--surface2); }

.article-row-body { flex: 1; min-width: 0; }

.article-row-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.4px;
}

.article-row-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.article-row-date {
  font-size: 13px;
  color: var(--label2);
  flex-shrink: 0;
}

.article-row-excerpt {
  font-size: 15px;
  color: var(--label2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.article-row-chevron {
  color: var(--label3);
  flex-shrink: 0;
  width: 8px;
  height: 14px;
}

/* ── Placeholder & error states ─────────────────────────────────── */
.placeholder, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  text-align: center;
  color: var(--label2);
  font-size: 15px;
}

.placeholder-icon, .empty-state-icon {
  width: 48px;
  height: 48px;
  color: var(--label3);
}

.placeholder-icon svg, .empty-state-icon svg {
  width: 100%;
  height: 100%;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--label2);
  letter-spacing: -.3px;
}

/* ── Article reading view ──────────────────────────────────────── */
.article-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 24px 20px calc(env(safe-area-inset-bottom, 24px) + 24px);
}

/* Article typography */
.article-content .article-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: .5px solid var(--sep);
}

.article-content .article-header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.2;
  color: var(--label);
  margin-bottom: 6px;
}

.article-content .article-date {
  font-size: 13px;
  color: var(--label2);
  letter-spacing: .1px;
}

.article-body { color: var(--label); }

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4,
.article-body h5,
.article-body h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -.3px;
  line-height: 1.25;
  margin: 24px 0 8px;
  color: var(--label);
}

.article-body h1 { font-size: 24px; }
.article-body h2 { font-size: 20px; }
.article-body h3 { font-size: 17px; }
.article-body h4, .article-body h5, .article-body h6 { font-size: 15px; }

.article-body p {
  font-size: 17px;
  line-height: 1.65;
  margin: 0 0 16px;
  letter-spacing: -.2px;
}

.article-body a {
  color: var(--tint);
  text-decoration: none;
}

.article-body a:active { opacity: .6; }

.article-body strong { font-weight: 600; }
.article-body em { font-style: italic; }

.article-body ul, .article-body ol {
  margin: 0 0 16px 20px;
}

.article-body li {
  font-size: 17px;
  line-height: 1.65;
  margin-bottom: 4px;
  letter-spacing: -.2px;
}

.article-body blockquote {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-left: 3px solid var(--tint);
  background: var(--surface2);
  border-radius: 0 8px 8px 0;
  color: var(--label2);
  font-size: 17px;
  line-height: 1.65;
}

.article-body code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  background: var(--surface2);
  color: var(--red);
  padding: 2px 5px;
  border-radius: 5px;
}

.article-body pre {
  background: var(--surface2);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 16px;
}

.article-body pre code {
  background: none;
  padding: 0;
  color: var(--label);
  font-size: 13px;
  line-height: 1.6;
}

.article-body hr {
  border: none;
  border-top: .5px solid var(--sep);
  margin: 24px 0;
}

.article-body img {
  max-width: 100%;
  border-radius: 10px;
  margin: 8px 0 16px;
}

/* ── Match count badge ──────────────────────────────────────────── */
.match-count {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--tint);
  background: color-mix(in srgb, var(--tint) 12%, transparent);
  border-radius: 20px;
  padding: 1px 6px;
  letter-spacing: .2px;
  white-space: nowrap;
}

/* ── Search highlight ───────────────────────────────────────────── */
mark {
  background: #FFD60A;
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

@media (prefers-color-scheme: dark) {
  mark {
    background: #F4B800;
    color: #000;
  }
}

/* ── Swipe gesture hint line ─────────────────────────────────────── */
.view.dragging { transition: none !important; }
