:root {
  color-scheme: light;
  --canvas: #ebe9e4;
  --sidebar: #e2e0db;
  --surface: #f7f6f2;
  --surface-hover: #fffefa;
  --ink: #20201e;
  --secondary: #777570;
  --tertiary: #a4a19a;
  --line: rgb(37 36 33 / 9%);
  --selected: rgb(255 255 255 / 58%);
  --accent: #df633a;
  --accent-soft: #f3d8ca;
  --shadow: 0 18px 44px rgb(41 38 31 / 10%);
  --sidebar-width: 264px;
  --content-width: 760px;
  --sans: ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "SF Pro Text", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #181817;
  --sidebar: #20201f;
  --surface: #262625;
  --surface-hover: #2d2d2b;
  --ink: #f3f1eb;
  --secondary: #aaa7a0;
  --tertiary: #74716c;
  --line: rgb(255 255 255 / 8%);
  --selected: rgb(255 255 255 / 8%);
  --accent: #ed7a50;
  --accent-soft: #533227;
  --shadow: 0 18px 44px rgb(0 0 0 / 24%);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; margin: 0; overflow: hidden; }
button, input { color: inherit; font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

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

svg {
  width: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--surface);
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: max(22px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.sidebar-top {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 720;
  letter-spacing: -0.035em;
  text-decoration: none;
}

.brand-mark {
  display: flex;
  width: 28px;
  height: 28px;
  align-items: end;
  justify-content: center;
  gap: 2px;
  padding: 6px;
  border-radius: 9px;
  background: var(--accent);
}
.brand-mark span { width: 3px; border-radius: 3px; background: white; }
.brand-mark span:nth-child(1) { height: 8px; }
.brand-mark span:nth-child(2) { height: 15px; }
.brand-mark span:nth-child(3) { height: 11px; }

.round-button {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.round-button:hover { background: var(--selected); }
.round-button svg { width: 20px; }

.sidebar-close,
.mobile-only { display: none; }

.library-nav { display: grid; gap: 3px; }

.library-item {
  display: grid;
  grid-template-columns: 25px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 43px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 570;
  text-align: left;
}
.library-item:hover { background: rgb(255 255 255 / 28%); color: var(--ink); }
.library-item.is-active {
  background: var(--selected);
  box-shadow: 0 1px 1px rgb(0 0 0 / 3%);
  color: var(--ink);
}
.library-item svg { width: 20px; }

.item-count {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgb(128 125 117 / 13%);
  color: var(--secondary);
  font-size: 11px;
  text-align: center;
}

.source-section {
  min-height: 0;
  margin-top: 26px;
  overflow: hidden;
}

.source-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 9px;
  color: var(--tertiary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .035em;
  text-transform: uppercase;
}
.source-heading button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 10px;
  font-weight: 650;
  text-transform: none;
}

.source-list {
  display: grid;
  max-height: calc(100vh - 405px);
  gap: 2px;
  overflow-y: auto;
  scrollbar-width: none;
}
.source-list::-webkit-scrollbar { display: none; }

.source-item {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 9px;
  align-items: center;
  min-height: 43px;
  padding: 4px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
}
.source-item:hover,
.source-item.is-active { background: var(--selected); }
.source-dot {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font: italic 700 14px var(--serif);
  box-shadow: inset 0 0 0 1px var(--line);
}
.source-item span:last-child {
  overflow: hidden;
  font-size: 12px;
  font-weight: 560;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-bottom {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding: 16px 7px 0;
  border-top: 1px solid var(--line);
}
.sidebar-setting {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 12px;
  text-align: left;
}
.sidebar-setting svg { width: 18px; }
#theme-label { color: var(--tertiary); }
.sync-status {
  display: flex;
  gap: 7px;
  align-items: center;
  margin: 0 4px;
  color: var(--tertiary);
  font-size: 10px;
}
.sync-status span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #62a36c;
  box-shadow: 0 0 0 3px rgb(98 163 108 / 13%);
}

.timeline-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.timeline-header {
  position: absolute;
  z-index: 10;
  inset: 0 0 auto;
  display: flex;
  height: 92px;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) max(24px, calc((100% - var(--content-width)) / 2));
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--canvas) 85%, transparent);
  backdrop-filter: blur(28px) saturate(1.25);
}
.timeline-header.is-scrolled { border-color: var(--line); }

.timeline-title p {
  margin: 0 0 2px;
  color: var(--secondary);
  font-size: 10px;
  font-weight: 650;
}
.timeline-title h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 740;
  letter-spacing: -.045em;
  line-height: 1;
}

.header-actions { display: flex; gap: 3px; }

