:root {
  --epaper-bg: #d6d1c9;
  --epaper-text: #1e1c19;
  --epaper-text-light: #524e47;
  --epaper-text-muted: #8a857d;
  --epaper-divider: #a9a49b;
  --backlight-intensity: 0;
  --backlight-warmth: 0.3;
  --text-glow: 0 0 0px transparent;
  --nav-height: 40px;
  --content-width: 550px;
  --content-padding: 2rem;
  --font-body: 'Literata', 'Georgia', serif;
  --font-ui: 'Source Sans 3', 'Helvetica Neue', sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; overflow-x: hidden; }

body {
  min-height: 100%;
  background: var(--epaper-bg);
  color: var(--epaper-text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.72;
  font-optical-sizing: auto;
  font-weight: 400;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: auto;
  -moz-osx-font-smoothing: auto;
  transition: background-color 0.6s ease;
  cursor: default;
}

::selection { background: rgba(30, 28, 25, 0.18); color: inherit; }

.epaper-grain {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  opacity: 0.45; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  transition: opacity 0.6s ease;
}

.backlight-layer {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none; background: transparent;
  transition: background 0.5s ease;
}


/* Kaleido CFA */
.book-cover { position: relative; overflow: hidden; }
.book-cover::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(0deg, transparent 47%, rgba(0,0,0,0.055) 47%, rgba(0,0,0,0.055) 53%, transparent 53%),
    linear-gradient(90deg, transparent 47%, rgba(0,0,0,0.055) 47%, rgba(0,0,0,0.055) 53%, transparent 53%);
  background-size: 4px 4px;
  mix-blend-mode: multiply;
  pointer-events: none; z-index: 2; border-radius: inherit;
}
.book-cover::after {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 64px 64px;
  opacity: 0.12; mix-blend-mode: multiply;
  pointer-events: none; z-index: 1; border-radius: inherit;
}

.reading-tag-color { position: relative; overflow: hidden; }
.reading-tag-color::after {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(0deg, transparent 47%, rgba(0,0,0,0.05) 47%, rgba(0,0,0,0.05) 53%, transparent 53%),
    linear-gradient(90deg, transparent 47%, rgba(0,0,0,0.05) 47%, rgba(0,0,0,0.05) 53%, transparent 53%);
  background-size: 3px 3px;
  pointer-events: none;
}

/* Screen */
.epaper-screen {
  position: relative; z-index: 2;
  min-height: 100vh;
  padding: calc(var(--nav-height) + 1.5rem) var(--content-padding) 5rem;
}
.content-column { max-width: var(--content-width); margin: 0 auto; }

