:root {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-muted: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 4px 24px rgba(15, 23, 42, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --sidebar-w: 240px;
  --content-max: 780px;
  --font-sans: "Inter", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --bg-muted: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #1e293b;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: #1e3a5f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] #hljs-light { display: none; }
[data-theme="dark"] #hljs-dark { display: block; }
[data-theme="light"] #hljs-light,
:root:not([data-theme]) #hljs-light { display: block; }
[data-theme="light"] #hljs-dark,
:root:not([data-theme]) #hljs-dark { display: none; }

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.125rem;
}

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

.brand-icon { border-radius: 6px; }

.header-actions { display: flex; align-items: center; gap: 0.5rem; }

.icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.calendar-dropdown {
  position: relative;
}

.calendar-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: min(320px, calc(100vw - 2rem));
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.75rem;
}

.calendar-panel[hidden] {
  display: none !important;
}

.calendar-panel .calendar {
  border: none;
  box-shadow: none;
  padding: 0.25rem;
}

.calendar-panel .calendar-legend {
  display: flex;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-muted);
  color: var(--text);
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun,
:root:not([data-theme]) .icon-sun { display: none; }
[data-theme="light"] .icon-moon,
:root:not([data-theme]) .icon-moon { display: block; }

/* Main */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.view[hidden] { display: none !important; }

/* Loading & Error */
.loading[hidden] {
  display: none !important;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 1rem;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  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); } }

.error-panel {
  padding: 1.25rem 1.5rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: #b91c1c;
}

[data-theme="dark"] .error-panel {
  background: #450a0a;
  border-color: #7f1d1d;
  color: #fca5a5;
}

/* Home View */
.home-hero {
  text-align: center;
  padding: 2rem 0 2.5rem;
}

.home-hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.home-hero p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.latest-card {
  background: linear-gradient(135deg, var(--accent) 0%, #1e40af 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-lg);
  text-decoration: none;
  display: block;
  transition: transform 0.15s, box-shadow 0.15s;
}

.latest-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(37, 99, 235, 0.35);
  color: #fff;
}

.latest-label {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
  margin-bottom: 0.5rem;
}

.latest-date {
  font-size: 0.9rem;
  opacity: 0.9;
  margin-bottom: 0.75rem;
}

.latest-headline {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.5;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

/* Daily one-liner list */
.daily-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 2.5rem;
}

.daily-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.875rem 1.25rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.daily-row:last-child {
  border-bottom: none;
}

.daily-row:hover {
  background: var(--bg-muted);
}

.daily-row:hover .daily-date {
  color: var(--accent);
}

.daily-date {
  flex-shrink: 0;
  width: 10.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.daily-summary {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.daily-list-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  margin: 0;
}

.date-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.date-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
}

.date-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
}

.date-card.is-latest {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 40%, var(--bg-elevated));
}

.date-card-date {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.date-card-headline {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tools-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background: var(--bg-muted);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.tool-chip img {
  width: 18px;
  height: 18px;
}

/* Calendar */
.calendar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.calendar-title {
  font-weight: 600;
  font-size: 1rem;
}

.cal-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cal-nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.35rem;
}

.calendar-weekdays {
  margin-bottom: 0.35rem;
}

.cal-weekday {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.25rem 0;
}

.cal-day {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-height: 36px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.12s;
}

.cal-day--pad {
  visibility: hidden;
  pointer-events: none;
}

.cal-day--disabled {
  opacity: 0.35;
  cursor: default;
}

.cal-day--has-summary {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

a.cal-day--has-summary:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}

.cal-day--today {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cal-day--selected {
  background: var(--accent) !important;
  color: #fff !important;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.calendar-legend {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.cal-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.cal-legend-dot--summary {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}

.cal-legend-dot--today {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: transparent;
}

.calendar--compact {
  padding: 0.875rem;
  margin-top: 1rem;
}

.calendar--compact .calendar-title {
  font-size: 0.875rem;
}

.calendar--compact .cal-day {
  min-height: 28px;
  font-size: 0.75rem;
}

.calendar--compact .calendar-legend {
  display: none;
}

/* Day View */
.day-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 2rem;
  align-items: start;
}

.day-sidebar {
  position: sticky;
  top: calc(var(--header-h) + 1.5rem);
}

.day-meta {
  margin-bottom: 1.25rem;
}

.day-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 0.75rem;
}

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

.day-title {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.day-headline {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.nav-sections {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-sections a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}

.nav-sections a:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.nav-sections a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-sections a img {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.75rem 0.875rem 0.25rem;
}

.day-content {
  min-width: 0;
}

.insight-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.insight-card {
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-size: 0.875rem;
}

.insight-card strong {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.markdown-body {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  box-shadow: var(--shadow);
  max-width: var(--content-max);
}

/* Markdown typography */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--text);
  font-weight: 600;
  line-height: 1.35;
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

.markdown-body h1 {
  font-size: 1.75rem;
  margin: 0 0 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.markdown-body h2 {
  font-size: 1.35rem;
  margin: 2rem 0 0.875rem;
}

.markdown-body h3 {
  font-size: 1.1rem;
  margin: 1.5rem 0 0.75rem;
}

.markdown-body h4 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }

.markdown-body p { margin: 0 0 1rem; }

.markdown-body > blockquote,
.markdown-body blockquote {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 1rem;
  padding-left: 1.5rem;
}

.markdown-body li { margin-bottom: 0.35rem; }

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

.markdown-body a:hover { color: var(--accent-hover); }

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-muted);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.markdown-body pre {
  margin: 0 0 1.25rem;
  padding: 1rem 1.25rem;
  background: #0d1117;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

[data-theme="light"] .markdown-body pre,
:root:not([data-theme]) .markdown-body pre {
  background: #f6f8fa;
  border: 1px solid var(--border);
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  display: block;
  overflow-x: auto;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.625rem 0.875rem;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-muted);
  font-weight: 600;
}

.markdown-body tr:nth-child(even) td {
  background: color-mix(in srgb, var(--bg-muted) 50%, transparent);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* Mobile nav */
.mobile-nav {
  display: none;
  position: sticky;
  top: var(--header-h);
  z-index: 50;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 0.35rem;
}

.mobile-nav::-webkit-scrollbar { display: none; }

.mobile-nav a {
  flex-shrink: 0;
  padding: 0.5rem 0.875rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-secondary);
  background: var(--bg-muted);
  white-space: nowrap;
}

.mobile-nav a.active {
  background: var(--accent);
  color: #fff;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.site-footer code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-muted);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* Responsive */
@media (max-width: 860px) {
  .day-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .day-sidebar {
    position: static;
  }

  .day-sidebar .nav-sections,
  .day-sidebar .nav-group-label {
    display: none;
  }

  .sidebar-calendar {
    margin: 0 -0.25rem 1rem;
  }

  .sidebar-calendar .calendar--compact .calendar-legend {
    display: flex;
  }

  .mobile-nav {
    display: flex;
    margin: 0 -1.25rem 1rem;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  .markdown-body {
    padding: 1.25rem 1rem;
    border-radius: var(--radius-sm);
  }
}

@media (max-width: 480px) {
  .main { padding: 1rem 1rem 2rem; }
  .daily-row {
    flex-direction: column;
    gap: 0.35rem;
    align-items: flex-start;
  }
  .daily-date { width: auto; }
  .calendar-panel {
    position: fixed;
    top: calc(var(--header-h) + 0.5rem);
    right: 1rem;
    left: 1rem;
    width: auto;
  }
}
