/* SPLbooks — design follows familiar Apple (iOS / macOS) interface conventions. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-secondary: #f2f2f7;
  --fill: rgba(118, 118, 128, .12);
  --fill-strong: rgba(120, 120, 128, .2);
  --seg-active: #ffffff;
  --label: #1c1c1e;
  --label-2: rgba(60, 60, 67, .75);
  --label-3: rgba(60, 60, 67, .45);
  --separator: rgba(60, 60, 67, .18);
  --tint: #0a6cdf;
  --tint-soft: rgba(10, 108, 223, .11);
  --danger: #d70015;
  --danger-soft: rgba(215, 0, 21, .09);
  --green: #34c759;
  --warn-bg: rgba(255, 149, 0, .14);
  --warn-text: #9a5200;
  --bar: rgba(249, 249, 251, .8);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);
  --radius: 14px;
  --radius-lg: 20px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, "Times New Roman", serif;
  --story-size: 1.18rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --fill: rgba(118, 118, 128, .24);
    --fill-strong: rgba(120, 120, 128, .36);
    --seg-active: #636366;
    --label: #f5f5f7;
    --label-2: rgba(235, 235, 245, .7);
    --label-3: rgba(235, 235, 245, .38);
    --separator: rgba(84, 84, 88, .65);
    --tint: #0a84ff;
    --tint-soft: rgba(10, 132, 255, .2);
    --danger: #ff453a;
    --danger-soft: rgba(255, 69, 58, .16);
    --green: #30d158;
    --warn-bg: rgba(255, 159, 10, .18);
    --warn-text: #ffb340;
    --bar: rgba(22, 22, 24, .78);
    --shadow: none;
  }
}

/* Each writer's ink. Elements set --ink; text uses --ink-text, which is lightened in dark mode. */
* { --ink-text: var(--ink, var(--label)); }
@media (prefers-color-scheme: dark) {
  * { --ink-text: color-mix(in oklab, var(--ink, #ffffff) 55%, #ffffff); }
}
.ink { color: var(--ink-text); }

* { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: var(--sans);
  line-height: 1.47;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--tint); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--display); line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.015em; }
h1 { font-size: 2.1rem; font-weight: 700; letter-spacing: -.025em; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 3px solid var(--tint); outline-offset: 2px; border-radius: 6px; }
.icon { flex: none; display: block; }

/* ---------- Top bar & navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem max(1rem, env(safe-area-inset-right)) .55rem max(1rem, env(safe-area-inset-left));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--separator);
}
.brand {
  display: inline-flex; align-items: center; gap: .55rem;
  font: 700 1.15rem/1 var(--display); letter-spacing: -.02em; color: var(--label);
}
.brand:hover { text-decoration: none; }
.brand > span:not(.logo) { font-weight: 500; color: var(--label-2); margin-left: -.5rem; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #ff9f0a, #ff375f);
  box-shadow: 0 1px 3px rgba(255, 55, 95, .35);
}
.brand.big { font-size: 1.6rem; justify-content: center; width: 100%; margin-bottom: 1rem; }
.brand.big .logo { width: 44px; height: 44px; border-radius: 11px; }

.mainnav {
  display: flex; gap: 2px; margin: 0 auto; padding: 2px;
  background: var(--fill); border-radius: 10px;
}
.mainnav a {
  display: flex; align-items: center; gap: .4rem;
  padding: .36rem .9rem; border-radius: 8px;
  color: var(--label); font-size: .9rem; font-weight: 500;
  transition: background .15s;
}
.mainnav a:hover { text-decoration: none; background: var(--fill); }
.mainnav a.active { background: var(--seg-active); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }
.mainnav .icon { width: 17px; height: 17px; }

.me-chip {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--fill); border: 0; border-radius: 999px;
  padding: 3px 14px 3px 3px; min-height: 38px;
  font: 600 .9rem var(--sans); color: var(--label); cursor: pointer;
}
.me-chip:hover { background: var(--fill-strong); }
.me-chip .name { color: var(--ink-text); }
.me-chip.empty { background: var(--tint); color: #fff; padding: 0 16px; }

/* ---------- Layout ---------- */
main { max-width: 50rem; margin: 0 auto; padding: 1.75rem max(1rem, env(safe-area-inset-right)) 5rem max(1rem, env(safe-area-inset-left)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head h1 { margin-bottom: .15rem; }
.page-head p { color: var(--label-2); margin: 0; }
.muted { color: var(--label-2); }
.small { font-size: .85rem; }
.center { text-align: center; }
.spacer { flex: 1; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.back {
  display: inline-flex; align-items: center; gap: .1rem; margin: 0 0 .9rem -.35rem;
  font-size: 1.02rem; color: var(--tint);
}
.back:hover { text-decoration: none; opacity: .7; }
.loading { color: var(--label-3); padding: 4rem 0; text-align: center; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 1rem 1.1rem; border-radius: var(--radius); }
.empty-state {
  text-align: center; padding: 3rem 1.5rem; border-radius: var(--radius-lg);
  background: var(--bg-elevated); color: var(--label-2); box-shadow: var(--shadow);
}
.empty-state h2 { color: var(--label); }

.badge {
  display: inline-block; font-size: .7rem; font-weight: 600; letter-spacing: .01em;
  background: var(--tint-soft); color: var(--tint); border-radius: 999px; padding: .12rem .55rem; vertical-align: middle;
}
.new-dot {
  display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 600; color: var(--tint);
  white-space: nowrap;
}
.new-dot::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--tint); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: 600 .95rem/1.2 var(--sans); letter-spacing: -.01em;
  padding: .62rem 1.15rem; min-height: 44px;
  border: 0; border-radius: 12px;
  background: var(--fill); color: var(--label);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--tint); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.tinted { background: var(--tint-soft); color: var(--tint); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.quiet { background: transparent; color: var(--tint); padding: .35rem .55rem; min-height: 34px; font-weight: 500; }
.btn.quiet:hover { background: var(--tint-soft); filter: none; }
.btn.quiet.danger { color: var(--danger); background: transparent; }
.btn.quiet.danger:hover { background: var(--danger-soft); }
.btn.small { font-size: .85rem; padding: .4rem .85rem; min-height: 34px; border-radius: 999px; }
.btn.quiet.small { padding: .3rem .55rem; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }

/* ---------- Form controls ---------- */
.field { display: block; margin-bottom: 1.25rem; }
.field > span {
  display: block; margin: 0 0 .4rem .15rem;
  font-size: .78rem; font-weight: 500; text-transform: uppercase; letter-spacing: .03em; color: var(--label-2);
}
.field .hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--label-3); }
input[type=text], input[type=password], textarea {
  width: 100%; font: 400 1rem/1.45 var(--sans); color: var(--label);
  background: var(--fill); border: 0; border-radius: 12px; padding: .75rem .95rem;
  transition: box-shadow .15s, background .15s;
}
textarea { resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: var(--label-3); }
input[type=text]:focus, input[type=password]:focus, textarea:focus {
  outline: none; background: var(--bg-elevated); box-shadow: 0 0 0 2px var(--tint), 0 0 0 6px var(--tint-soft);
}
.form-error { color: var(--danger); font-weight: 500; }
.ink-input { font-family: var(--serif); font-size: var(--story-size); line-height: 1.65; color: var(--ink-text); min-height: 8rem; }

/* iOS-style switch */
input.switch {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 51px; height: 31px; border-radius: 999px; position: relative; cursor: pointer;
  background: var(--fill-strong); transition: background .25s;
}
input.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16);
  transition: transform .25s cubic-bezier(.3, .7, .4, 1);
}
input.switch:checked { background: var(--green); }
input.switch:checked::after { transform: translateX(20px); }
.toggle { display: inline-flex; flex-direction: row-reverse; align-items: center; gap: .6rem; cursor: pointer; font-size: .95rem; min-height: 44px; }