/* Site nav bar */
.site-nav {
  position: fixed; top: 0; left: 0; right: 0; height: var(--nav-height);
  z-index: 100; background: var(--epaper-bg);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  transition: background-color 0.6s ease;
}
.site-nav-inner {
  max-width: calc(var(--content-width) + 4rem);
  margin: 0 auto; height: 100%;
  padding: 0 var(--content-padding);
  display: flex; align-items: center; justify-content: space-between;
}
.site-nav-brand {
  font-family: var(--font-ui); font-size: 0.82rem; font-weight: 600;
  color: var(--epaper-text-light); text-decoration: none;
  letter-spacing: 0.01em; transition: color 0.2s;
}
.site-nav-brand:hover { color: var(--epaper-text); }
.site-nav-links { display: flex; align-items: center; gap: 1.2rem; }
.site-nav-link {
  font-family: var(--font-ui); font-size: 0.72rem; font-weight: 500;
  color: var(--epaper-text-muted); text-decoration: none;
  letter-spacing: 0.02em; text-transform: uppercase;
  transition: color 0.2s;
}
.site-nav-link:hover { color: var(--epaper-text-light); }
.site-nav-icon {
  color: var(--epaper-text-muted); transition: color 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.site-nav-icon:hover { color: var(--epaper-text-light); }
.site-nav-icon svg { width: 14px; height: 14px; }
.site-nav-settings {
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--epaper-text-muted); transition: color 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.site-nav-settings:hover { color: var(--epaper-text-light); }
.site-nav-settings svg { width: 16px; height: 16px; }

/* Settings dropdown */
.settings-dropdown {
  position: fixed; top: var(--nav-height); z-index: 99;
  left: 50%;
  width: calc(var(--content-width) + 4rem); max-width: calc(100vw - 1rem);
  background: var(--epaper-bg); border: 1px solid var(--epaper-divider);
  border-top: none; border-radius: 0 0 3px 3px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  padding: 0.7rem 1rem 0.65rem;
  transform: translateX(-50%) translateY(-100%);
  opacity: 0; pointer-events: none;
  transition: transform 0.3s ease, opacity 0.2s ease, background-color 0.6s ease;
}
.settings-dropdown.open { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }

.comfort-light { display: flex; align-items: center; gap: 1rem; }
.comfort-slider-group { display: flex; align-items: center; gap: 0.45rem; flex: 1; }
.comfort-slider-group svg { width: 14px; height: 14px; color: var(--epaper-text-light); opacity: 0.6; flex-shrink: 0; }
.comfort-slider-label {
  font-family: var(--font-ui); font-size: 0.65rem; font-weight: 500;
  color: var(--epaper-text-light); text-transform: uppercase;
  letter-spacing: 0.04em; min-width: 42px;
}
.comfort-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 22px; background: transparent; cursor: pointer;
}
.comfort-slider::-webkit-slider-runnable-track { height: 2px; background: var(--epaper-divider); border-radius: 1px; }
.comfort-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--epaper-text-light); border: 2px solid var(--epaper-bg);
  margin-top: -5.5px; cursor: grab; transition: background 0.2s;
}
.comfort-slider::-webkit-slider-thumb:hover { background: var(--epaper-text); }
.comfort-slider::-moz-range-track { height: 2px; background: var(--epaper-divider); border-radius: 1px; border: none; }
.comfort-slider::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--epaper-text-light); border: 2px solid var(--epaper-bg); cursor: grab;
}

