/* Palette and reading defaults */
:root {
  color-scheme: light dark;
  --bg: #fbf8f2;
  --surface: #fffefa;
  --ink: #1f2430;
  --muted: #5e6472;
  --border: #dedbd4;
  --control-border: #858994;
  --accent: #1e3a5f;
  --on-accent: #fffefa;
  --accent-tint: #edf1f5;
  --gold: #b08d57;
  --gold-tint: #f5ecd9;
  --mark-bg: #eddbad;
  --mark-ink: #1f2430;
  --casual-bg: #e7efe5;
  --casual-ink: #34573b;
  --neutral-bg: #e9edf2;
  --neutral-ink: #46546a;
  --formal-bg: #f1e7ed;
  --formal-ink: #673c54;
  --toast-bg: #25262b;
  --toast-ink: #fbf8f2;
  --clear: transparent;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --tab-height: 76px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #201f1d;
    --surface: #292826;
    --ink: #f5f0e6;
    --muted: #b9b7b1;
    --border: #484641;
    --control-border: #85847f;
    --accent: #a7c4e5;
    --on-accent: #17273b;
    --accent-tint: #2c3540;
    --gold-tint: #3d3425;
    --mark-bg: #63502d;
    --mark-ink: #fff5dc;
    --casual-bg: #2c3c30;
    --casual-ink: #bdd6ba;
    --neutral-bg: #333b46;
    --neutral-ink: #c6d2e3;
    --formal-bg: #45313f;
    --formal-ink: #e3bfd2;
  }
}
* { box-sizing: border-box; }
html { font-size: 17px; scroll-padding-block: 80px 110px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  overflow-wrap: anywhere;
}
button, input { font: inherit; }
button, a, label.btn { -webkit-tap-highlight-color: var(--accent-tint); }
button { cursor: pointer; }
a { color: var(--accent); text-underline-offset: 0.18em; }
p { margin: 0 0 1em; }
h1, h2 { font-family: var(--serif); line-height: 1.25; }
svg { flex-shrink: 0; vertical-align: middle; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* App frame */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 6px max(16px, calc((100% - 648px) / 2));
}
.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font: 600 1.15rem/1.2 var(--serif);
  color: var(--ink);
  text-decoration: none;
}
.view {
  width: 100%;
  max-width: 680px;
  margin-inline: auto;
  padding: 0 16px calc(var(--tab-height) + env(safe-area-inset-bottom, 0px) + 32px);
}
.page { padding-top: 26px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.back::before {
  content: '';
  width: 7px;
  height: 7px;
  border-left: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  margin-left: 3px;
}
.page-title { margin: 0 0 10px; font-size: 1.75rem; font-weight: 600; }
.page-sub { margin-bottom: 24px; color: var(--muted); font-size: 1.05rem; }
.title-row { display: flex; align-items: flex-start; gap: 12px; }
.title-row .page-title { flex: 1; min-width: 0; }
.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: 20;
  display: flex;
  min-height: calc(var(--tab-height) + env(safe-area-inset-bottom, 0px));
  padding: 6px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
  text-decoration: none;
}
.tab svg { width: 20px; height: 20px; }
.tab.is-active { color: var(--accent); }
.tab.is-active span { font-weight: 700; }

/* Search and filters */
.search { margin-block: 20px; }
.search-input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.search-input::placeholder { color: var(--muted); opacity: 1; }
.chips, .backup { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 20px; }
.chip, .btn, .pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  max-width: 100%;
  padding: 8px 14px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Featured reading and cards */
