:root {
  color-scheme: light dark;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-2: #f0ece3;
  --text: #1d1c19;
  --muted: #6d685f;
  --faint: #989188;
  --line: #dcd5c8;
  --line-strong: #c6bdad;
  --accent: #20201d;
  --accent-contrast: #ffffff;
  --danger: #9f2f2f;
  --notice-bg: #1d1c19;
  --notice-text: #fffdf8;
  --notice-muted: #d9d4cb;
  --notice-accent: #e2b65a;
  --shadow: 0 18px 45px rgba(45, 39, 30, .09);
  --shadow-small: 0 6px 22px rgba(45, 39, 30, .08);
  --radius: 20px;
  --radius-small: 12px;
  --shell: 1180px;
  --reading: 760px;
  --article-font-size: 1.12rem;
  --header-height: 76px;
}

html[data-theme="dark"] {
  --bg: #11110f;
  --surface: #191916;
  --surface-2: #22221e;
  --text: #efede7;
  --muted: #b4afa5;
  --faint: #858076;
  --line: #33322c;
  --line-strong: #47463e;
  --accent: #f3f0e8;
  --accent-contrast: #11110f;
  --danger: #f28b82;
  --notice-bg: #f7f4ee;
  --notice-text: #11110f;
  --notice-muted: #5f5a52;
  --notice-accent: #9a681f;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
  --shadow-small: 0 6px 22px rgba(0, 0, 0, .24);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #11110f;
    --surface: #191916;
    --surface-2: #22221e;
    --text: #efede7;
    --muted: #b4afa5;
    --faint: #858076;
    --line: #33322c;
    --line-strong: #47463e;
    --accent: #f3f0e8;
    --accent-contrast: #11110f;
    --danger: #f28b82;
    --notice-bg: #f7f4ee;
    --notice-text: #11110f;
    --notice-muted: #5f5a52;
    --notice-accent: #9a681f;
    --shadow: 0 18px 45px rgba(0, 0, 0, .28);
    --shadow-small: 0 6px 22px rgba(0, 0, 0, .24);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  transition: background-color .2s ease, color .2s ease;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
img { max-width: 100%; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 1000;
  padding: .75rem 1rem;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

.shell { width: min(calc(100% - 2rem), var(--shell)); margin-inline: auto; }
.reading-shell { width: min(calc(100% - 2rem), var(--reading)); margin-inline: auto; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  background: color-mix(in srgb, var(--bg) 89%, transparent);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.header-inner {
  width: min(calc(100% - 1.5rem), var(--shell));
  height: var(--header-height);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-button {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .8rem;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #fff;
  border: 1px solid #dedede;
}
.brand-mark img { width: 43px; height: 43px; object-fit: contain; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: normal; padding-block: 2px; overflow: visible; }
.brand-copy strong { font-size: 1rem; line-height: 1.25; letter-spacing: -.01em; }
.brand-copy span { margin-top: .12rem; padding-bottom: .08rem; color: var(--muted); font-size: .77rem; line-height: 1.4; white-space: nowrap; overflow: visible; }

.header-actions { display: flex; align-items: center; gap: .25rem; }
.icon-button, .small-action {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover, .small-action:hover { background: var(--surface-2); border-color: var(--line); }
.icon-button:focus-visible, .small-action:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--text) 26%, transparent); outline-offset: 2px; }
.theme-icon-dark { display: none; }
html[data-theme="dark"] .theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-dark { display: block; }
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .theme-icon-light { display: none; }
  html[data-theme="system"] .theme-icon-dark { display: block; }
}

main { min-height: calc(100vh - var(--header-height)); }
.hero {
  padding-block: 1.35rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}
.hero-intro { min-width: 0; }
.eyebrow { margin: 0 0 .45rem; color: var(--muted); font-size: .75rem; font-weight: 760; letter-spacing: .11em; text-transform: uppercase; }
.hero-copy { max-width: 620px; margin: 0; color: var(--muted); font-size: clamp(.96rem, 1.7vw, 1.08rem); }

.update-panel {
  flex: 0 0 auto;
  min-width: 230px;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  box-shadow: var(--shadow-small);
}
.update-panel div { display: grid; }
.update-panel strong { font-size: .82rem; }
.update-panel span:not(.sync-dot) { margin-top: .12rem; color: var(--muted); font-size: .72rem; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #7f9b72; box-shadow: 0 0 0 4px color-mix(in srgb, #7f9b72 16%, transparent); }
.sync-dot.is-syncing { background: #bf8a37; animation: pulse 1.1s infinite; }
.sync-dot.is-error { background: #ba5b55; box-shadow: 0 0 0 4px color-mix(in srgb, #ba5b55 16%, transparent); }
@keyframes pulse { 50% { opacity: .35; } }

.demo-banner { padding: .85rem 1rem; border: 1px solid #c59c52; border-radius: var(--radius-small); background: color-mix(in srgb, #d7ae63 15%, var(--surface)); color: var(--text); }

.controls-dock { position: sticky; top: var(--header-height); z-index: 30; width: 100%; padding-block: .5rem .35rem; background: var(--bg); box-shadow: 0 1px 0 color-mix(in srgb, var(--line) 70%, transparent); }
.controls { position: relative; padding: .8rem; border: 1px solid var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 96%, var(--bg)); box-shadow: var(--shadow-small); backdrop-filter: blur(16px); }
.search-box { height: 52px; display: flex; align-items: center; gap: .7rem; padding: 0 .9rem; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.search-box:focus-within { border-color: var(--line-strong); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent); }
.search-box svg { flex: 0 0 auto; color: var(--muted); }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.search-box input::placeholder { color: var(--faint); }
.clear-search { width: 32px; height: 32px; border: 0; border-radius: 999px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 1.25rem; }

.filter-row { margin-top: .65rem; display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.filter-row select, .settings-list select { height: 40px; max-width: 210px; padding: 0 2.2rem 0 .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; }
.segmented, .view-switch { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); }
.segmented button, .view-switch button { min-height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button { padding: 0 .75rem; font-size: .85rem; }
.view-switch button { width: 38px; display: grid; place-items: center; }
.segmented button.is-active, .view-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.count-badge { display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; margin-left: .2rem; padding: 0 .3rem; border-radius: 999px; background: var(--line); font-size: .7rem; }
.view-switch { margin-left: auto; }

.results { padding-block: 1.6rem 5rem; }
.results-heading-row { min-height: 35px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.results-heading-row h2 { margin: 0; color: var(--muted); font-size: .83rem; font-weight: 650; letter-spacing: .02em; }
.text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.article-collection { display: grid; gap: .9rem; }
.article-card { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: 0 1px 0 rgba(0,0,0,.02); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.article-card:hover { transform: translateY(-2px); border-color: var(--line-strong); box-shadow: var(--shadow-small); }
.card-open { width: 100%; display: grid; border: 0; background: transparent; color: inherit; padding: 0; cursor: pointer; text-align: left; }
.list-layout .card-open { grid-template-columns: 190px minmax(0, 1fr); min-height: 190px; }
.card-image-wrap { min-height: 100%; overflow: hidden; background: #fff; }
.card-image { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .35s ease; }
.article-card:hover .card-image { transform: scale(1.025); }
.card-content { min-width: 0; display: flex; flex-direction: column; padding: 1.35rem 3.6rem 1.2rem 1.35rem; }
.card-kicker { color: var(--muted); font-size: .72rem; font-weight: 720; letter-spacing: .07em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { margin-top: .38rem; max-width: 780px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.25rem, 2vw, 1.65rem); line-height: 1.18; font-weight: 600; letter-spacing: -.015em; }
.card-excerpt { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; margin-top: .6rem; color: var(--muted); font-size: .92rem; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; margin-top: auto; padding-top: .85rem; color: var(--faint); font-size: .75rem; }
.card-meta > * + *::before { content: "·"; margin-right: .55rem; }
.card-updated { color: var(--muted); }
.card-bookmark { position: absolute; top: .85rem; right: .85rem; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--surface) 90%, transparent); cursor: pointer; backdrop-filter: blur(8px); }
.card-bookmark svg { fill: transparent; }
.card-bookmark.is-saved svg, #articleBookmarkButton.is-saved svg { fill: currentColor; }

.grid-layout { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-layout .article-card { min-width: 0; }
.grid-layout .card-open { height: 100%; grid-template-rows: 195px 1fr; }
.grid-layout .card-image-wrap { min-height: 195px; }
.grid-layout .card-content { padding: 1.15rem 1.15rem 1.05rem; }
.grid-layout .card-title { font-size: 1.2rem; }
.grid-layout .card-excerpt { -webkit-line-clamp: 3; font-size: .86rem; }
.grid-layout .card-meta { padding-top: 1rem; }
.grid-layout .card-bookmark { background: rgba(255,255,255,.9); color: #171717; border-color: rgba(0,0,0,.12); }

.empty-state { max-width: 520px; margin: 4rem auto; padding: 2rem; text-align: center; color: var(--muted); }
.empty-state img { width: 90px; height: 90px; object-fit: contain; }
.empty-state h3 { margin: 1rem 0 .3rem; color: var(--text); font-family: Georgia, serif; font-size: 1.6rem; }
.empty-state p { margin: 0 0 1.2rem; }
.primary-button, .secondary-button, .danger-button, .back-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1rem;
  border-radius: 11px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 650;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-contrast); }
.secondary-button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
.danger-button { border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line)); background: transparent; color: var(--danger); }

/* Article reader */
.article-topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: .8rem; }
.back-button { border: 0; background: transparent; color: var(--muted); padding-left: .2rem; }
.back-button:hover { color: var(--text); }
.article-actions { display: flex; align-items: center; gap: .15rem; }
.small-action { width: 38px; height: 38px; font-family: Georgia, serif; font-weight: 700; }
.article-header { padding-block: 2.6rem 2rem; }
.category-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.category-chip { display: inline-flex; align-items: center; min-height: 28px; padding: .25rem .62rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .72rem; }
.article-header h1 { margin: .9rem 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.2rem, 7vw, 4.6rem); line-height: 1.02; letter-spacing: -.038em; font-weight: 500; text-wrap: balance; }
.article-meta { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 1.1rem; color: var(--muted); font-size: .82rem; }
.article-meta > * + *::before { content: "·"; margin-right: .55rem; }
.article-hero { overflow: hidden; border-radius: var(--radius); background: #fff; }
.article-hero img { width: 100%; max-height: 520px; object-fit: cover; display: block; }
.article-progress { position: fixed; top: var(--header-height); left: 0; z-index: 49; width: 100%; height: 2px; background: transparent; }
.article-progress span { display: block; width: 0; height: 100%; background: var(--text); transition: width .08s linear; }
.article-body { padding-block: 2.4rem; font-family: Georgia, "Times New Roman", serif; font-size: var(--article-font-size); line-height: 1.76; overflow-wrap: anywhere; }
.article-body > :first-child { margin-top: 0; }
.article-body h2, .article-body h3, .article-body h4 { line-height: 1.25; margin: 2.2em 0 .7em; text-wrap: balance; }
.article-body h2 { font-size: 1.65em; }
.article-body h3 { font-size: 1.32em; }
.article-body p { margin: 1.05em 0; }
.article-body a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.article-body img { height: auto; border-radius: 8px; }
.article-body figure { max-width: 100%; margin: 2em auto; }
.article-body figcaption { margin-top: .45rem; color: var(--muted); font-family: ui-sans-serif, sans-serif; font-size: .76rem; text-align: center; }
.article-body blockquote { margin: 1.7em 0; padding: .1em 0 .1em 1.25em; border-left: 3px solid var(--line-strong); color: color-mix(in srgb, var(--text) 86%, var(--muted)); font-style: italic; }
.article-body pre { overflow-x: auto; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: .82em; }
.article-body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.article-body table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; font-family: ui-sans-serif, sans-serif; font-size: .83em; }
.article-body th, .article-body td { padding: .65rem; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.article-body iframe { width: 100%; max-width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 10px; }
.article-body .wp-caption { max-width: 100% !important; }
.article-body .gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.article-body .gallery-item { margin: 0; }

.ai-guide { margin-top: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.ai-guide-trigger { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.25rem; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.ai-guide-trigger span { display: grid; }
.ai-guide-trigger strong { font-family: Georgia, serif; font-size: 1.1rem; }
.ai-guide-trigger small { margin-top: .2rem; color: var(--muted); }
.ai-guide-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
.ai-guide-content { padding: 0 1.25rem 1.3rem; }
.ai-disclaimer { padding: .7rem .8rem; border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: .78rem; }
#aiGuideText { font-family: Georgia, serif; line-height: 1.7; }

.article-footer { padding-block: 2rem 5rem; border-top: 1px solid var(--line); }
.article-footer-actions { display: flex; flex-wrap: wrap; gap: .7rem; }
.quote-help { margin: 1rem 0 0; color: var(--muted); font-size: .8rem; }
.article-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: 2.4rem; }
.article-nav-button { min-height: 100px; display: grid; align-content: center; gap: .25rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius-small); background: var(--surface); color: inherit; text-decoration: none; }
.article-nav-button.next { text-align: right; }
.article-nav-button small { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.article-nav-button strong { font-family: Georgia, serif; line-height: 1.25; }

.quote-toolbar { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 90; width: min(calc(100% - 2rem), 720px); transform: translateX(-50%); display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem .85rem .8rem 1rem; border: 2px solid var(--notice-accent); border-radius: 16px; background: var(--notice-bg); color: var(--notice-text); box-shadow: 0 20px 70px rgba(0,0,0,.48), 0 0 0 4px color-mix(in srgb, var(--notice-accent) 20%, transparent); }
.quote-toolbar::before { content: "“"; flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--notice-accent); color: var(--notice-bg); font: 800 1.25rem/1 Georgia, serif; }
.quote-toolbar > span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--notice-muted); font-family: Georgia, serif; font-size: .84rem; }
.quote-toolbar > div { flex: 0 0 auto; display: flex; gap: .4rem; }
.quote-toolbar button { min-height: 38px; padding: 0 .75rem; border: 1px solid color-mix(in srgb, var(--notice-text) 35%, transparent); border-radius: 9px; background: color-mix(in srgb, var(--notice-text) 12%, transparent); color: var(--notice-text); cursor: pointer; font-size: .79rem; font-weight: 700; }
.quote-toolbar button:hover { background: color-mix(in srgb, var(--notice-text) 22%, transparent); }
.quote-toolbar .quote-close { width: 38px; padding: 0; font-size: 1.1rem; }

/* Embedded PDF reader */
.pdf-readers { display: grid; gap: 1.4rem; padding-block: 1.2rem 2rem; }
.pdf-reader { overflow: hidden; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-small); }
.pdf-reader-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.pdf-reader-header > div { min-width: 0; }
.pdf-reader-eyebrow { display: block; color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.pdf-reader h2 { margin: .15rem 0 0; font-family: Georgia, serif; font-size: clamp(1rem, 2vw, 1.3rem); line-height: 1.25; }
.pdf-direct-link { flex: 0 0 auto; white-space: nowrap; }
.pdf-frame-wrap { position: relative; width: 100%; height: min(82vh, 920px); min-height: 620px; background: #4a4a4a; }
.pdf-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.pdf-reader-note { margin: 0; padding: .75rem 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; }

/* Installation encouragement */
.install-nudge { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 105; width: min(calc(100% - 2rem), 680px); transform: translateX(-50%); display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: .85rem; padding: .8rem; border: 2px solid var(--notice-accent); border-radius: 18px; background: var(--notice-bg); color: var(--notice-text); box-shadow: 0 24px 80px rgba(0,0,0,.5), 0 0 0 4px color-mix(in srgb, var(--notice-accent) 18%, transparent); }
.install-nudge img { width: 48px; height: 48px; border-radius: 12px; background: #fff; }
.install-nudge > div { min-width: 0; display: grid; }
.install-nudge strong { font-size: .9rem; }
.install-nudge span { margin-top: .12rem; color: var(--notice-muted); font-size: .75rem; }
.install-nudge-action { min-height: 40px; padding: 0 1rem; border: 0; border-radius: 10px; background: var(--notice-accent); color: var(--notice-bg); cursor: pointer; font-weight: 800; }
.install-nudge-close { width: 38px; height: 38px; border: 1px solid color-mix(in srgb, var(--notice-text) 30%, transparent); border-radius: 50%; background: transparent; color: var(--notice-text); cursor: pointer; font-size: 1.2rem; }

.back-to-top { position: fixed; left: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 85; min-width: 54px; height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: .25rem; padding: 0 .8rem; border: 2px solid var(--notice-accent); border-radius: 999px; background: var(--notice-bg); color: var(--notice-text); box-shadow: 0 12px 36px rgba(0,0,0,.34); cursor: pointer; font-weight: 800; }
.back-to-top svg { width: 1.1rem; height: 1.1rem; }
.back-to-top span { font-size: .76rem; }

/* Dialogs */
.app-dialog { width: min(calc(100% - 2rem), 620px); max-height: min(84vh, 780px); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 26px 80px rgba(0,0,0,.3); }
.app-dialog::backdrop { background: rgba(0,0,0,.48); backdrop-filter: blur(3px); }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.dialog-header h2 { margin: 0; font-family: Georgia, serif; font-size: 1.55rem; }
.dialog-header .eyebrow { margin-bottom: .15rem; }
.dialog-close { width: 40px; height: 40px; border: 0; border-radius: 999px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 1.35rem; }
.dialog-body { padding: 1.2rem; overflow-y: auto; }
.settings-list section + section { margin-top: 1.7rem; }
.settings-list h3 { margin: 0 0 .5rem; color: var(--muted); font-size: .76rem; letter-spacing: .07em; text-transform: uppercase; }
.setting-row { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.setting-row > span:first-child { display: grid; }
.setting-row strong { font-size: .91rem; }
.setting-row small { margin-top: .16rem; color: var(--muted); font-size: .74rem; }
.setting-row.is-muted { opacity: .72; }
.status-pill { flex: 0 0 auto; padding: .25rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .7rem; }
.toggle-row input { appearance: none; width: 46px; height: 26px; flex: 0 0 auto; padding: 3px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface-2); cursor: pointer; }
.toggle-row input::before { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .18s ease; }
.toggle-row input:checked { background: var(--accent); }
.toggle-row input:checked::before { transform: translateX(18px); background: var(--accent-contrast); }
.about-block { display: flex; align-items: center; gap: .8rem; padding: 1rem; border-radius: 12px; background: var(--surface-2); }
.about-block img { width: 48px; height: 48px; object-fit: contain; }
.about-block div { display: grid; }
.about-block small { color: var(--muted); }

.share-options { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.share-options button, .share-options a { min-height: 78px; display: flex; align-items: center; gap: .75rem; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: inherit; text-decoration: none; cursor: pointer; text-align: left; }
.share-options button:hover, .share-options a:hover { border-color: var(--line-strong); background: var(--surface-2); }
.share-option-icon { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; background: var(--surface); font-weight: 800; }
.share-options span:last-child { display: grid; }
.share-options strong { font-size: .88rem; }
.share-options small { margin-top: .12rem; color: var(--muted); font-size: .71rem; }

.install-help { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; background: rgba(0,0,0,.48); }
.install-help > div { position: relative; width: min(100%, 420px); padding: 1.7rem; border-radius: var(--radius); background: var(--surface); text-align: center; box-shadow: var(--shadow); }
.install-help img { width: 96px; height: 96px; border-radius: 20px; }
.install-help h2 { margin: 1rem 0 .5rem; font-family: Georgia, serif; }
.install-help p { color: var(--muted); }
.install-help button { position: absolute; top: .7rem; right: .7rem; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--surface-2); cursor: pointer; font-size: 1.2rem; }

.toast-region { position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 130; display: grid; gap: .65rem; pointer-events: none; }
.toast { position: relative; width: min(390px, calc(100vw - 2rem)); min-height: 72px; display: grid; align-content: center; padding: .9rem 1rem .9rem 3.6rem; border: 2px solid var(--notice-accent); border-radius: 14px; background: var(--notice-bg); box-shadow: 0 22px 70px rgba(0,0,0,.46), 0 0 0 4px color-mix(in srgb, var(--notice-accent) 18%, transparent); color: var(--notice-text); animation: toast-in .22s ease both; }
.toast::before { content: "✓"; position: absolute; left: 1rem; top: 50%; width: 30px; height: 30px; display: grid; place-items: center; transform: translateY(-50%); border-radius: 50%; background: var(--notice-accent); color: var(--notice-bg); font-weight: 900; }
.toast strong { display: block; font-size: .91rem; }
.toast span { display: block; margin-top: .18rem; color: var(--notice-muted); font-size: .77rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 900px) {
  .grid-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { align-items: start; flex-direction: column; }
  .update-panel { width: 100%; }
}

@media (max-width: 680px) {
  :root { --header-height: 68px; }
  .header-inner { width: min(calc(100% - 1rem), var(--shell)); }
  .brand-mark { width: 46px; height: 46px; border-radius: 12px; }
  .brand-mark img { width: 38px; height: 38px; }
  .brand-copy span { display: none; }
  .header-actions .icon-button { width: 38px; height: 38px; }
  #themeButton { display: none; }
  .hero { padding-top: 1rem; }
  .controls-dock { padding-block: .25rem; }
  .controls { width: calc(100% - .75rem); border-radius: 16px; }
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; }
  .filter-row label, .filter-row select { width: 100%; max-width: none; }
  .segmented { grid-column: 1 / 2; }
  .view-switch { grid-column: 2 / 3; justify-self: end; margin-left: 0; }
  .list-layout .card-open { grid-template-columns: 108px minmax(0, 1fr); min-height: 150px; }
  .card-content { padding: 1rem 3rem 1rem 1rem; }
  .card-title { font-size: 1.12rem; }
  .card-excerpt { -webkit-line-clamp: 2; font-size: .82rem; }
  .card-meta { font-size: .68rem; }
  .grid-layout { grid-template-columns: 1fr; }
  .grid-layout .card-open { grid-template-rows: 190px 1fr; }
  .article-header { padding-top: 1.6rem; }
  .article-header h1 { font-size: 2.45rem; }
  .article-body { padding-top: 1.4rem; line-height: 1.7; }
  .article-navigation { grid-template-columns: 1fr; }
  .article-nav-button.next { text-align: left; }
  .quote-toolbar { align-items: stretch; flex-direction: column; gap: .45rem; }
  .quote-toolbar::before { display: none; }
  .pdf-reader-header { align-items: stretch; flex-direction: column; }
  .pdf-direct-link { width: 100%; justify-content: center; }
  .pdf-frame-wrap { height: 72vh; min-height: 480px; }
  .install-nudge { grid-template-columns: auto 1fr auto; }
  .install-nudge-action { grid-column: 1 / 3; }
  .install-nudge-close { grid-column: 3; grid-row: 1 / 3; }
  .quote-toolbar > div { width: 100%; }
  .quote-toolbar > div button:not(.quote-close) { flex: 1; }
  .share-options { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .brand-copy strong { font-size: .92rem; }
  .filter-row { grid-template-columns: 1fr; }
  .segmented, .view-switch { grid-column: auto; }
  .view-switch { position: absolute; opacity: 0; pointer-events: none; }
  .article-collection.grid-layout { grid-template-columns: 1fr; }
  .list-layout .card-open { grid-template-columns: 1fr; }
  .list-layout .card-image-wrap { height: 165px; }
  .card-content { padding: 1rem; }
  .card-bookmark { top: .7rem; right: .7rem; }
  .article-topbar { min-height: 62px; }
  .small-action { display: none; }
  .article-footer-actions { display: grid; }
}

@media print {
  .app-header, .article-topbar, .article-progress, .article-footer-actions, .quote-help, .article-navigation, .quote-toolbar, .ai-guide-trigger, .toast-region, .install-nudge, .back-to-top, .pdf-frame-wrap { display: none !important; }
  body, html { background: #fff !important; color: #000 !important; }
  .article-view { display: block !important; }
  .archive-view { display: none !important; }
  .article-body, .article-header { width: 100%; max-width: none; }
  .article-body { font-size: 12pt; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.icon-button.is-spinning svg { animation: icon-spin .9s linear infinite; }
@keyframes icon-spin { to { transform: rotate(360deg); } }
.logo-fallback { object-fit: contain !important; padding: 12%; background: #fff; }
.thumbnail-fallback { object-fit: cover !important; padding: 0 !important; background: #d8d5dc; }
