:root {
  --max-width: 720px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  --bg: #ffffff;
  --bg-subtle: #f6f6f7;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --selection: #dbeafe;
}

:root[data-theme="dark"] {
  --bg: #111113;
  --bg-subtle: #1a1a1d;
  --text: #e8e8ea;
  --text-muted: #9a9aa3;
  --border: #2a2a2e;
  --accent: #6ea8fe;
  --accent-hover: #93bbff;
  --selection: #1e3a5f;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--selection);
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 40px 0 0;
}

.site-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.site-title a {
  color: var(--text);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 16px;
  transition: color 0.15s ease;
}

.site-nav a:hover {
  color: var(--text);
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  padding: 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.theme-toggle:hover {
  background: var(--bg-subtle);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* Layout */
main {
  padding: 0 0 80px;
}

/* Article reading view: no site header, just content */
main.reading {
  padding-top: 44px;
}

.intro {
  color: var(--text-muted);
  font-size: 16px;
  margin: 0 0 40px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--border);
}

/* Post list */
.section-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-list li {
  margin: 0;
}

.post-card {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 22px 20px;
  margin: 0 -20px;
  border-radius: 12px;
  transition: background 0.15s ease;
}

.post-card:hover {
  background: var(--bg-subtle);
}

.post-card-title {
  display: block;
  color: var(--text);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: color 0.15s ease;
}

.post-card-title::after {
  content: "\2192";
  display: inline-block;
  margin-left: 8px;
  color: var(--accent);
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

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

.post-card:hover .post-card-title::after {
  opacity: 1;
  transform: translateX(0);
}

.post-meta {
  display: block;
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.post-excerpt {
  display: block;
  color: var(--text-muted);
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 1.6;
}

/* Article */
article h1 {
  font-size: 34px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.article-meta {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 40px;
}

article p {
  margin: 0 0 24px;
}

article h2 {
  font-size: 24px;
  letter-spacing: -0.01em;
  margin: 48px 0 16px;
}

article h3 {
  font-size: 20px;
  margin: 36px 0 12px;
}

article a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

article a:hover {
  color: var(--accent-hover);
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
}

article blockquote {
  margin: 24px 0;
  padding: 4px 20px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
  font-style: italic;
}

article code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 5px;
}

article pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  overflow-x: auto;
  font-size: 15px;
  line-height: 1.5;
}

article pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 48px 0;
}

article ul,
article ol {
  padding-left: 24px;
  margin: 0 0 24px;
}

article li {
  margin-bottom: 8px;
}

.back-link {
  display: inline-block;
  margin-bottom: 40px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 15px;
}

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

/* Audio player */
.audio-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  margin: 0 0 40px;
}

.audio-toggle {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.audio-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.audio-toggle svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.audio-speed {
  flex: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 3px 7px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.audio-speed:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Word highlighting synced to narration */
.w {
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s ease;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.w.is-active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.audio-toggle .icon-pause {
  display: none;
}

.audio-player.playing .icon-play {
  display: none;
}

.audio-player.playing .icon-pause {
  display: inline;
}

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

.audio-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.audio-progress {
  height: 3px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}

.audio-bar {
  height: 100%;
  width: 0;
  background: var(--text-muted);
  border-radius: 3px;
}

.audio-time {
  flex: none;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 32px 0 48px;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--text);
}

@media (max-width: 600px) {
  body {
    font-size: 17px;
  }
  article h1 {
    font-size: 28px;
  }
  .site-header {
    padding-top: 28px;
  }
  .site-title {
    font-size: 22px;
  }
  main.reading {
    padding-top: 28px;
  }
}
