:root {
  --bg: #fbf7ef; --card: #ffffff; --ink: #1f1a2e; --muted: #5f5975; --line: #e6dfd0;
  --brand: #2a1f45; --brand-ink: #ffffff; --accent: #237a52; --accent-ink: #ffffff; --warn: #a44a17; --danger: #b3261e;
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171226; --card: #221a38; --ink: #f1ecff; --muted: #b0a8c8; --line: #3a2e57; --accent: #48bd88; --accent-ink: #10261b; --warn: #f2b441; --danger: #ff8a80; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 20px; }
h3 { font-size: 17px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- controls --- */
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; max-width: 100%; }
textarea { width: 100%; min-height: 76px; resize: vertical; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font-weight: 500; cursor: pointer; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.button.danger { color: var(--danger); }
.button:disabled { opacity: .45; cursor: default; }
.linklike { display: block; margin: 6px auto 0; padding: 10px; background: none; border: 0; color: var(--muted); text-decoration: underline; text-align: center; cursor: pointer; }
.sub, .quiet { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.quiet { font-size: 15px; padding: 4px 0 8px; }

/* --- frame: header, navigation --- */
header.top { background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 18px; min-height: 44px; margin-right: auto; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
header.top .add { background: #ffffff; color: var(--brand); border-color: #ffffff; font-weight: 600; }
nav.main { display: flex; }
nav.main a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--nav-h); flex: 1; text-decoration: none; font-size: 13px; color: #ffffffcc; position: relative; }
nav.main a[aria-current="page"] { color: #ffffff; font-weight: 700; box-shadow: inset 0 3px 0 #ffffff; }
nav.main .dot { position: absolute; top: 6px; left: calc(50% + 8px); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #f2b441; color: #2a1f45; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
/* Phones: the three destinations sit at the bottom, under the thumb. */
@media (max-width: 719px) {
  nav.main { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--brand); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid #ffffff22; }
  main { padding-bottom: calc(var(--nav-h) + 40px + env(safe-area-inset-bottom)) !important; }
  .toast { bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)) !important; }
}
/* Wider screens: they join the header. */
@media (min-width: 720px) {
  .brand { margin-right: 12px; }
  nav.main { margin-right: auto; gap: 4px; }
  nav.main a { flex-direction: row; gap: 8px; min-height: 44px; padding: 0 14px; font-size: 15px; border-radius: 10px; flex: none; }
  nav.main a[aria-current="page"] { box-shadow: none; background: #ffffff26; }
  nav.main .dot { position: static; }
}

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 48px; }
main > h2, main > div > h2 { margin: 2px 0 14px; }
main.solo { padding-top: 28px; }
section { margin-bottom: 26px; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; min-height: 28px; }
.heading .quiet { padding: 0; }

/* --- story cards --- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.card h3 a { text-decoration: none; display: inline-block; padding: 2px 0; }
.card h3 a:hover { text-decoration: underline; }
.news { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -4px 0 6px; }
.quiet-button { margin-left: auto; border-color: transparent; background: none; color: var(--muted); text-decoration: underline; padding: 4px 8px; }
.badge { font-size: 13px; border-radius: 999px; padding: 3px 10px; border: 1px solid var(--line); color: var(--muted); }
.badge.new { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.state { font-size: 14px; font-weight: 600; margin: 10px 0 4px; padding-left: 10px; border-left: 4px solid currentColor; }
.state span { font-weight: 400; }
.state.done { color: var(--accent); }
.state.wip { color: var(--warn); }
.state.stale { color: var(--danger); }
.position { font-size: 15px; margin-top: 6px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 2px; }
.bar > div { height: 100%; background: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions.end { justify-content: flex-end; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-top: 10px; padding: 10px 0; min-height: 44px; }
.field { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 10px; }
.field.column { flex-direction: column; align-items: stretch; }
.field label, .field .label { font-size: 14px; font-weight: 600; min-width: 120px; }
.stepper { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stepper .button { min-width: 44px; }
.stepper .value { min-width: 64px; text-align: center; }
.stars { display: inline-flex; }
.stars button { background: none; border: 0; font-size: 26px; line-height: 1; min-width: 40px; min-height: 44px; padding: 0; color: var(--muted); cursor: pointer; }
.stars button.on { color: var(--warn); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* --- library controls --- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: thin; }
.chip { flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #ffffff; font-weight: 600; }
.chip .count { margin-left: 6px; font-size: 13px; opacity: .8; }
.search { width: 100%; }
.filters { margin-bottom: 10px; }
.filters[open] { margin-bottom: 16px; }
.filters .field select { flex: 1; min-width: 0; }

/* --- account, privacy --- */
form.inline { display: flex; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; align-items: center; }
form.inline label { flex: 1 1 100%; font-size: 14px; font-weight: 600; }
form.inline input { flex: 1; min-width: 160px; }
.card > h3 + .sub, .card > h3 + p { margin-top: 4px; }
.card > p { margin-top: 6px; }
ul.plain { list-style: none; padding: 0; margin: 8px 0 0; }
ul.plain li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
ul.plain li:first-child { border-top: 0; }
ul.plain li > span { flex: 1; overflow-wrap: anywhere; }
.token { font-family: ui-monospace, monospace; overflow-wrap: anywhere; background: var(--bg); padding: 10px; border-radius: 8px; user-select: all; margin-top: 8px; }
.notice { border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; background: var(--card); border: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.notice.err { color: var(--danger); border-color: currentColor; }
.card .notice { margin-top: 12px; display: block; }
.card .notice .button { margin-top: 10px; }

/* --- empty states, sign-in, dialog, toast --- */
.empty { text-align: center; padding: 36px 12px; display: grid; gap: 14px; justify-items: center; }
.empty img { border-radius: 22px; }
.empty p { max-width: 420px; }
.empty.small { padding: 24px 12px; }
.auth { max-width: 380px; margin: 0 auto; padding: 44px 16px; text-align: center; }
.auth img { width: 96px; height: 96px; border-radius: 22px; margin-bottom: 10px; }
.auth h1 { font-size: 30px; }
.auth > p { color: var(--muted); margin: 4px 0 20px; }
.auth form { display: grid; gap: 10px; text-align: left; }
.auth .notice { text-align: left; }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(460px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: #0f0a1ecc; }
dialog input, dialog select { width: 100%; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 10; background: var(--brand); color: #ffffff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 6px 24px #0006; max-width: calc(100vw - 32px); border: 1px solid #ffffff33; }