.timeline {
  height: 100vh;
  padding: 110px max(24px, calc((100% - var(--content-width)) / 2)) 80px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.timeline-marker {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  margin: 0 3px 7px;
  color: var(--tertiary);
  font-size: 10px;
  font-weight: 600;
}
.timeline-marker button {
  padding: 5px 9px;
  border: 0;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
}

.story-list { display: grid; gap: 10px; }
.day-label {
  position: sticky;
  z-index: 2;
  top: -18px;
  width: max-content;
  margin: 16px 0 2px 4px;
  padding: 5px 9px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--canvas) 89%, transparent);
  color: var(--secondary);
  font-size: 10px;
  font-weight: 700;
  backdrop-filter: blur(12px);
}

.story {
  position: relative;
  padding: 17px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 1px 1px rgb(36 34 29 / 2%);
  cursor: pointer;
  transition: background 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}
.story:hover {
  background: var(--surface-hover);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.story-source {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  color: var(--secondary);
  font-size: 10px;
}
.source-avatar {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 7px;
  background: #b22b2b;
  color: white;
  font: 700 7px/1 var(--serif);
}
.source-name { color: var(--ink); font-weight: 650; }
.story-date::before { margin-right: 7px; content: "·"; }
.audio-badge { display: inline-grid; margin-left: auto; place-items: center; color: var(--accent); }
.audio-badge[hidden] { display: none; }
.audio-badge svg { width: 17px; }

.story-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 18px;
  align-items: start;
  margin-top: 11px;
}
.story-copy { min-width: 0; }
.story h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: 1.08;
}
.story-summary {
  display: -webkit-box;
  margin: 8px 0 0;
  overflow: hidden;
  color: var(--secondary);
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.38;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.story-author {
  margin: 9px 0 0;
  color: var(--secondary);
  font-size: 10px;
  font-weight: 590;
}

.story-image-wrap {
  position: relative;
  width: 128px;
  aspect-ratio: 1.38;
  overflow: hidden;
  border-radius: 12px;
  background: var(--accent-soft);
}
.story-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.story-image:not([src]) { display: none; }
.image-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
  font: italic 38px var(--serif);
}

.story-footer {
  display: flex;
  min-height: 26px;
  align-items: end;
  justify-content: space-between;
  margin-top: 10px;
  color: var(--tertiary);
  font-size: 9px;
}
.story-actions { display: flex; gap: 2px; align-items: center; }
.save-action,
.audio-action {
  display: grid;
  height: 29px;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--secondary);
  text-decoration: none;
}
.save-action { width: 31px; }
.audio-action { grid-template-columns: 17px auto; gap: 3px; padding: 0 8px; font-size: 10px; font-weight: 650; }
.save-action:hover,
.audio-action:hover { background: var(--selected); color: var(--ink); }
.save-action svg,
.audio-action svg { width: 16px; }
.save-action.is-saved { color: var(--accent); }
.save-action.is-saved svg { fill: currentColor; }

.is-compact .story-list { gap: 5px; }
.is-compact .story { padding: 13px 15px 11px; border-radius: 14px; }
.is-compact .story-main { grid-template-columns: minmax(0, 1fr) 92px; gap: 14px; margin-top: 8px; }
.is-compact .story-image-wrap { width: 92px; }
.is-compact .story h2 { font-size: 19px; }
.is-compact .story-summary { -webkit-line-clamp: 1; }
.is-compact .story-footer { margin-top: 5px; }

.view-intro {
  padding: 20px 4px 30px;
  border-bottom: 1px solid var(--line);
}
.view-intro > p {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}
.view-intro h2 {
  margin: 0 0 7px;
  font: 700 32px/1.05 var(--serif);
  letter-spacing: -.035em;
}
.view-intro > span { color: var(--secondary); font-size: 12px; }

.issue-grid { display: grid; gap: 2px; padding: 14px 0 60px; }
.issue-card {
  display: grid;
  grid-template-columns: 54px 1fr 20px;
  gap: 14px;
  align-items: center;
  min-height: 78px;
  padding: 8px 10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  text-align: left;
}
.issue-card:hover { background: var(--selected); }
.issue-cover-wrap {
  position: relative;
  width: 50px;
  aspect-ratio: .76;
  overflow: hidden;
  border-radius: 3px;
  background: #9f2929;
  box-shadow: 0 4px 10px rgb(0 0 0 / 14%);
}
.issue-cover {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.issue-cover:not([src]) { display: none; }
.issue-fallback {
  position: absolute;
  top: 9px;
  left: 5px;
  color: white;
  font: 700 7px/.8 var(--serif);
}
.issue-copy { display: grid; gap: 4px; }
.issue-title { font: 700 17px/1.1 var(--serif); }
.issue-meta { color: var(--secondary); font-size: 10px; }
.issue-chevron { width: 16px; color: var(--tertiary); }

.status-region:not(:empty) { margin-bottom: 10px; }
.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--secondary);
  font-size: 11px;
}
.notice button { border: 0; background: transparent; color: var(--accent); font-weight: 700; }