/* ComfortLight settings */
.comfort-settings { margin-top: 0.5rem; padding-top: 0.45rem; border-top: 1px solid var(--epaper-divider); }
.comfort-auto-row { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-ui); }
.comfort-auto-label { font-size: 0.65rem; font-weight: 500; color: var(--epaper-text-light); text-transform: uppercase; letter-spacing: 0.04em; }
.comfort-toggle {
  position: relative; width: 32px; height: 17px;
  background: var(--epaper-divider); border: 1px solid var(--epaper-divider);
  border-radius: 9px; cursor: pointer; padding: 0;
  transition: background 0.2s, border-color 0.2s;
}
.comfort-toggle.active { background: var(--epaper-text-light); border-color: var(--epaper-text-light); }
.comfort-toggle-knob {
  position: absolute; top: 2px; left: 2px; width: 11px; height: 11px;
  background: var(--epaper-bg); border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.comfort-toggle.active .comfort-toggle-knob { transform: translateX(15px); }
.comfort-bedtime-row { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; transition: opacity 0.2s; }
.comfort-bedtime-row.hidden { opacity: 0.3; pointer-events: none; }
.comfort-select {
  font-family: var(--font-ui); font-size: 0.65rem; color: var(--epaper-text);
  background: transparent; border: 1px solid var(--epaper-divider); border-radius: 3px;
  padding: 0.15em 0.3em; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%23524e47' stroke-width='1' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 4px center; padding-right: 16px;
}

/* Left edge brightness */
.left-hover-zone { position: fixed; top: var(--nav-height); left: 0; bottom: 0; width: 44px; z-index: 98; }
.left-brightness {
  position: absolute; top: calc(-1 * var(--nav-height)); bottom: 0; left: 0; width: 44px;
  transform: translateX(-100%); opacity: 0;
  transition: transform 0.3s ease, opacity 0.25s ease, background-color 0.6s ease;
  background: var(--epaper-bg);
  border-right: 1px solid var(--epaper-divider);
  box-shadow: 2px 0 8px rgba(0,0,0,0.04);
}
.left-hover-zone:hover .left-brightness { transform: translateX(0); opacity: 1; }
.vslider-icon {
  display: block; width: 16px; height: 16px;
  margin: 1.8rem auto 0; color: var(--epaper-text-light); opacity: 0.5;
}
.vslider-track {
  position: absolute; top: 5rem; bottom: 2rem;
  left: 50%; transform: translateX(-50%);
  width: 2px; cursor: pointer;
}
.vslider-thumb {
  position: absolute; left: 50%; transform: translate(-50%, -50%);
  width: 24px; height: 24px; border-radius: 5px;
  border: 1px solid var(--epaper-divider);
  background: transparent; cursor: grab; transition: border-color 0.2s;
}
.vslider-thumb:hover { border-color: var(--epaper-text-light); }
.vslider-thumb.dragging { cursor: grabbing; border-color: var(--epaper-text-light); }

/* Home screen */
.home-screen { padding-top: 0.5rem; }
.section-heading {
  font-family: var(--font-ui); font-size: 0.73rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--epaper-text-light); margin-bottom: 0.7rem;
}
.continue-card {
  display: block; text-decoration: none; color: inherit;
  padding: 1rem; border: 1px solid var(--epaper-divider);
  border-radius: 3px; margin-bottom: 2rem; transition: border-color 0.2s; cursor: pointer;
}
.continue-card:hover { border-color: var(--epaper-text-light); }
.continue-cover-thumb {
  width: 80px; min-width: 80px; aspect-ratio: 2 / 3; flex-shrink: 0;
  border-radius: 2px; float: left; margin-right: 1rem; overflow: hidden;
}
.continue-cover-thumb img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(1) contrast(1.08) brightness(0.95); transition: filter 0.4s ease;
}
body.backlit .continue-cover-thumb img { filter: grayscale(1) contrast(1.05) brightness(0.98) sepia(calc(var(--backlight-warmth) * 0.15)); }
.continue-meta { display: flex; flex-direction: column; gap: 0.1rem; margin-bottom: 0.5rem; }
.continue-title { font-size: 1.08rem; font-weight: 600; line-height: 1.3; }
.continue-author { font-family: var(--font-ui); font-size: 0.72rem; color: var(--epaper-text-light); }
.continue-excerpt { font-size: 0.83rem; color: var(--epaper-text-light); line-height: 1.5; margin-bottom: 0.6rem; }
.continue-progress { height: 2px; background: var(--epaper-divider); border-radius: 1px; overflow: hidden; }
.continue-progress-bar { height: 100%; background: var(--epaper-text-light); }

/* Post list */
.post-list { display: flex; flex-direction: column; gap: 1.5rem; }
.post-card {
  text-decoration: none; color: inherit; display: block;
  cursor: pointer; transition: border-color 0.2s;
}
.post-card-image {
  position: relative; overflow: hidden;
  border: 1px solid var(--epaper-divider); border-radius: 2px;
  aspect-ratio: 3 / 1;
}
.post-card-image img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(1) contrast(1.08) brightness(0.95); transition: filter 0.4s ease;
}
body.backlit .post-card-image img { filter: grayscale(1) contrast(1.05) brightness(0.98) sepia(calc(var(--backlight-warmth) * 0.15)); }
.post-card:hover .post-card-image { border-color: var(--epaper-text-light); }
.post-card-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 2rem 0.8rem 0.6rem;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.45) 50%, rgba(0,0,0,0.15) 80%, transparent 100%);
}
.post-card-overlay .post-title {
  color: #f0ece6; margin-bottom: 0;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6), 0 0 12px rgba(0,0,0,0.3);
}
.post-thumb-progress { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: rgba(0,0,0,0.1); z-index: 5; }
.post-thumb-progress-bar { height: 100%; width: 0%; background: var(--epaper-text-light); opacity: 0.6; transition: width 0.3s ease; }
.post-thumb-read {
  position: absolute; top: 6px; right: 6px; z-index: 5;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--epaper-bg); border: 1px solid var(--epaper-text-light);
  display: flex; align-items: center; justify-content: center;
  opacity: 0.8;
}
.post-thumb-read svg { width: 11px; height: 11px; }
.post-card-body { padding: 0.5rem 0 0; }
.post-title { display: block; font-size: 1.15rem; font-weight: 600; line-height: 1.3; margin-bottom: 0.3rem; }
.post-summary {
  display: block; font-size: 0.88rem; color: var(--epaper-text-light); line-height: 1.6; margin-bottom: 0.4rem;
}
.post-meta {
  font-family: var(--font-ui); font-size: 0.65rem; color: var(--epaper-text-muted);
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}

