/* style.css */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-read: "Lora", Georgia, 'Times New Roman', serif;
  --font-display: "DM Serif Display", Georgia, serif;
}

[data-theme="dark"] {
  --bg: #0f0e0c;
  --bg-elev: #1a1814;
  --bg-card: #232019;
  --border: #332e26;
  --text: #e8e2d5;
  --text-dim: #a39e92;
  --text-faint: #6e6a60;
  --accent: #d4a857;
  --accent-hover: #e6bd6a;
  --accent-soft: rgba(212, 168, 87, 0.12);
  --star: #f0c050;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --hover: rgba(255,255,255,0.04);
}

[data-theme="light"] {
  --bg: #faf8f3;
  --bg-elev: #fff;
  --bg-card: #f7f4ee;
  --border: #ddd6ca;
  --text: #2a2620;
  --text-dim: #6b655a;
  --text-faint: #9a958a;
  --accent: #a8761a;
  --accent-hover: #c08820;
  --accent-soft: rgba(168, 118, 26, 0.08);
  --star: #d4a020;
  --shadow: 0 4px 24px rgba(0,0,0,0.06);
  --hover: rgba(0,0,0,0.02);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

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

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 10;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px; letter-spacing: -0.01em;
  color: var(--text); white-space: nowrap;
}
.brand-icon { width: 22px; height: 22px; color: var(--accent); }

.search-wrap { flex: 1; position: relative; max-width: 520px; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-faint); pointer-events: none;
}
#search {
  width: 100%; padding: 10px 14px 10px 38px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 14px;
  font-family: var(--font-ui); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#search::placeholder { color: var(--text-faint); }

.controls { display: flex; align-items: center; gap: 10px; }
#sort {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 13px;
  font-family: var(--font-ui); cursor: pointer; outline: none; min-height: 44px;
}
#sort:focus { border-color: var(--accent); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text-dim); cursor: pointer;
  transition: all 0.15s; flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small { width: 36px; height: 36px; font-size: 13px; font-weight: 600; }

/* Layout */
.layout { display: grid; grid-template-columns: 340px 1fr; flex: 1; overflow: hidden; min-height: 0; }

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border); background: var(--bg-elev);
  overflow-y: auto; display: flex; flex-direction: column;
}

/* ─── PATHWAY VISUALIZATION ─── */
.pathway-container {
  padding: 16px 20px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.pathway-header {
  text-align: center;
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.pathway-glow {
  color: var(--accent);
  font-size: 10px;
  animation: glow-pulse 3s ease-in-out infinite;
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.pathway-group {
  position: relative;
  padding: 8px 0 12px;
}
.pathway-group-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 6px;
  padding-left: 4px;
  position: relative; z-index: 2;
}
.pathway-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--path-color, var(--accent));
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--path-color, var(--accent));
  opacity: 0.6;
}

.pathway-nodes {
  position: relative;
  padding-left: 12px;
}
.pathway-node {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0;
  position: relative; z-index: 2;
  cursor: default;
}
.pathway-node-missing { opacity: 0.35; }
.pathway-node .pathway-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--path-color, var(--accent));
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.3s, transform 0.3s;
  position: relative;
}
.pathway-node:last-child .pathway-dot::after {
  content: '';
  position: absolute;
  left: 50%; bottom: 0;
  width: 1px; height: 6px;
  background: var(--path-color, var(--accent));
  transform: translateX(-50%);
  opacity: 0.3;
}
.pathway-node:first-child .pathway-dot { margin-top: 0; }

.pathway-label {
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  line-height: 1.35;
  transition: color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pathway-label:hover { color: var(--accent); }
.pathway-label:visited { color: var(--accent); }

.explore-check {
  font-size: 10px;
  color: var(--accent);
  margin-left: auto;
  opacity: 0.7;
  flex-shrink: 0;
}

/* List area below pathway */
.list-meta {
  padding: 10px 20px; font-size: 12px; color: var(--text-faint);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  position: sticky; top: 0; background: var(--bg-elev); z-index: 2;
}
.essay-list { flex: 1; overflow-y: auto; padding: 6px 0; }

.year-header {
  padding: 16px 20px 6px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; color: var(--text-faint); text-transform: uppercase;
  position: sticky; top: 0; background: var(--bg-elev); z-index: 1;
}

.essay-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 20px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.essay-item:hover { background: var(--hover); }
.essay-item.active {
  background: var(--accent-soft); border-left-color: var(--accent);
}

.fav-btn {
  flex-shrink: 0; width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; border-radius: 6px; margin-top: -2px; transition: color 0.15s;
}
.fav-btn:hover { color: var(--star); }
.fav-btn .star { width: 18px; height: 18px; }
.fav-btn .star.filled { color: var(--star); }

.essay-main { flex: 1; min-width: 0; }
.essay-title {
  font-size: 14px; line-height: 1.4; color: var(--text); font-weight: 500;
}
.essay-snippet {
  margin-top: 3px; font-size: 12px; line-height: 1.45; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: break-word;
}
.essay-snippet mark {
  background: var(--accent-soft); color: var(--accent); border-radius: 2px; padding: 0 1px;
}
.essay-year { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.essay-item.active .essay-title { color: var(--accent); font-weight: 600; }

/* Loading / empty states */
.loading-state, .empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 60px 20px; color: var(--text-faint); text-align: center;
}
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-link {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 14px; text-decoration: underline; font-family: var(--font-ui);
}

/* Reader */
.reader { overflow-y: auto; position: relative; background: var(--bg); scroll-behavior: smooth; }

.progress-bar {
  position: sticky; top: 0; left: 0; right: 0; height: 3px; background: transparent; z-index: 20;
}
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.1s; }