/* Text-size stepper */
.sizer { display: inline-flex; align-items: stretch; background: var(--fill); border-radius: 9px; padding: 2px; }
.sizer button {
  font: inherit; border: 0; background: transparent; color: var(--label); cursor: pointer;
  min-width: 44px; min-height: 36px; border-radius: 7px; display: grid; place-items: center;
}
.sizer button:hover { background: var(--seg-active); }
.sizer button + button { position: relative; }
.sizer button + button::before { content: ""; position: absolute; left: -1px; top: 25%; bottom: 25%; width: 1px; background: var(--separator); }
.a-sm { font-size: .8rem; font-weight: 600; }
.a-lg { font-size: 1.15rem; font-weight: 600; }

/* ---------- Book covers ---------- */
.cover {
  flex: none; width: 54px; height: 74px; border-radius: 4px 9px 9px 4px;
  background: linear-gradient(155deg, var(--c1), var(--c2));
  color: rgba(255, 255, 255, .95); font: 600 1.6rem/1 var(--serif);
  display: grid; place-items: center; text-shadow: 0 1px 2px rgba(0, 0, 0, .2);
  box-shadow: inset 3px 0 0 rgba(0, 0, 0, .14), inset 4px 0 0 rgba(255, 255, 255, .15), 0 2px 6px rgba(0, 0, 0, .14);
}
.cover.lg { width: 92px; height: 128px; font-size: 2.6rem; border-radius: 5px 12px 12px 5px; box-shadow: inset 4px 0 0 rgba(0, 0, 0, .14), inset 5px 0 0 rgba(255, 255, 255, .15), 0 8px 24px rgba(0, 0, 0, .18); }

