/* Ink Relay — calm paper & ink */
:root {
  --paper: #f6f1e8;
  --paper-2: #efe8db;
  --card: #fffcf6;
  --ink: #26211c;
  --ink-2: #4a423a;
  --muted: #857a6c;
  --line: #e2d8c6;
  --accent: #9a3b2a;
  --accent-ink: #fffcf6;
  --ok: #3f6b3a;
  --warn: #9b6a12;
  --char: #2f6f6a;  --char-bg: #2f6f6a1c;
  --obj:  #94620f;  --obj-bg:  #b07a1622;
  --loc:  #6b4a8a;  --loc-bg:  #6b4a8a1e;
  --shadow: 0 1px 2px #26211c0d, 0 8px 28px #26211c0f;
  --radius: 14px;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1715; --paper-2: #221e1b; --card: #24201c; --ink: #ede5d8; --ink-2: #cfc5b6; --muted: #9a8f81;
    --line: #3a332c; --accent: #e08a6e; --accent-ink: #1a1715; --ok: #8fbf86; --warn: #e0b45c;
    --char: #7cc4bc; --char-bg: #7cc4bc1f; --obj: #e0b45c; --obj-bg: #e0b45c1c; --loc: #b99ad8; --loc-bg: #b99ad81f;
    --shadow: 0 1px 2px #0006, 0 10px 30px #0005;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.55 var(--sans); min-height: 100vh;
  background-image: radial-gradient(#26211c08 1px, transparent 1px); background-size: 22px 22px;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1120px; margin: 0 auto; padding: 18px 20px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--serif); font-size: 22px; letter-spacing: -.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--ink); position: relative; }
.brand-mark::after { content: ''; position: absolute; inset: 7px 6px 6px 9px; border-left: 2.5px solid var(--paper);
  transform: skewX(-22deg); border-radius: 2px; }
.topnav { display: flex; align-items: center; gap: 10px; }
.lang-toggle { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px;
  font-size: 13px; color: var(--muted); cursor: pointer; letter-spacing: .04em; }
.lang-toggle b { color: var(--ink); font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.user-chip button { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 0; }

main { max-width: 1120px; margin: 0 auto; padding: 8px 20px 80px; outline: none; }
main:focus, main:focus-visible { outline: none; }

/* Type */
h1, h2, h3 { font-family: var(--serif); font-weight: 400; letter-spacing: -.015em; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(34px, 5vw, 54px); }
h2 { font-size: 28px; }
h3 { font-size: 20px; }
.eyebrow { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; font-weight: 500; }
.lede { font-family: var(--serif); font-size: 21px; color: var(--ink-2); max-width: 34ch; margin: 0 0 28px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: 28px; align-items: start; }
.story-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 36px; align-items: start; }
.sticky { position: sticky; top: 16px; }
@media (max-width: 900px) {
  .grid-2, .story-layout { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.spacer { flex: 1; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

/* Forms */
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
input[type=text], input[type=email], input[type=number], select, textarea {
  width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px;
  transition: border-color .15s, background .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink-2); background: var(--card); }
textarea { resize: vertical; min-height: 180px; font-family: var(--serif); font-size: 19px; line-height: 1.6; }
.code-input { font-family: ui-monospace, 'SF Mono', Menlo, monospace !important; letter-spacing: .18em; text-transform: uppercase; font-size: 18px !important; text-align: center; }
.field + .field { margin-top: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--paper); }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px #0001; font-weight: 500; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--ink); background: var(--ink); color: var(--paper);
  padding: 11px 20px; border-radius: 10px; cursor: pointer; font-weight: 500; text-decoration: none; transition: transform .08s, opacity .15s; white-space: nowrap; }
.btn:hover { opacity: .9; } .btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-2); opacity: 1; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.btn.sm { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn.lg { padding: 14px 26px; font-size: 17px; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; }

/* Home */
.hero { padding: 40px 0 36px; }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 36px; }
.how div { border-top: 1px solid var(--line); padding-top: 14px; }
.how b { font-family: var(--serif); font-weight: 400; font-size: 26px; color: var(--accent); display: block; }
@media (max-width: 700px) { .how { grid-template-columns: 1fr; } }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.title { font-family: var(--serif); font-size: 19px; text-decoration: none; }
.list a.title:hover { text-decoration: underline; text-underline-offset: 3px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.hot { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.empty { text-align: center; padding: 28px 10px; color: var(--muted); font-family: var(--serif); font-size: 18px; }

/* Story text */
.story-head { margin: 18px 0 26px; }
.story { font-family: var(--serif); font-size: 20px; line-height: 1.7; color: var(--ink); max-width: 66ch; }
.segment { position: relative; margin: 0 0 1.1em; }
.segment p { margin: 0; white-space: pre-wrap; }
.segment .by { position: absolute; left: -150px; width: 130px; top: 6px; text-align: right; font: 12px/1.35 var(--sans); color: var(--muted); }
.segment .by .ic { display: block; font-size: 14px; }
@media (max-width: 1240px) { .segment .by { position: static; display: block; text-align: left; width: auto; margin-bottom: 2px; } .segment .by .ic { display: inline; } }
.segment.opening p::first-letter { font-size: 3.1em; float: left; line-height: .9; margin: 6px 8px 0 0; color: var(--accent); }
.segment .twist-note { font: 13px var(--sans); color: var(--muted); margin-top: 4px; }
.segment figure { margin: 6px 0 0; }
.segment figure img { width: 100%; max-width: 640px; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: block; }
.segment figcaption { font-style: italic; color: var(--ink-2); margin-top: 6px; font-size: 18px; }
.segment .del { position: absolute; right: -36px; top: 4px; opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.segment:hover .del { opacity: 1; }
.fin { text-align: center; color: var(--muted); letter-spacing: .5em; margin: 30px 0; }

mark.tag { background: transparent; color: inherit; border-radius: 3px; padding: 0 1px; box-shadow: inset 0 -0.42em 0 var(--hl); cursor: help; }
mark.t-character { --hl: var(--char-bg); }
mark.t-object { --hl: var(--obj-bg); }
mark.t-location { --hl: var(--loc-bg); }

/* Story bible */
.bible h3 { margin-bottom: 12px; }
.bible-group + .bible-group { margin-top: 18px; }
.bible-group h4 { font: 600 12px var(--sans); letter-spacing: .12em; text-transform: uppercase; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.bible-group h4::before { content: ''; width: 9px; height: 9px; border-radius: 3px; background: var(--c); }
.bible-group.character { --c: var(--char); } .bible-group.object { --c: var(--obj); } .bible-group.location { --c: var(--loc); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; padding: 4px 10px; border-radius: 8px; background: color-mix(in srgb, var(--c) 12%, transparent); color: var(--ink); }
.chip button { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; line-height: 1; }
.chip.empty-chip { background: transparent; border: 1px dashed var(--line); color: var(--muted); }

.tag-pop { position: absolute; z-index: 50; background: var(--ink); color: var(--paper); border-radius: 10px; padding: 5px; display: flex; gap: 3px; box-shadow: var(--shadow); }
.tag-pop[hidden] { display: none; }
.tag-pop button { border: 0; background: transparent; color: var(--paper); padding: 6px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tag-pop button:hover { background: #ffffff1f; }
.tag-pop i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }

/* Link card */
.passcard { text-align: center; }
.big-code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: clamp(30px, 6vw, 44px); letter-spacing: .12em; margin: 10px 0 6px; user-select: all; }
.linkbox { display: flex; gap: 8px; margin-top: 14px; }
.linkbox input { font-size: 14px; color: var(--ink-2); }
.state-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.state-dot.open { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 18%, transparent); }
.state-dot.claimed { background: var(--warn); }

/* Turn */
.turn-card { border-radius: var(--radius); padding: 22px 24px; background: var(--ink); color: var(--paper); position: relative; overflow: hidden; }
.turn-card .eyebrow { color: color-mix(in srgb, var(--paper) 60%, transparent); }
.turn-card h2 { margin: 0 0 6px; }
.turn-card p { margin: 0; color: color-mix(in srgb, var(--paper) 80%, transparent); }
.turn-card .big-emoji { font-size: 46px; letter-spacing: .15em; margin-top: 10px; }
.turn-card .twist { font-family: var(--serif); font-size: 26px; font-style: italic; margin-top: 10px; color: var(--paper); }
.turn-icon { position: absolute; right: 18px; top: 10px; font-size: 64px; opacity: .14; }
.timer { font-variant-numeric: tabular-nums; font-weight: 500; }
.timer.low { color: var(--accent); }

.blind-wall { position: relative; font-family: var(--serif); font-size: 20px; line-height: 1.7; }
.blind-wall .fog { filter: blur(6px); user-select: none; color: var(--muted); }
.blind-wall .last { padding: 14px 18px; border-left: 3px solid var(--accent); background: var(--card); border-radius: 0 10px 10px 0; margin-top: 10px; }

.choices { display: grid; gap: 10px; }
.choice { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 16px 18px; cursor: pointer;
  font-family: var(--serif); font-size: 18px; line-height: 1.5; transition: border-color .15s, box-shadow .15s; }
.choice:hover { border-color: var(--ink-2); }
.choice.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.choice small { display: block; font: 600 12px var(--sans); letter-spacing: .12em; color: var(--muted); margin-bottom: 4px; }

.counter { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.bad { color: var(--accent); } .counter.good { color: var(--ok); }

/* Grammar */
.issues { margin-top: 12px; display: grid; gap: 8px; }
.issue { border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: 0 10px 10px 0; padding: 10px 14px; background: var(--card); font-size: 14px; }
.issue .ctx { font-family: var(--serif); font-size: 16px; margin-bottom: 4px; }
.issue .ctx u { text-decoration: wavy underline var(--accent); text-underline-offset: 4px; }
.issue .fix { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.issue .fix button { border: 1px solid var(--line); background: var(--paper); border-radius: 7px; padding: 3px 10px; cursor: pointer; font-size: 14px; }
.issue .fix button:hover { border-color: var(--ok); color: var(--ok); }
.all-good { color: var(--ok); font-size: 14px; margin-top: 10px; }

/* Drawing */
.draw-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.draw-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.size { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; display: grid; place-items: center; padding: 0; }
.size.on { border-color: var(--ink); }
.size i { background: var(--ink); border-radius: 50%; display: block; }
canvas.board { width: 100%; aspect-ratio: 8 / 5; background: #fff; border-radius: 10px; border: 1px solid var(--line); touch-action: none; cursor: crosshair; display: block; }

/* Banners */
.banner { border-radius: 12px; padding: 14px 18px; border: 1px solid var(--line); background: var(--card); display: flex; gap: 12px; align-items: flex-start; }
.banner .ic { font-size: 20px; line-height: 1.3; }
.banner b { display: block; font-weight: 600; }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.dev-link { word-break: break-all; font-size: 13px; background: var(--paper-2); padding: 10px; border-radius: 8px; margin-top: 10px; }

/* Settings */
details.adv { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 18px; }
details.adv summary { cursor: pointer; color: var(--ink-2); font-weight: 500; list-style: none; }
details.adv summary::before { content: '+ '; color: var(--muted); }
details.adv[open] summary::before { content: '− '; }
.weights { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.weight { display: grid; grid-template-columns: 150px 1fr 38px; gap: 10px; align-items: center; font-size: 14px; }
.weight input[type=range] { width: 100%; accent-color: var(--ink); }
.weight output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.three { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 14px; margin-top: 10px; }
.check input { margin-top: 3px; accent-color: var(--ink); }
aside .passcard .big-code { font-size: 28px; letter-spacing: .08em; white-space: nowrap; }
aside .passcard .linkbox { flex-direction: column; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--paper);
  padding: 11px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { padding: 80px 0; text-align: center; color: var(--muted); font-family: var(--serif); font-size: 20px; }
.fade-in { animation: fade .35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Export & share */
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.exp { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; text-decoration: none; background: var(--paper); transition: border-color .15s; }
.exp:hover { border-color: var(--ink-2); }
.exp b { display: block; font-weight: 600; font-size: 15px; }
.exp span { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.wp-row { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; position: relative; }
.wp-row > b { display: block; font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.wp-help { position: absolute; top: 9px; right: 11px; }
.wp-help summary { list-style: none; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.wp-help[open] { position: static; }
.wp-help[open] summary { position: absolute; top: 9px; right: 11px; }
.share-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.share { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; text-decoration: none; cursor: pointer; color: var(--ink-2); }
.share:hover { border-color: var(--ink-2); color: var(--ink); }

/* Print view (screen) */
body.print-mode .topbar { display: none; }
body.print-mode { background: var(--paper-2); }
.print-bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  max-width: 820px; margin: 16px auto; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.print-page { max-width: 820px; margin: 0 auto 60px; background: #fffdf9; color: #26211c; padding: 72px 80px; border-radius: 4px; box-shadow: var(--shadow); }
.print-page .story { max-width: none; font-size: 18px; color: #26211c; }
.print-page .segment .by, .print-page .segment .del { display: none; }
.print-page .segment.opening p::first-letter { color: #9a3b2a; }
.print-page mark.tag { box-shadow: none; }
.print-title { text-align: center; margin-bottom: 48px; }
.print-title h1 { font-size: 44px; margin: 6px 0 12px; }
.print-authors { font-family: var(--serif); font-style: italic; color: #6d6358; margin: 0; }
.print-bible { margin-top: 44px; padding-top: 20px; border-top: 1px solid #e2d8c6; font-size: 15px; }
.print-bible h2 { font-size: 20px; }
.print-bible p { margin: 4px 0; }
.print-foot { margin-top: 36px; font-size: 12px; color: #8a7f74; text-align: center; }
@media (max-width: 700px) { .print-page { padding: 36px 24px; } }

@media print {
  @page { size: A4; margin: 22mm 20mm 20mm; @bottom-center { content: counter(page); font: 9pt Georgia, serif; color: #8a7f74; } }
  html, body, body.print-mode { background: #fff !important; background-image: none !important; }
  .topbar, .print-bar, #toast, .tag-pop { display: none !important; }
  main { padding: 0; max-width: none; }
  .print-page { box-shadow: none; padding: 0; max-width: none; margin: 0; background: #fff; }
  .print-page .story { font-size: 11.5pt; line-height: 1.6; }
  .print-title { margin-bottom: 14mm; }
  .print-title h1 { font-size: 28pt; }
  .segment { break-inside: avoid-page; }
  .segment figure { break-inside: avoid; }
  .segment figure img { max-height: 110mm; width: auto; max-width: 100%; border: 0.3pt solid #ccc; }
  .print-bible { break-inside: avoid; }
  a { text-decoration: none; }
}