/* Reading view */
.reading-view { padding-top: 1.5rem; }
.reading-header { margin-bottom: 1.8rem; padding-bottom: 1.2rem; border-bottom: 1px solid var(--epaper-divider); }
.reading-title { font-size: 1.6rem; font-weight: 700; line-height: 1.22; margin-bottom: 0.4rem; letter-spacing: -0.01em; }
.reading-meta { font-family: var(--font-ui); font-size: 0.73rem; color: var(--epaper-text-light); display: flex; align-items: center; gap: 0.6rem; }

/* Article hero */
.article-hero {
  position: relative; overflow: hidden;
  margin: calc(-1 * (var(--nav-height) + 1.5rem)) calc(-1 * var(--content-padding)) 2rem;
  aspect-ratio: 5 / 2;
}
.article-hero img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(1) contrast(1.08) brightness(0.95); transition: filter 0.4s ease;
}
body.backlit .article-hero img { filter: grayscale(1) contrast(1.05) brightness(0.98) sepia(calc(var(--backlight-warmth) * 0.15)); }
.article-hero-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 3rem var(--content-padding) 1.2rem;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.45) 50%, rgba(0,0,0,0.15) 80%, transparent 100%);
}
.article-hero-overlay .reading-title {
  color: #f0ece6;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6), 0 0 12px rgba(0,0,0,0.3);
}
.article-hero-overlay .reading-meta { color: rgba(240,236,230,0.7); }

.kaleido-img { position: relative; display: block; margin: 1.5em 0; border-radius: 2px; overflow: hidden; border: 1px solid var(--epaper-divider); }
.kaleido-img img, .kaleido-img svg { display: block; width: 100%; height: auto; filter: grayscale(1) contrast(1.08) brightness(0.95); transition: filter 0.4s ease; }
body.backlit .kaleido-img img, body.backlit .kaleido-img svg { filter: grayscale(1) contrast(1.05) brightness(0.98) sepia(calc(var(--backlight-warmth) * 0.15)); }
.kaleido-img::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(0deg, transparent 46%, rgba(0,0,0,0.06) 46%, rgba(0,0,0,0.06) 54%, transparent 54%),
    linear-gradient(90deg, transparent 46%, rgba(0,0,0,0.06) 46%, rgba(0,0,0,0.06) 54%, transparent 54%);
  background-size: 4px 4px; mix-blend-mode: multiply; pointer-events: none; z-index: 3;
}
.kaleido-img::after {
  content: ''; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 128px 128px; opacity: 0.18; mix-blend-mode: multiply; pointer-events: none; z-index: 2;
}
.kaleido-img-caption { font-family: var(--font-ui); font-size: 0.68rem; color: var(--epaper-text-light); padding: 0.4rem 0.1rem 0; text-align: center; position: relative; z-index: 4; }

.reading-body p { margin-bottom: 1.2em; text-align: justify; hyphens: auto; }
.reading-body p:first-child::first-letter {
  float: left; font-size: 3.2em; line-height: 0.8; font-weight: 700;
  margin: 0.05em 0.12em 0 0; color: var(--epaper-text);
}
.reading-body h2 { font-size: 1.18rem; font-weight: 600; line-height: 1.3; margin: 2.2em 0 0.8em; }
.reading-body blockquote { border-left: 2px solid var(--epaper-divider); padding-left: 1rem; margin: 1.3em 0; font-style: italic; color: var(--epaper-text-light); }
.reading-body em { font-style: italic; }
.reading-body a { color: var(--epaper-text); text-decoration-color: var(--epaper-divider); text-underline-offset: 3px; }

