*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --surface: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e5e7eb;
  --me-bg: #eff6ff;
  --me-code-bg: #dbeafe;
  --me-code-border: #bfdbfe;
  --sans: system-ui, -apple-system, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
  --mono: 'Courier New', Courier, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --text: #f9fafb;
    --muted: #9ca3af;
    --accent: #60a5fa;
    --border: #374151;
    --me-bg: #1e3a5f;
    --me-code-bg: #1e3a8a;
    --me-code-border: #3b82f6;
  }
}

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  margin: 0;
}

/* ── Header ── */
header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

nav {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-family: var(--sans);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.025em;
}

.site-title:hover { color: var(--accent); }

.site-subtitle {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
  letter-spacing: 0;
}

.visitor-count {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

.visitor-count:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Main ── */
main {
  max-width: 740px;
  margin: 3rem auto;
  padding: 0 1.5rem;
}

/* ── Post list ── */
article.preview {
  margin-bottom: 3rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--border);
}

article.preview:last-child { border-bottom: none; }

article.preview h2 {
  font-family: var(--sans);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.375rem;
  letter-spacing: -0.025em;
}

article.preview h2 a { color: var(--text); text-decoration: none; }
article.preview h2 a:hover { color: var(--accent); }

time {
  display: block;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

article.preview p { color: var(--muted); margin: 0 0 1rem; }

.read-more {
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.read-more:hover { text-decoration: underline; }

/* ── Single post ── */
article h1 {
  font-family: var(--sans);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin: 0 0 0.5rem;
  letter-spacing: -0.03em;
}

.content { margin-top: 1.5rem; }
.content p { margin: 0 0 1.25rem; }

.content h2 {
  font-family: var(--sans);
  font-size: 1.375rem;
  font-weight: 700;
  margin: 2rem 0 0.75rem;
  letter-spacing: -0.02em;
}

.content h3 {
  font-family: var(--sans);
  font-size: 1.125rem;
  font-weight: 700;
  margin: 1.5rem 0 0.5rem;
}

.content ul, .content ol { padding-left: 1.5rem; margin: 0 0 1.25rem; }
.content li { margin-bottom: 0.375rem; }

.content code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.content pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

.content pre code { background: none; border: none; padding: 0; color: inherit; }

.content blockquote {
  border-left: 4px solid var(--border);
  padding: 0.5rem 0 0.5rem 1.25rem;
  margin: 1.5rem 0;
  color: var(--muted);
  font-style: italic;
}

.content a { color: var(--accent); }

.back {
  display: inline-block;
  margin-top: 3rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: none;
}

.back:hover { color: var(--text); }

.empty, .error { color: var(--muted); font-style: italic; }

/* ── Leaderboard ── */
.lb-header { margin-bottom: 2rem; }

.lb-header h1 {
  font-family: var(--sans);
  font-size: 2rem;
  font-weight: 800;
  margin: 0 0 0.5rem;
  letter-spacing: -0.03em;
}

.subtitle {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.95rem;
  margin: 0;
}

.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9rem;
}

.leaderboard th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0.6rem 1rem;
  border-bottom: 2px solid var(--border);
}

.leaderboard td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.leaderboard tbody tr:last-child td { border-bottom: none; }

.leaderboard tbody tr:hover td { background: var(--surface); }

.rank {
  color: var(--muted);
  font-size: 0.8rem;
  width: 3rem;
}

.visitor code {
  font-family: var(--mono);
  font-size: 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.15em 0.5em;
  border-radius: 4px;
}

.visits {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  width: 6rem;
}

.bar-cell { width: 40%; }

.bar-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bar-wrap {
  flex: 1;
  background: var(--border);
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
}

.bar-fill {
  height: 8px;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.pct {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--mono);
  min-width: 3.5rem;
}

/* ── Your name banner ── */
.your-name {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.75rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
}

.your-name code {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.15em 0.5em;
  border-radius: 4px;
}

.change-link {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.change-link:hover { color: var(--accent); }

/* Separator row between top 10 and user's out-of-range row */
.leaderboard tr.separator td {
  text-align: center;
  padding: 0.375rem;
  color: var(--muted);
  letter-spacing: 0.2em;
  border-bottom: 1px dashed var(--border);
  border-top: 1px dashed var(--border);
}

/* Highlighted row for current visitor */
.leaderboard tbody tr.me td { background: var(--me-bg); }
.leaderboard tbody tr.me .visitor code {
  color: var(--accent);
  border-color: var(--me-code-border);
  background: var(--me-code-bg);
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 2rem 1.5rem;
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
}