.empty-state { padding: 90px 20px; text-align: center; }
.empty-symbol {
  display: grid;
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  font: italic 30px var(--serif);
}
.empty-state h2 { margin: 0 0 7px; font: 700 26px var(--serif); }
.empty-state p { margin: 0; color: var(--secondary); font-size: 12px; }

.skeleton {
  height: 190px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(90deg, transparent, rgb(255 255 255 / 35%), transparent) -80% 0/45% 100% no-repeat,
    linear-gradient(var(--selected) 0 0) 18px 22px/115px 12px no-repeat,
    linear-gradient(var(--selected) 0 0) 18px 58px/62% 24px no-repeat,
    linear-gradient(var(--selected) 0 0) 18px 95px/53% 11px no-repeat,
    linear-gradient(var(--selected) 0 0) calc(100% - 18px) 58px/128px 94px no-repeat,
    var(--surface);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { to { background-position: 180% 0,18px 22px,18px 58px,18px 95px,calc(100% - 18px) 58px; } }

.mobile-tabs { display: none; }

.search-dialog {
  width: min(620px, calc(100% - 30px));
  max-width: none;
  margin: max(80px, 12vh) auto auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgb(0 0 0 / 22%);
  color: var(--ink);
}
.search-dialog::backdrop { background: rgb(20 19 17 / 28%); backdrop-filter: blur(4px); }
.search-sheet { padding: 16px; }
.search-top { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; }
.search-top svg { color: var(--secondary); }
.search-top input { min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; }
.search-top button { border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 700; }
.search-sheet p { margin: 10px 32px 0; color: var(--tertiary); font-size: 10px; }

.sidebar-scrim { display: none; }
.noscript { position: fixed; z-index: 100; inset: auto 0 0; padding: 15px; background: var(--accent); color: white; text-align: center; }

@media (max-width: 800px) {
  body { overflow: auto; }
  .app-shell { display: block; height: auto; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(310px, 86vw);
    transform: translateX(-105%);
    transition: transform 220ms cubic-bezier(.2,.8,.2,1);
    box-shadow: 18px 0 50px rgb(0 0 0 / 18%);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-close,
  .mobile-only { display: grid; }
  .sidebar-scrim {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: block;
    border: 0;
    background: rgb(25 24 22 / 28%);
    backdrop-filter: blur(3px);
  }
  .sidebar-scrim[hidden] { display: none; }
  .timeline-header {
    position: fixed;
    height: 78px;
    padding: max(9px, env(safe-area-inset-top)) 14px 8px;
  }
  .timeline-title { margin-right: auto; margin-left: 9px; }
  .timeline-title h1 { font-size: 24px; }
  .timeline {
    height: auto;
    min-height: 100vh;
    padding: calc(90px + env(safe-area-inset-top)) 12px calc(92px + env(safe-area-inset-bottom));
    overflow: visible;
  }
  .mobile-tabs {
    position: fixed;
    z-index: 15;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: 63px;
    padding: 6px;
    border: 1px solid rgb(255 255 255 / 34%);
    border-radius: 22px;
    background: color-mix(in srgb, var(--sidebar) 83%, transparent);
    box-shadow: 0 12px 35px rgb(0 0 0 / 18%);
    backdrop-filter: blur(28px) saturate(1.4);
  }
  .mobile-tab {
    display: grid;
    gap: 2px;
    place-items: center;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--secondary);
    font-size: 9px;
  }
  .mobile-tab svg { width: 20px; }
  .mobile-tab.is-active { background: var(--selected); color: var(--ink); }
  .day-label { top: 78px; }
}

@media (max-width: 520px) {
  .header-actions { gap: 0; }
  .round-button { width: 36px; height: 36px; }
  .story { padding: 15px 15px 12px; border-radius: 16px; }
  .story-main { grid-template-columns: minmax(0, 1fr) 91px; gap: 12px; }
  .story-image-wrap { width: 91px; border-radius: 10px; }
  .story h2 { font-size: 20px; }
  .story-summary { font-size: 13px; -webkit-line-clamp: 2; }
  .story-author { display: none; }
  .story-footer { margin-top: 7px; }
  .is-compact .story-summary { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