.reading-cta {
  font-family: var(--font-ui); font-size: 0.78rem; color: var(--epaper-text-light);
  margin-bottom: 1.5rem; text-align: center;
}
.reading-cta a { color: var(--epaper-text); text-decoration-color: var(--epaper-divider); text-underline-offset: 3px; }
.reading-cta a:hover { text-decoration-color: var(--epaper-text-light); }
.reading-footer { margin-top: 2.5rem; padding-top: 1.2rem; border-top: 1px solid var(--epaper-divider); }
.reading-end-mark { text-align: center; color: var(--epaper-text-light); font-size: 0.85rem; letter-spacing: 0.3em; margin-bottom: 1rem; }
.reading-nav { display: flex; justify-content: center; }
.reading-nav-link { font-family: var(--font-ui); font-size: 0.78rem; color: var(--epaper-text-light); text-decoration: none; cursor: pointer; transition: color 0.2s; }
.reading-nav-link:hover { color: var(--epaper-text); }

.reading-progress { position: fixed; bottom: 0; left: 0; right: 0; height: 3px; background: var(--epaper-divider); z-index: 50; opacity: 0.7; }
.reading-progress-bar { height: 100%; width: 0%; background: var(--epaper-text-light); transition: width 0.1s linear; }

/* Read next card */
.read-next { margin-top: 1.5rem; margin-bottom: 0.8rem; }
.read-next-heading {
  font-family: var(--font-ui); font-size: 0.65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--epaper-text-light); margin-bottom: 0.6rem;
}
.read-next-card {
  display: flex; gap: 1rem; text-decoration: none; color: inherit;
  padding: 0.8rem; border: 1px solid var(--epaper-divider); border-radius: 3px;
  transition: border-color 0.2s; cursor: pointer;
}
.read-next-card:hover { border-color: var(--epaper-text-light); }
.read-next-cover {
  width: 100px; flex-shrink: 0;
  aspect-ratio: 3 / 2; border: 1px solid var(--epaper-divider); border-radius: 2px;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.read-next-cover img {
  width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(1) contrast(1.08) brightness(0.95); transition: filter 0.4s ease;
}
body.backlit .read-next-cover img { filter: grayscale(1) contrast(1.05) brightness(0.98) sepia(calc(var(--backlight-warmth) * 0.15)); }
.read-next-cover-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-body); font-size: 0.6rem; font-weight: 600;
  color: var(--epaper-text-light); text-align: center;
  padding: 0.3rem; line-height: 1.2;
}
.read-next-info { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.read-next-title { font-size: 0.95rem; font-weight: 600; line-height: 1.3; margin-bottom: 0.2rem; }
.read-next-excerpt {
  font-size: 0.78rem; color: var(--epaper-text-light); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-bottom: 0.25rem;
}
.read-next-date { font-family: var(--font-ui); font-size: 0.65rem; color: var(--epaper-text-light); }

body.backlit .reading-body, body.backlit .reading-title, body.backlit .continue-title, body.backlit .book-cover-title { text-shadow: var(--text-glow); }
body.backlit .epaper-grain { opacity: calc(0.45 - var(--backlight-intensity) * 0.35); }

@media (max-width: 620px) {
  :root { --content-padding: 1.2rem; }
  body { font-size: 16px; }
  .book-grid { grid-template-columns: repeat(2, 1fr); }
  .reading-title { font-size: 1.35rem; }
  .comfort-slider-label { display: none; }
  .site-nav-inner { padding: 0 var(--content-padding); }
  .settings-dropdown { width: 100%; max-width: 100%; left: 0; transform: translateY(-100%); border-radius: 0; }
  .settings-dropdown.open { transform: translateY(0); }
  .read-next-cover { width: 56px; }
}