.today-card {
  padding: 20px;
  margin-block: 24px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  background: var(--accent-tint);
}
.eyebrow { margin-bottom: 10px; color: var(--muted); font-size: 0.72rem; font-variant: small-caps; letter-spacing: 0.09em; }
.today-text { margin-bottom: 12px; font: 1.35rem/1.45 var(--serif); }
.today-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0; color: var(--muted); font-size: 0.8rem; }
.today-meta a, .phrase-group a { display: inline-flex; align-items: center; min-height: 44px; }
.card-list, .phrase-list { display: grid; gap: 12px; padding: 0; margin: 20px 0; list-style: none; }
.card-list > li { min-width: 0; }
.card-link, .phrase {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}
.card-link { display: block; min-height: 44px; text-decoration: none; }
.card-title { display: block; font: 600 1.15rem/1.35 var(--serif); }
.card-sub { display: block; margin-top: 5px; color: var(--muted); font-size: 0.9rem; }
.card-count { display: block; margin-top: 10px; color: var(--muted); font-size: 0.78rem; }
.card-link .tone { margin-top: 10px; }
.phrase { display: flex; align-items: flex-start; gap: 12px; }
.phrase-main { flex: 1; min-width: 0; }
.phrase-text { margin-bottom: 8px; font: 1.2rem/1.5 var(--serif); }
.phrase-note { color: var(--muted); font-size: 0.85rem; }
.phrase-group { color: var(--muted); font-size: 0.75rem; }
.phrase-main > :last-child { margin-bottom: 0; }
.phrase-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; max-width: 40%; flex-shrink: 0; }
.tone {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--neutral-bg);
  color: var(--neutral-ink);
  font: 500 0.7rem/1.5 var(--sans);
}
.tone-casual { background: var(--casual-bg); color: var(--casual-ink); }
.tone-neutral, .tone-mixed { background: var(--neutral-bg); color: var(--neutral-ink); }
.tone-formal { background: var(--formal-bg); color: var(--formal-ink); }
.star {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--clear);
  color: var(--muted);
}
.star svg { width: 24px; height: 24px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.star.is-on svg { fill: var(--gold); stroke: var(--gold); }

/* Guides and saved reading */
.guide-section { margin-top: 28px; }
.guide-section > h2, .section-title { margin: 28px 0 12px; font-size: 1.15rem; font-weight: 600; }
.guide-list { padding: 0; margin: 0; list-style: none; }
.guide-list > li { position: relative; padding-left: 20px; margin-bottom: 12px; }
.guide-list > li::before { content: ''; position: absolute; left: 2px; top: 0.65em; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.culture-note, .try-box { margin-block: 24px; padding: 18px; border-radius: 10px; background: var(--accent-tint); }
.try-box { background: var(--gold-tint); border-left: 3px solid var(--gold); padding: 20px; }
.culture-note h2, .try-box h2 { margin: 0 0 8px; font-size: 1rem; }
.culture-note p, .try-box p { font-size: 0.9rem; }
.culture-note > :last-child, .try-box > :last-child { margin-bottom: 0; }
.related { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.related-label { flex-basis: 100%; margin-bottom: 2px; color: var(--muted); font-size: 0.8rem; }
.related ul, .related ol { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; list-style: none; }
.empty { padding: 32px 12px; color: var(--muted); font-style: italic; text-align: center; }
.btn { position: relative; border-radius: 8px; }
.fineprint { margin-top: 24px; color: var(--muted); font-size: 0.75rem; }
.blank {
  display: inline-block;
  width: 2.6em;
  height: 1em;
  margin-inline: 0.1em;
  border-bottom: 2px solid var(--gold);
  vertical-align: baseline;
}
mark { padding-inline: 0.08em; border-radius: 2px; background: var(--mark-bg); color: var(--mark-ink); }

/* Feedback and accessibility */
.toast {
  position: fixed;
  z-index: 30;
  bottom: calc(var(--tab-height) + env(safe-area-inset-bottom, 0px) + 14px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 20px;
  border-radius: 24px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.85rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}
.toast.is-shown { opacity: 1; }
.visually-hidden, label.btn input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
label.btn:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
.card-link, .chip, .btn, .pill, .star, .tab { transition: background-color 120ms ease, border-color 120ms ease; }
@media (hover: hover) {
  .card-link:hover { background: var(--accent-tint); border-color: var(--accent); }
  .chip:not(.is-active):hover, .btn:hover, .pill:hover, .star:hover, .tab:hover { background: var(--accent-tint); }
  .back:hover { color: var(--accent); }
}
.card-link:active, .chip:not(.is-active):active, .btn:active, .pill:active, .star:active, .tab:active { background: var(--gold-tint); }
@media (min-width: 700px) {
  html { font-size: 18px; }
  .page { padding-top: 36px; }
}
@media (min-width: 900px) {
  .tabbar { padding-inline: calc((100% - 680px) / 2); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
