/* Say It — book-style reading themes */
:root {
  --fs: 19px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --read: var(--serif);
  --radius: 10px;
}
:root[data-font="sans"] { --read: var(--sans); }
:root[data-font="georgia"] { --read: Georgia, "Times New Roman", serif; }
:root[data-font="palatino"] { --read: "Palatino Linotype", "Book Antiqua", Palatino, serif; }
:root[data-font="humanist"] { --read: "Trebuchet MS", "Segoe UI", sans-serif; }

/* Paper: warm off-white paperback page */
:root, :root[data-theme="paper"] {
  --bg: #f8f4ea; --surface: #fffcf5; --ink: #262220; --muted: #70665a; --line: #e4dbc8;
  --accent: #8a4b2a; --accent-ink: #fffaf0; --accent-soft: #f0e2d2; --shadow: 0 1px 2px rgba(60,40,10,.06), 0 6px 20px rgba(60,40,10,.06);
}
/* Sepia: amber e-reader tone */
:root[data-theme="sepia"] {
  --bg: #efe0c0; --surface: #f6ead0; --ink: #43301f; --muted: #7a6348; --line: #dcc69c;
  --accent: #8b4a1e; --accent-ink: #fff6e2; --accent-soft: #ead3a9; --shadow: 0 1px 2px rgba(70,40,0,.08), 0 6px 20px rgba(70,40,0,.08);
}
/* Night: low-glare warm dark */
:root[data-theme="night"] {
  --bg: #14120e; --surface: #1c1914; --ink: #d9d0bf; --muted: #9a8f7c; --line: #302b22;
  --accent: #e0a46c; --accent-ink: #1a140b; --accent-soft: #2c241a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); line-height: 1.5; min-height: 100vh;
  display: flex; flex-direction: column;
  transition: background .25s, color .25s;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
a { color: var(--accent); text-underline-offset: 3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 99; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .6rem max(16px, 4vw); padding-top: calc(.6rem + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; min-width: 0; margin-right: auto; flex: 0 1 auto; }
.brand img { display: block; width: clamp(135px, 20vw, 220px); max-width: 100%; height: auto; }
:root[data-theme="night"] .brand img { filter: brightness(0) invert(1); }
.nav { display: flex; align-items: center; gap: .25rem; }
.nav a { color: var(--ink); text-decoration: none; padding: .45rem .75rem; border-radius: 999px; font-size: .95rem; }
.nav a:hover { background: var(--accent-soft); }
.nav a.on { background: var(--accent-soft); font-weight: 600; }
.nav a.cta { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.auth-actions { display: flex; flex-shrink: 0; }
.auth-actions a, .auth-actions button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  padding: .45rem .75rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--accent); font: inherit; font-size: .9rem; text-decoration: none;
}
.auth-actions a:hover, .auth-actions button:hover { background: var(--accent-soft); }
.prefs-wrap { position: relative; }
.btn-aa { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; width: 40px; height: 40px; font-family: var(--serif); font-weight: 700; font-size: 1.1rem; }
.btn-aa small { font-size: .7em; font-weight: 400; }
.prefs {
  position: absolute; right: 0; top: calc(100% + 8px); width: 260px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; display: grid; gap: 10px;
}
.prefs-row { display: flex; gap: 6px; align-items: center; }
.prefs-row > * { flex: 1; }
.swatch, .chip { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .3rem; background: var(--bg); text-align: center; }
.swatch.sw-paper { background: #f8f4ea; color: #262220; }
.swatch.sw-sepia { background: #efe0c0; color: #43301f; }
.swatch.sw-night { background: #14120e; color: #d9d0bf; }
.f-serif { font-family: var(--serif); }
.f-georgia { font-family: Georgia, "Times New Roman", serif; }
.f-palatino { font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif; }
.f-sans { font-family: var(--sans); }
.f-humanist { font-family: "Trebuchet MS", "Segoe UI", sans-serif; }
.size-val { text-align: center; color: var(--muted); font-size: .85rem; }
[aria-pressed="true"], .swatch.active, .chip.active { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- layout ---------- */
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 24px 16px 56px; outline: none; }
.foot { text-align: center; color: var(--muted); padding: 28px 16px calc(28px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); font-family: var(--serif); }
.foot p { margin: .2rem 0; } .foot .fine { font-family: var(--sans); font-size: .8rem; }
.foot-links { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin: .7rem 0; font: .85rem var(--sans); }
.legal, .contact-page, .messages, .support-queue { max-width: 650px; margin: 0 auto; }
.legal h2 { font-size: 1.25rem; margin: 1.5rem 0 .25rem; }
.legal p { line-height: 1.7; }
.faq details { border-top: 1px solid var(--line); padding: .8rem 0; }
.faq summary { cursor: pointer; font-weight: 700; }
.faq details p { margin: .6rem 0 0; }
.contact-page form, .messages form { max-width: 600px; }
.contact-page select { width: 100%; }
.message-item, .ticket { border-top: 1px solid var(--line); padding: 1rem 0; }
.message-item p, .ticket p { overflow-wrap: anywhere; white-space: pre-wrap; }
.message-item small, .ticket small { color: var(--muted); }
.ticket-reply { padding: .5rem 1rem; border-left: 2px solid var(--accent); margin: .75rem 0; }

h1, h2, h3 { font-family: var(--serif); line-height: 1.2; letter-spacing: -.01em; }
.hero { padding: 28px 0 8px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.1rem); margin: 0 0 .4rem; }
.hero h1 em { color: var(--accent); }
.hero p { color: var(--muted); font-family: var(--serif); font-size: 1.15rem; max-width: 34em; margin: 0 auto 1.1rem; }
.btn {
  display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: .65rem 1.2rem; border-radius: 999px; font-weight: 600; text-decoration: none; font-size: .98rem;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: .35rem .8rem; font-size: .85rem; }
.btn.danger { background: transparent; color: #b3261e; border-color: #b3261e; }
:root[data-theme="night"] .btn.danger { color: #ff8f86; border-color: #ff8f86; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row.center { justify-content: center; }
.spread { justify-content: space-between; }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 22px 0 14px; }
.toolbar .grow { flex: 1; }
.pill { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .35rem .9rem; font-size: .9rem; }
.pill.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input:not([type]), input[type=search], input[type=text], input[type=email], input[type=url], input[type=password],
input[type=tel], input[type=number], input[type=date], input[type=month], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .65rem .8rem;
  font-size: 1rem; min-width: 0; min-height: 44px;
}
input[type=search] { max-width: 220px; border-radius: 999px; }
textarea { resize: vertical; }
label { display: block; font-size: .9rem; font-weight: 600; margin: 14px 0 6px; }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.err { color: #b3261e; font-size: .9rem; min-height: 1.2em; margin: 8px 0 0; }
:root[data-theme="night"] .err { color: #ff8f86; }
.ok { color: #2f7d3a; } :root[data-theme="night"] .ok { color: #8fd69a; }

/* ---------- cards ---------- */
.card {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin: 0 0 14px;
  color: inherit; text-decoration: none; box-shadow: var(--shadow); transition: transform .12s;
}
a.card:hover { transform: translateY(-1px); }
.card h2 { margin: 0 0 .25rem; font-size: 1.3rem; }
.card .meta { color: var(--muted); font-size: .85rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card .excerpt { font-family: var(--read); color: var(--ink); opacity: .9; margin: .6rem 0 .7rem; white-space: pre-line; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.tag { border: 1px solid var(--line); border-radius: 999px; padding: 0 .55rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.thumbs { display: inline-flex; gap: .3rem; align-items: center; color: var(--muted); font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-family: var(--serif); }

/* ---------- reader (the book page) ---------- */
.page {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px 14px 14px 6px; box-shadow: var(--shadow);
  padding: clamp(24px, 6vw, 56px) clamp(20px, 7vw, 64px); margin: 4px 0 20px; position: relative;
  border-left: 6px solid var(--accent-soft);
}
.page h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); margin: 0 0 .4rem; text-align: center; }
.byline { text-align: center; color: var(--muted); font-family: var(--serif); font-style: italic; margin-bottom: 1.6rem; }
.byline .orn { display: block; letter-spacing: .5em; margin-top: .8rem; font-style: normal; color: var(--accent); }
.text { font-family: var(--read); font-size: var(--fs); line-height: 1.75; max-width: 34em; margin: 0 auto; hyphens: auto; text-wrap: pretty; }
.text p { margin: 0 0 1.05em; }
.text.story p { text-indent: 1.5em; margin-bottom: 0; }
.text.story p:first-child { text-indent: 0; }
.text.story p:first-child::first-letter { float: left; font-size: 3.3em; line-height: .9; padding: .06em .1em 0 0; color: var(--accent); font-family: var(--serif); font-weight: 700; }
.text.poem { text-align: left; }
.text.poem .stanza { margin: 0 0 1.5em; }
.text.poem .ln { display: block; padding-left: 1.5em; text-indent: -1.5em; }
.end { text-align: center; color: var(--accent); letter-spacing: .6em; margin: 2rem 0 .5rem; }
.like-bar { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-top: 1.2rem; }
.reactions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.reaction-btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: var(--surface); padding: .5rem .75rem; border-radius: 6px; font-weight: 600; }
.reaction-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.reaction-btn svg, .reaction-btn .down-icon { display: inline-flex; width: 1.1em; height: 1.1em; }
.reaction-btn .down-icon svg { transform: rotate(180deg); }
.reaction-btn .heart-icon { color: #ad3d45; font-size: 1.1em; line-height: 1; }
.reaction-btn.active .heart-icon { color: #ad3d45; }
.reaction-btn.tip-btn { border-color: var(--accent); color: var(--accent); }
.comments { margin-top: 26px; }
.comments h2 { display: flex; align-items: baseline; gap: .55rem; font-size: 1.35rem; }
.comment-total { color: var(--muted); font: 500 .85rem var(--sans); }
.comment-list { margin-bottom: 18px; }
.comment { border-top: 1px solid var(--line); padding: 12px 0; }
.comment-meta { display: flex; gap: .65rem; align-items: baseline; flex-wrap: wrap; font-size: .9rem; }
.comment-meta time { color: var(--muted); font-size: .8rem; }
.comment-meta .report-link { margin-left: auto; }
.comment p { margin: .35rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form-meta { display: flex; justify-content: space-between; gap: 1rem; margin: .25rem 0 .75rem; }
.comments textarea { width: 100%; resize: vertical; }
.share { display: flex; gap: .5rem; align-items: center; justify-content: center; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.share code { background: var(--accent-soft); padding: .2rem .55rem; border-radius: 6px; font-size: .85rem; word-break: break-all; }
.author-card { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; text-decoration: none; color: inherit; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--serif); font-weight: 700; font-size: 1.2rem; flex: none; }
.avatar-photo { object-fit: cover; }
.profile-avatar { width: 72px; height: 72px; margin: 0 auto 10px; font-size: 1.7rem; }
.avatar-editor { display: flex; align-items: center; gap: 14px; margin: 16px 0; }
.avatar-fields { min-width: 0; flex: 1; }
.avatar-fields label { margin-top: 0; }
.avatar-fields input[type="file"] { display: block; width: 100%; max-width: 100%; font: .9rem var(--sans); }
.avatar-fields .hint { margin: .4rem 0; }
.avatar.anon { background: var(--accent-soft); color: var(--accent); }

/* ---------- forms / account ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin: 0 0 16px; box-shadow: var(--shadow); }
.danger-zone { border-color: color-mix(in srgb, #ad3d45 42%, var(--line)); }
.danger-zone h2 { color: #8f3038; }
.panel h2 { margin-top: 0; font-size: 1.25rem; }
.profile-actions { flex-wrap: wrap; margin-top: 12px; }
.report-link { margin-top: .5rem; }
.moderation-report { margin: 12px 0; }
.report-snapshot { background: var(--bg); border-left: 3px solid var(--accent-soft); padding: 10px 12px; margin: .6rem 0; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14em; overflow: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: .45rem 1.1rem; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); outline: none; }
.write-area { font-family: var(--read); font-size: var(--fs); line-height: 1.7; min-height: 46vh; }
.write-title { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; margin: 16px 0 0; }
.check input { flex-shrink: 0; margin-top: .3rem; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.linkbox { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.linkbox code { background: var(--accent-soft); padding: .35rem .6rem; border-radius: 8px; word-break: break-all; }
.price { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; }
.mine-item { display: flex; gap: 10px; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.mine-item:first-of-type { border-top: 0; }

.native-shell { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
.native-shell .nav { display: none; }
.native-tabs {
  display: none;
}
.native-shell .native-tabs {
  position: fixed; inset: auto 0 0; z-index: 40; display: flex; justify-content: space-around; align-items: stretch;
  min-height: 62px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.native-tabs a {
  display: flex; min-width: 56px; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font: .72rem var(--sans); border-radius: 8px;
}
.native-tabs a span:first-child { font-size: 1.2rem; line-height: 1.1; }
.native-tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.native-shell #view { padding-bottom: 10px; }
.native-shell .foot { padding-bottom: 12px; }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 22px; max-width: min(440px, 92vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20,14,6,.5); }
dialog h2 { margin-top: 0; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: .65rem 1.1rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .top { flex-wrap: wrap; gap: .4rem; padding-left: 12px; padding-right: 12px; }
  .brand img { width: clamp(128px, 40vw, 170px); }
  .nav { order: 3; width: 100%; justify-content: center; flex-wrap: wrap; gap: 0; }
  .nav a { padding: .38rem .5rem; font-size: .84rem; }
  .text.poem .ln { padding-left: 1em; text-indent: -1em; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .top, .foot, .like-bar, .share, .btn-aa { display: none !important; } body { background: #fff; } .page { box-shadow: none; border: 0; } }
