:root {
  color-scheme: light;
  --header-height: 80px;
  --bg: #f6f1e8;
  --text: #2b2118;
  --muted: rgba(43, 33, 24, 0.58);
  --line: rgba(43, 33, 24, 0.12);
  --card: #ffffff;
  --card-shadow: rgba(43, 33, 24, 0.08);
  --accent: #e74c3c;
  --button: rgba(43, 33, 24, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1510;
  --text: #f6f1e8;
  --muted: rgba(246, 241, 232, 0.58);
  --line: rgba(246, 241, 232, 0.12);
  --card: #2a2018;
  --card-shadow: rgba(0, 0, 0, 0.2);
  --button: rgba(246, 241, 232, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.5;
  margin: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2 {
  font-family: "Libre Baskerville", Georgia, serif;
}

img {
  display: block;
  background: #222;
}

button,
.rss-link {
  color: var(--text);
  background: var(--button);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

button:hover,
.rss-link:hover,
button.active {
  background: transparent;
  border-color: var(--line);
}

#toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px 20px;
  align-items: center;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.toolbar-primary {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

#counts {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.toolbar-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#pubFilters {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

#pubFilters button {
  flex: 0 0 auto;
}

#app {
  display: flex;
  align-items: flex-start;
}

#list {
  max-width: 1040px;
  margin: 72px auto 110px;
  padding: 0 24px;
  width: 100%;
  transition: margin 0.3s ease, max-width 0.3s ease, padding 0.3s ease, width 0.3s ease;
}

#viewer {
  position: fixed;
  right: 0;
  top: 0;
  z-index: 200;
  width: 66.666%;
  height: 100vh;
  background: var(--bg);
  box-shadow: -18px 0 42px var(--card-shadow);
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

#viewer.open {
  transform: translateX(0);
}

iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

#close {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  min-width: 36px;
  height: 36px;
  background: #111;
  color: white;
  border: none;
  border-radius: 999px;
  padding: 8px;
  cursor: pointer;
  line-height: 1;
}

.year-section {
  margin-bottom: 72px;
  scroll-margin-top: calc(var(--header-height) + 40px);
}

.year-section h2 {
  font-size: 34px;
  margin: 0 0 18px;
}

.year-items {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  position: relative;
  display: flex;
  gap: 12px;
  overflow: hidden;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 10px 30px var(--card-shadow);
  padding: 14px;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
}

.card:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.card img,
.image-placeholder {
  flex: 0 0 132px;
  width: 132px;
  height: 92px;
  object-fit: cover;
  border-radius: 10px;
}

.image-placeholder {
  display: block;
  background: color-mix(in srgb, var(--text) 12%, transparent);
}

.card-body {
  min-width: 0;
}

.meta {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.title {
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 18px;
  line-height: 1.3;
  margin-top: 4px;
}

.excerpt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.ribbon {
  position: absolute;
  top: 10px;
  right: -30px;
  z-index: 2;
  transform: rotate(45deg);
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 4px 40px;
}

.empty {
  color: var(--muted);
  font-size: 14px;
}

.grid .year-items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.grid .card {
  display: block;
  min-height: 100%;
}

.grid .card img,
.grid .image-placeholder {
  width: 100%;
  height: 160px;
  margin-bottom: 12px;
}

.grid .excerpt {
  -webkit-line-clamp: 3;
}

#timeline {
  position: fixed;
  right: 24px;
  top: calc(var(--header-height) + 16px);
  z-index: 50;
  height: calc(100vh - var(--header-height) - 40px);
  width: 88px;
  user-select: none;
}

#timelineTrack {
  position: absolute;
  right: 18px;
  top: 0;
  width: 2px;
  height: 100%;
  background: color-mix(in srgb, var(--text) 18%, transparent);
  border-radius: 999px;
  pointer-events: none;
}

.timeline-dot {
  position: absolute;
  right: 14px;
  width: 10px;
  height: 10px;
  transform: translateY(-50%);
  border: 2px solid color-mix(in srgb, var(--text) 55%, transparent);
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    opacity 0.16s ease;
}

.timeline-dot.active,
.timeline-dot:hover,
.timeline-dot:focus-visible {
  transform: translateY(-50%) scale(1.35);
  background: var(--text);
  border-color: var(--text);
}

#timelineYears {
  position: absolute;
  right: 38px;
  top: 0;
  height: 100%;
  width: 42px;
}

.year-label {
  position: absolute;
  transform: translateY(-50%);
  color: color-mix(in srgb, var(--text) 58%, transparent);
  cursor: pointer;
  font-family: Inter, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  user-select: none;
  transition: color 0.15s ease, transform 0.15s ease;
}

.year-label:hover,
.year-label.active {
  color: var(--text);
  transform: translateY(-50%) translateX(-2px);
}

#timelineTooltip {
  position: fixed;
  z-index: 999;
  padding: 5px 8px;
  transform: translate(-100%, -50%);
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-family: Inter, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

@media (max-width: 1120px) {
  #timeline {
    right: 8px;
  }
}

@media (min-width: 901px) {
  body.viewer-open #list {
    width: 33.333%;
    max-width: none;
    height: calc(100vh - 112px);
    overflow-y: auto;
    margin-left: 0;
    margin-right: auto;
    padding: 32px 24px 90px;
  }

  body.viewer-open #viewer {
    width: 66.666%;
    transform: translateX(0);
  }

  body.viewer-open.grid #list {
    width: 33.333%;
  }

  body.viewer-open .year-items {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
}

@media (max-width: 900px) {
  #app {
    display: block;
  }

  #viewer {
    display: none;
  }

  #timeline,
  #timelineTooltip {
    display: none;
  }
}

@media (max-width: 760px) {
  #toolbar {
    grid-template-columns: 1fr;
    padding: 12px 16px;
  }

  .toolbar-primary,
  .toolbar-controls {
    justify-content: space-between;
  }

  #list {
    margin: 46px auto 82px;
    padding: 0 16px;
  }

  .year-section {
    margin-bottom: 54px;
  }

  .year-section h2 {
    font-size: 29px;
  }

  .card,
  .list .card {
    display: block;
  }

  .card img,
  .image-placeholder {
    width: 100%;
    height: 172px;
    margin-bottom: 12px;
  }

  .grid .year-items {
    grid-template-columns: 1fr;
  }
}
