/* ── Light theme (default) ── */
:root {
  --bg: #fafafa;
  --text: #1a1a1a;
  --text-2: #555;
  --text-3: #888;
  --border: #e8e8e8;
  --accent: #2563eb;
  --quote-bg: #f5f5f5;
  --quote-border: #d0d0d0;
  --stripe: #f9f9f9;
}

/* ── Dark theme ── */
[data-theme="dark"] {
  --bg: #111; --text: #e5e5e5; --text-2: #aaa; --text-3: #666;
  --border: #2a2a2a; --accent: #60a5fa;
  --quote-bg: #1e1e1e; --quote-border: #444; --stripe: #1e1e1e;
}

/* ── Auto: follow system ── */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #111; --text: #e5e5e5; --text-2: #aaa; --text-3: #666;
    --border: #2a2a2a; --accent: #60a5fa;
    --quote-bg: #1e1e1e; --quote-border: #444; --stripe: #1e1e1e;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif;
  font-size: 16px; line-height: 1.7; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
  max-width: 680px; margin: 0 auto; padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
}

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed; top: 16px; right: 16px;
  background: var(--quote-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px;
  font-size: 14px; color: var(--text-2);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  z-index: 100; line-height: 1;
}
.theme-toggle:active { opacity: 0.6; }

/* ── Index ── */
.index-header { padding: 40px 0 20px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.index-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.index-header p { color: var(--text-3); font-size: 14px; margin-top: 2px; }
.date-label { font-size: 13px; font-weight: 600; color: var(--text-3); padding: 16px 0 6px; letter-spacing: 0.3px; }
a.item { display: block; padding: 12px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; -webkit-tap-highlight-color: rgba(0,0,0,0.05); }
a.item:active { opacity: 0.5; }
.item-title { font-size: 16px; font-weight: 600; line-height: 1.4; }
.item-meta { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.item-meta .src { color: var(--text-2); }

/* ── Article ── */
a.back { display: inline-block; padding: 16px 0; font-size: 14px; color: var(--accent); text-decoration: none; }
a.back:active { opacity: 0.5; }
article { padding-bottom: 60px; }
article > h1 { font-size: 22px; font-weight: 700; line-height: 1.3; margin: 12px 0 6px; letter-spacing: -0.3px; }
.meta { font-size: 13px; color: var(--text-3); margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.meta a { color: var(--accent); text-decoration: none; }

article h2 { font-size: 18px; font-weight: 700; margin: 28px 0 10px; letter-spacing: -0.2px; }
article h3 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }
article h4 { font-size: 15px; font-weight: 600; margin: 16px 0 6px; }
article p { margin: 10px 0; }
article ul, article ol { margin: 10px 0; padding-left: 24px; }
article li { margin: 5px 0; }
article li > ul, article li > ol { margin: 4px 0; }
article blockquote {
  background: var(--quote-bg); border-left: 3px solid var(--quote-border);
  padding: 10px 14px; margin: 14px 0; font-size: 14px; color: var(--text-2); border-radius: 4px;
}
article blockquote p { margin: 3px 0; }
article table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14px; }
article th, article td { padding: 8px 10px; border: 1px solid var(--border); text-align: left; }
article th { font-weight: 600; background: var(--quote-bg); white-space: nowrap; }
article tr:nth-child(even) { background: var(--stripe); }
article strong { font-weight: 600; }
article em { font-style: italic; }
article a { color: var(--accent); text-decoration: none; }
article a:hover { text-decoration: underline; }
article code { font-size: 14px; background: var(--quote-bg); padding: 1px 5px; border-radius: 3px; font-family: "SF Mono", Menlo, monospace; }
article pre { background: var(--quote-bg); padding: 12px 14px; border-radius: 6px; overflow-x: auto; margin: 14px 0; }
article pre code { padding: 0; background: none; }
article hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
article img { max-width: 100%; height: auto; border-radius: 4px; }

/* ── Pagination ── */
.pagination {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 0; margin-top: 8px; border-top: 1px solid var(--border);
}
.pagination a { color: var(--accent); text-decoration: none; font-size: 14px; }
.pagination a:active { opacity: 0.5; }
.page-info { font-size: 13px; color: var(--text-3); }

@media (max-width: 600px) {
  article table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