.reader-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; color: var(--text-faint); gap: 16px; padding: 40px;
}
.reader-empty svg { width: 56px; height: 56px; opacity: 0.4; }
.reader-empty h2 { font-family: var(--font-display); font-size: 22px; color: var(--text-dim); font-weight: 400; }
.reader-empty p { font-size: 15px; max-width: 320px; }

.reader-content {
  max-width: 720px; margin: 0 auto; padding: 0 32px 80px;
}

.reader-header {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 28px 0 20px; border-bottom: 1px solid var(--border);
  margin-bottom: 28px; position: sticky; top: 3px;
  background: var(--bg); z-index: 15;
}
.reader-back { display: none; }

.reader-title-wrap { flex: 1; min-width: 0; }
.reader-title {
  font-family: var(--font-read); font-size: 28px; font-weight: 700;
  line-height: 1.25; color: var(--text); letter-spacing: -0.01em;
}
.reader-year {
  display: inline-block; margin-top: 6px; font-size: 12px;
  color: var(--text-faint); font-family: var(--font-ui);
}
.reader-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.font-controls { display: flex; gap: 4px; }
.fav-toggle .star { width: 20px; height: 20px; }
.fav-toggle .star.filled { color: var(--star); }
.external-link { text-decoration: none; }

.essay-body {
  font-family: var(--font-read); line-height: 1.75; color: var(--text); font-size: 18px;
}
.essay-body p { margin-bottom: 1.25em; }
.essay-body h1, .essay-body h2, .essay-body h3 {
  font-family: var(--font-read); margin: 1.5em 0 0.6em; line-height: 1.3;
}
.essay-body h1 { font-size: 1.5em; }
.essay-body h2 { font-size: 1.25em; }
.essay-body h3 { font-size: 1.1em; }
.essay-body a { color: var(--accent); text-decoration: underline; }
.essay-body img { max-width: 100%; height: auto; border-radius: 4px; margin: 1em 0; }
.essay-body blockquote {
  border-left: 3px solid var(--accent); padding-left: 1em;
  margin: 1.25em 0; color: var(--text-dim); font-style: italic;
}
.essay-body ul, .essay-body ol { margin: 1em 0 1.25em 1.5em; }
.essay-body li { margin-bottom: 0.5em; }
.essay-body pre { background: var(--bg-card); padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 0.9em; }
.essay-body code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.essay-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.essay-body table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.essay-body td, .essay-body th { padding: 8px 12px; border: 1px solid var(--border); }
.essay-body font { font-size: inherit !important; color: inherit !important; }

.reader-loading, .reader-error {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 18px; padding: 80px 20px;
  text-align: center; color: var(--text-dim);
}
.reader-error a { color: var(--accent); }

.btn-primary {
  display: inline-block; padding: 12px 24px; background: var(--accent);
  color: #1a1a1a; border: none; border-radius: 10px; font-size: 14px;
  font-weight: 600; text-decoration: none; font-family: var(--font-ui);
  cursor: pointer; min-height: 44px;
}
.btn-primary:hover { background: var(--accent-hover); }

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Notice */
.notice {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card); color: var(--text);
  padding: 14px 20px; border-radius: 10px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  font-size: 13px; max-width: 90vw; text-align: center;
  opacity: 0; transition: all 0.3s; z-index: 100;
}
.notice.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Responsive */
@media (max-width: 768px) {
  .topbar { padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .brand { font-size: 14px; }
  .brand-icon { width: 20px; height: 20px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  #sort { padding: 8px 10px; font-size: 12px; min-height: 40px; }
  .icon-btn { width: 40px; height: 40px; }

  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  body.reading .sidebar { display: none; }
  body.reading .reader { display: block; }
  body:not(.reading) .reader { display: none; }

  .reader-back { display: inline-flex; }
  .reader-content { padding: 0 16px 60px; }
  .reader-header { padding: 18px 0 16px; }
  .reader-title { font-size: 22px; }
  .essay-body { font-size: 16px; line-height: 1.7; }
}

@media (max-width: 400px) {
  .topbar { padding: 8px 10px; }
  .reader-content { padding: 0 14px 50px; }
  .essay-list { padding: 4px 0; }
  .essay-item { padding: 10px 14px; }
  .list-meta { padding: 8px 14px; }
  .year-header { padding: 14px 14px 4px; }
  .pathway-container { padding: 12px 14px 6px; }
  .pathway-label { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .reader { scroll-behavior: auto; }
}

/* Scrollbar styling */
.sidebar::-webkit-scrollbar, .reader::-webkit-scrollbar, .essay-list::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track, .reader::-webkit-scrollbar-track, .essay-list::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb, .reader::-webkit-scrollbar-thumb, .essay-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.sidebar::-webkit-scrollbar-thumb:hover, .reader::-webkit-scrollbar-thumb:hover, .essay-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