/* ---------- Story list (inset grouped) ---------- */
.story-list { background: var(--bg-elevated); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
.story-row { position: relative; display: flex; align-items: center; gap: .25rem; padding-right: .5rem; transition: background .15s; }
.story-row:hover { background: rgba(118, 118, 128, .06); }
.story-row + .story-row::before { content: ""; position: absolute; top: 0; left: 86px; right: 0; border-top: .5px solid var(--separator); }
.story-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 1rem; padding: .9rem .25rem .9rem 1rem; color: var(--label); }
.story-main:hover { text-decoration: none; }
.story-main .info { flex: 1; min-width: 0; display: grid; gap: .15rem; }
.story-main .title-line { display: flex; align-items: center; gap: .6rem; }
.story-main h2 { font-size: 1.1rem; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-main .desc { margin: 0; color: var(--label-2); font-size: .9rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.story-main .meta { font-size: .8rem; color: var(--label-3); }
.story-main .chev { color: var(--label-3); }
.story-main .inkdots { margin-top: .3rem; }
.inkdots { display: inline-flex; }
.inkdots .avatar { margin-right: -6px; box-shadow: 0 0 0 2px var(--bg-elevated); }

/* ---------- Avatars ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; object-fit: cover; overflow: hidden; user-select: none;
  background: var(--ink, #8e8e93);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .2), rgba(0, 0, 0, .08));
  color: #fff; font-weight: 600; font-family: var(--sans); letter-spacing: .02em;
}
img.avatar { background-image: none; box-shadow: 0 0 0 2px var(--ink-text); }

/* ---------- Story page ---------- */
.story-head { display: flex; gap: 1.4rem; align-items: flex-end; margin-bottom: 1.25rem; }
.story-head .head-text { min-width: 0; }
.story-head h1 { font-family: var(--serif); font-weight: 700; font-size: 2.2rem; letter-spacing: -.01em; margin-bottom: .3rem; }
.story-head .desc { font-family: var(--serif); font-style: italic; color: var(--label-2); font-size: 1.08rem; margin-bottom: .4rem; }
.story-head .muted { color: var(--label-3); margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; margin-bottom: 1rem; }
.toolbar .btn .icon { width: 16px; height: 16px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .9rem; font-size: .85rem; color: var(--label-3); margin: 0 0 1rem .2rem; }
.legend .who { display: inline-flex; align-items: center; gap: .35rem; }
.legend .who b { color: var(--ink-text); font-weight: 600; }

.manuscript {
  background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 2.1rem 2.4rem 1.4rem;
}
.passage { position: relative; padding: .1rem 0 .1rem 1.15rem; margin: 0 0 1.5rem; border-radius: 6px; }
.passage::before { content: ""; position: absolute; left: 0; top: .35rem; bottom: .35rem; width: 3px; border-radius: 3px; background: var(--ink-text); opacity: .85; }
.passage .text { color: var(--ink-text); font-family: var(--serif); font-size: var(--story-size); line-height: 1.7; }
.passage .text p { margin: 0 0 .75em; }
.scene-break { text-align: center; letter-spacing: .6em; color: var(--label-3); }
.passage.chapter { padding-left: 0; margin-top: 2.4rem; text-align: center; }
.passage.chapter::before { display: none; }
.manuscript > .passage.chapter:first-child { margin-top: 0; }
.passage.chapter h2 { font-family: var(--serif); color: var(--ink-text); font-size: calc(var(--story-size) * 1.5); font-weight: 700; margin-bottom: .25rem; letter-spacing: -.01em; }
.passage.chapter .byline { justify-content: center; }
.passage.is-new { background: linear-gradient(90deg, var(--tint-soft), transparent 65%); }
.colors-off .passage *, .colors-off .passage { --ink-text: var(--label); }
.colors-off .passage::before { background: var(--separator); }

.byline { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .8rem; color: var(--label-3); margin-top: .1rem; }
.byline .who { font-weight: 600; color: var(--ink-text); }
.byline .actions { display: inline-flex; flex-wrap: wrap; gap: .1rem; margin-left: .2rem; }
.byline .actions .icon { width: 15px; height: 15px; }
.passage:has(.editor) > .byline .actions { display: none; }
.more-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0 .2rem; }
.more-actions .btn { background: var(--fill); color: var(--label); border-radius: 999px; padding: .38rem .8rem; font-weight: 500; }
.more-actions .btn:hover { background: var(--fill-strong); }
.more-actions .btn.danger { color: var(--danger); }
.more-actions .icon { width: 15px; height: 15px; }

.notice { font-size: .85rem; border-radius: 10px; padding: .45rem .75rem; margin: .3rem 0 .5rem; display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.notice.editing { background: var(--warn-bg); color: var(--warn-text); }
.notice.draft { background: var(--tint-soft); color: var(--tint); }
.editor { margin: .2rem 0 .6rem; }
.editor .row { margin-top: .6rem; }
.saved-note { font-size: .8rem; color: var(--label-3); }

.composer { margin-top: 1.75rem; padding-top: 1.4rem; border-top: .5px solid var(--separator); }
.composer.inline { margin: .4rem 0 1.4rem; padding: 1rem; border: 0; border-radius: var(--radius); background: var(--bg-secondary); }
.composer.inline textarea { background: var(--bg-elevated); }
.composer h3 { margin-bottom: .3rem; }
.composer .as { font-size: .85rem; color: var(--label-2); margin-bottom: .6rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.composer .row { margin-top: .7rem; }
.composer .row .icon { width: 16px; height: 16px; }

/* Discussion — message bubbles */
.discussion { margin-top: 2.5rem; }
.discussion > h2 { margin-left: .2rem; }
.discussion > p { color: var(--label-2); margin-left: .2rem; }
.discussion-list { background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.comment { display: flex; align-items: flex-end; gap: .55rem; padding: .35rem 0; }
.comment .body { min-width: 0; max-width: 78%; }
.comment .head { font-size: .75rem; color: var(--label-3); display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; margin: 0 0 .2rem .75rem; }
.comment .head b { color: var(--ink-text); font-weight: 600; }
.comment .head .btn { min-height: 0; padding: .1rem .35rem; font-size: .75rem; color: var(--label-3); }
.comment .head .btn:hover { color: var(--danger); }
.comment .text {
  display: inline-block; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--fill); color: var(--label); padding: .55rem .9rem; border-radius: 18px; border-bottom-left-radius: 6px;
}
.comment.mine { flex-direction: row-reverse; }
.comment.mine .body { text-align: right; }
.comment.mine .head { justify-content: flex-end; margin: 0 .75rem .2rem 0; }
.comment.mine .text { background: var(--tint); color: #fff; text-align: left; border-radius: 18px; border-bottom-right-radius: 6px; }
.comment-form { display: flex; gap: .5rem; align-items: flex-end; margin-top: .9rem; padding-top: .9rem; border-top: .5px solid var(--separator); }
.comment-form textarea { border-radius: 20px; min-height: 44px; padding: .6rem 1rem; }
.comment-form .row { margin: 0 !important; }
.comment-form .btn { border-radius: 999px; }

.pending-banner {
  position: sticky; top: 4.1rem; z-index: 10; margin: 0 0 1rem;
  background: var(--bg-elevated); color: var(--tint); border-radius: 999px; padding: .55rem 1rem; font-size: .88rem; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .1); width: fit-content; max-width: 100%;
}

/* ---------- Writers ---------- */
.writer-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(14.5rem, 1fr)); }
.writer-card {
  background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 1.5rem 1.2rem 1.2rem; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .35rem;
}
.writer-card .name { font-family: var(--display); font-size: 1.2rem; font-weight: 600; color: var(--ink-text); margin-top: .5rem; letter-spacing: -.01em; }
.writer-card .bio { color: var(--label-2); font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.writer-card .stats { font-size: .78rem; color: var(--label-3); }
.writer-card .you { font-size: .7rem; font-weight: 600; color: var(--tint); background: var(--tint-soft); border-radius: 999px; padding: .1rem .55rem; }
.writer-card .actions { margin-top: auto; padding-top: .6rem; }

.pick-list { display: grid; gap: 0; margin: .9rem 0 1rem; background: var(--bg-secondary); border-radius: var(--radius); overflow: hidden; }
.pick {
  display: flex; align-items: center; gap: .75rem; font: inherit; text-align: left; color: var(--label);
  padding: .6rem 1rem; min-height: 56px; border: 0; background: transparent; cursor: pointer; position: relative;
}
.pick + .pick::before { content: ""; position: absolute; top: 0; left: 4rem; right: 0; border-top: .5px solid var(--separator); }
.pick:hover { background: var(--fill); }
.pick b { color: var(--ink-text); font-weight: 600; flex: 1; }
.pick::after { content: "›"; color: var(--label-3); font-size: 1.4rem; line-height: 1; }

/* ---------- Profile form ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: .7rem; margin: .4rem 0 .7rem .15rem; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; position: relative;
  background: var(--ink); background-image: linear-gradient(180deg, rgba(255, 255, 255, .18), rgba(0, 0, 0, .06));
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-checked=true] { box-shadow: 0 0 0 3px var(--bg-elevated), 0 0 0 5.5px var(--ink-text); }
.swatch[aria-checked=true]::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 1rem; }
.swatch .taken {
  position: absolute; right: -7px; bottom: -6px; background: var(--bg-elevated); color: var(--label-2); border-radius: 999px;
  font-size: .58rem; font-weight: 700; padding: 0 .3rem; box-shadow: 0 0 0 .5px var(--separator), 0 1px 3px rgba(0, 0, 0, .12);
}
.custom-color { display: inline-flex; align-items: center; gap: .6rem; font-size: .88rem; color: var(--label-2); margin-left: .15rem; cursor: pointer; }
.custom-color input { width: 40px; height: 40px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 50%; }
.ink-preview {
  position: relative; font-family: var(--serif); font-size: 1.15rem; color: var(--ink-text);
  padding: .8rem 1rem .8rem 1.4rem; background: var(--bg-secondary); border-radius: 12px;
}
.ink-preview::before { content: ""; position: absolute; left: .7rem; top: .8rem; bottom: .8rem; width: 3px; border-radius: 3px; background: var(--ink-text); }
.photo-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-left: .15rem; }
.warn { color: var(--warn-text); font-size: .85rem; margin-left: .15rem; }

/* ---------- Trash (inset grouped rows) ---------- */
.trash-section { margin-bottom: 2rem; }
.trash-section h2 { font: 500 .78rem var(--sans); text-transform: uppercase; letter-spacing: .03em; color: var(--label-2); margin: 0 0 .45rem 1rem; }
.trash-item {
  position: relative; display: flex; gap: 1rem; align-items: center; justify-content: space-between;
  background: var(--bg-elevated); padding: .85rem 1rem;
}
.trash-section h2 + .trash-item { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.trash-item:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.trash-item + .trash-item::before { content: ""; position: absolute; top: 0; left: 1rem; right: 0; border-top: .5px solid var(--separator); }
.trash-item .excerpt { font-family: var(--serif); color: var(--ink-text); margin: .2rem 0; overflow-wrap: anywhere; }
.trash-item .muted { color: var(--label-3); }

/* ---------- Help ---------- */
.help-list { list-style: none; counter-reset: step; padding: 0; margin: 0; }
.help-list li { counter-increment: step; position: relative; padding: .9rem 0 .9rem 3rem; color: var(--label-2); }
.help-list li + li { border-top: .5px solid var(--separator); }
.help-list li b { color: var(--label); }
.help-list li::before {
  content: counter(step); position: absolute; left: 0; top: .8rem;
  width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--tint-soft); color: var(--tint); font-weight: 700; font-size: .9rem;
}

/* ---------- Modals: sheets & alerts ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 1rem; overflow-y: auto;
  animation: fade-in .2s ease-out;
}
.modal-backdrop.centered { align-items: center; }
.modal {
  background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
  width: 100%; max-width: 34rem; padding: 1.6rem; position: relative;
  animation: pop-in .25s cubic-bezier(.2, .9, .3, 1.15);
}
.modal.wide { max-width: 46rem; }
.modal > h2 { padding-right: 2rem; }
.modal .close {
  position: absolute; top: .9rem; right: .9rem; width: 30px; height: 30px; border-radius: 50%;
  border: 0; padding: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--fill); color: var(--label-2);
}
.modal .close:hover { background: var(--fill-strong); }
.modal .buttons { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1.4rem; }

.modal.alert {
  max-width: 290px; padding: 1.25rem 1rem 0; text-align: center; border-radius: 14px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
}
.modal.alert > h2 { font: 600 1.02rem/1.3 var(--sans); padding: 0; margin-bottom: .3rem; letter-spacing: -.01em; }
.modal.alert > p { font-size: .84rem; color: var(--label); margin: 0; }
.modal.alert .buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 1.1rem -1rem 0; border-top: .5px solid var(--separator); }
.modal.alert .buttons .btn {
  background: transparent !important; color: var(--tint); border-radius: 0; min-height: 46px; font-weight: 400; font-size: 1rem; width: auto; filter: none;
}
.modal.alert .buttons .btn:hover { background: var(--fill) !important; }
.modal.alert .buttons .btn + .btn { border-left: .5px solid var(--separator); font-weight: 600; }
.modal.alert .buttons .btn.danger { color: var(--danger); }
.modal.alert .buttons .btn:focus-visible { outline-offset: -3px; border-radius: 0; }

.revision { border-top: .5px solid var(--separator); padding: 1rem 0; }
.revision .text { font-family: var(--serif); color: var(--ink-text); white-space: pre-wrap; max-height: 12rem; overflow: auto; background: var(--bg-secondary); padding: .7rem .9rem; border-radius: 12px; margin: .5rem 0; overflow-wrap: anywhere; }
.compare { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.compare .text { font-family: var(--serif); white-space: pre-wrap; max-height: 16rem; overflow: auto; background: var(--bg-secondary); padding: .7rem .9rem; border-radius: 12px; overflow-wrap: anywhere; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.94); } }
@keyframes sheet-up { from { transform: translateY(100%); } }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; bottom: calc(1.25rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 60;
  display: grid; gap: .5rem; width: min(28rem, calc(100% - 2rem));
}
.toast {
  display: flex; align-items: center; gap: .75rem;
  background: rgba(36, 36, 38, .9); color: #fff; border-radius: 16px; padding: .65rem .6rem .65rem 1.1rem; font-size: .92rem;
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .3s cubic-bezier(.2, .9, .3, 1.2);
}
.toast.error { background: rgba(215, 0, 21, .92); }
.toast .msg { flex: 1; }
.toast button { font: inherit; font-weight: 600; background: none; border: 0; color: #64d2ff; cursor: pointer; padding: .3rem .5rem; min-height: 36px; border-radius: 8px; display: grid; place-items: center; }
.toast.error button { color: #fff; }
.toast button:hover { background: rgba(255, 255, 255, .12); }
@keyframes toast-in { from { transform: translateY(16px) scale(.96); opacity: 0; } }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: var(--bg-elevated); border-radius: 22px; box-shadow: var(--shadow); padding: 2.2rem 2rem 2rem; width: 100%; max-width: 24rem; }
.login-card p { text-align: center; color: var(--label-2); }

/* ---------- Printable book (always looks like paper) ---------- */
.book {
  --label: #1c1c1e; --label-2: rgba(60, 60, 67, .75);
  background: #fff; color: #1c1c1e; padding: 3.5rem 4rem; border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .06), 0 18px 50px rgba(0, 0, 0, .12); font-family: var(--serif);
}
.book .title-page { text-align: center; padding: 2rem 0 3rem; }
.book .title-page h1 { font-family: var(--serif); font-size: 2.6rem; }
.book .title-page .desc { font-style: italic; color: var(--label-2); }
.book .title-page .authors { margin-top: 1.5rem; }
.book .title-page .muted { color: var(--label-2); }
.book h2 { font-family: var(--serif); text-align: center; margin: 2.5rem 0 1.2rem; font-size: 1.6rem; }
.book p { font-size: 1.1rem; line-height: 1.75; text-indent: 1.5em; margin: 0; }
.book p.scene-break { text-indent: 0; margin: 1rem 0; color: #8e8e93; }
.book .chunk { margin-bottom: .6em; }
.book.mono .chunk { color: #1c1c1e !important; }
.book .end { text-align: center; margin-top: 3rem; color: var(--label-2); font-size: .9rem; text-indent: 0; }

/* ---------- Phones: bottom tab bar, sheets ---------- */
@media (max-width: 700px) {
  h1 { font-size: 1.9rem; }
  .topbar { justify-content: space-between; background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
    justify-content: space-around; gap: 0; border-radius: 0;
    padding: 6px max(.5rem, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
    background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-top: .5px solid var(--separator);
  }
  .mainnav a { flex: 1; flex-direction: column; gap: 3px; padding: 3px 0; font-size: .66rem; font-weight: 500; color: #8e8e93; background: none !important; box-shadow: none !important; }
  .mainnav a.active { color: var(--tint); font-weight: 600; }
  .mainnav .icon { width: 25px; height: 25px; }
  main { padding-top: 1.25rem; padding-bottom: calc(6.5rem + env(safe-area-inset-bottom)); }
  #toasts { bottom: calc(5.2rem + env(safe-area-inset-bottom)); }
  .manuscript { padding: 1.4rem 1.1rem .8rem; border-radius: var(--radius); }
  .story-head { gap: 1rem; }
  .story-head h1 { font-size: 1.65rem; }
  .cover.lg { width: 70px; height: 98px; font-size: 2rem; }
  .row-delete span { display: none; }
  .book { padding: 2rem 1.25rem; }
  .compare { grid-template-columns: 1fr; }
  .pending-banner { top: 3.9rem; }

  .modal-backdrop:not(.centered) { align-items: flex-end; padding: 0; }
  .modal-backdrop:not(.centered) .modal {
    max-width: none; border-radius: 16px 16px 0 0; max-height: 94vh; overflow-y: auto;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    animation: sheet-up .32s cubic-bezier(.2, .9, .3, 1);
  }
  .modal-backdrop:not(.centered) .modal::before {
    content: ""; display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--fill-strong); margin: -.75rem auto 1rem;
  }
  .modal-backdrop:not(.centered) .modal .buttons { flex-direction: column-reverse; }
  .modal-backdrop:not(.centered) .modal .buttons .btn { width: 100%; }
}

@media print {
  .no-print, .topbar, .mainnav, #toasts { display: none !important; }
  html, body { background: #fff; }
  main { max-width: none; padding: 0; }
  .book { box-shadow: none; padding: 0; }
  .book h2 { break-before: page; }
  .book h2.first { break-before: auto; }
  .book .title-page { break-after: page; }
  @page { margin: 2cm; }
}

/* Round custom color well, like the preset swatches */
.custom-color input::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.custom-color input::-moz-color-swatch { border: 0; border-radius: 50%; }

@media (max-width: 700px) {
  .story-main { gap: .85rem; padding-left: .85rem; }
  .story-main .title-line { flex-wrap: wrap; gap: .1rem .5rem; }
  .story-main h2 { white-space: normal; }
  .story-row + .story-row::before { left: 78px; }
}
