/* the compose flow (src/compose.js), ported from mockups/compose/c4-flow.html.
   Layers: board (z 1) < ink field (20) < veil (22) < stage + worn scroll (30) < red Inky (60) < 却下 stamp (66) < bubble (70). */
#compose { --red: #d63a28; --red-dk: #a02218; --wash: #4a4652; --paper-hi: #fffaf0; --ink: #1a181c;
  --ui: 'ChiKareGo2', monospace; --small: 'FindersKeepers', 'ChiKareGo2', monospace; --jp: 'DotGothic16', monospace;
  font: 400 16px/1 var(--ui); color: var(--ink); -webkit-font-smoothing: none; }
html.composing, html.composing body { overflow: hidden; overscroll-behavior: none; }
#compose button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#compose .back, #compose .cpost, #compose .sign, #compose #clines, #compose .deny { touch-action: manipulation; }
#compose input, #compose textarea { font: inherit; color: inherit; border: 0; background: transparent; outline: none; padding: 0; margin: 0; border-radius: 0; box-shadow: none; -webkit-appearance: none; appearance: none; }
#compose [hidden] { display: none !important; }
.ink-field { position: fixed; left: 0; top: 0; /* round 14.8: oversize (ink-field.js sets left/top to minus its margin) */ pointer-events: none; image-rendering: pixelated; }
#cveil { position: fixed; inset: 0; z-index: 22; display: none; }
body.composing #cveil { display: block; }
/* FULL BLACKOUT once the flood has filled the screen: a solid wash far past every edge of the screen (above and below the
   visual viewport, behind Safari's translucent toolbars / keyboard bar, the overscroll bounce, the safe areas), and the
   same ink on html + body so nothing of the board can ever show around it. The board itself is locked (compose.js). */
body.composing.washed #cveil { inset: calc(-80vmax - env(safe-area-inset-top, 0px)) calc(-80vmax - env(safe-area-inset-right, 0px)) calc(-80vmax - env(safe-area-inset-bottom, 0px)) calc(-80vmax - env(safe-area-inset-left, 0px)); min-height: 100lvh; background: var(--ink, #1a181c); }       /* round 14.8: past every edge by 80% of the larger screen side: no vh / dvh / innerHeight */
/* round 14.10: the PAGE background (what iOS 26 paints behind the status bar / floating toolbar, beyond what any canvas can reach) goes ink only for the
   edge the black has actually covered (compose.js syncBands: .ink-t / .ink-b from InkField.edgeCover()), never at the tap and never as a flat bar ahead of the
   organic front. 14.8 / 14.9 forced html ink for the whole compose life (html.composing / .draining / .inkbg at the tap): a straight black bar before the flood. */
html.inkbg { --bt: #f4ecda; --bb: #f4ecda; background-color: var(--bt); background-image: linear-gradient(var(--bb), var(--bb)); background-repeat: no-repeat;
  background-size: 100% 100vmax; background-position: 0 calc(var(--sy, 0px) + 50vh); }       /* top colour = the page, bottom colour = a layer from mid-screen down, past the bottom edge */
html.inkbg.ink-t { --bt: #1a181c; }
html.inkbg.ink-b { --bb: #1a181c; }
/* body has NO background of its own while the page background is driven (a position: fixed body with a cream background-colour is what Safari samples for its bars);
   the cream paper is only a background IMAGE (opaque tile, no colour) on a fixed html::before at z -1, offset by --paper-y so the speckle sits where body's did. */
html.inkbg body { background: transparent !important; }
html.inkbg::before { content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; background: url(../assets/paper.png) repeat 0 var(--paper-y, 0px) / 192px; image-rendering: pixelated; }
html.inkbg.washed::before { display: none; }
/* a second solid black past every edge incl. the safe areas, above the board (z 24), below the stage / Inky / iris UI (z 30+). It must be a pseudo of BODY, not of html:
   the locked body is position: fixed = a stacking context at z 0, so a root-level layer above 0 would paint over the whole write page (scroll, Inky, everything). */
html.inkbg.washed body::after { content: ''; position: fixed; z-index: 24; pointer-events: none; background: #1a181c; min-height: 100lvh;
  inset: calc(-100vmax - env(safe-area-inset-top, 0px)) calc(-100vmax - env(safe-area-inset-right, 0px)) calc(-100vmax - env(safe-area-inset-bottom, 0px)) calc(-100vmax - env(safe-area-inset-left, 0px)); }

/* the stage follows the VISUAL viewport, so a real on-screen keyboard never covers the lines or Inky */
#cstage { position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100%); z-index: 30; pointer-events: none; }
body.composing #cstage { pointer-events: auto; }

/* ---------- back (cancel): big ink-blot arrow ON the scroll, lower left, paired with the wax seal ---------- */
/* both corner stamps sit on whole cells of the scroll's 6 px pixel grid (54 = 9 cells in, 78 / 66 = 13 / 11 cells up) */
#compose .back { position: absolute; left: 54px; top: calc(var(--ph) - 78px); display: flex; align-items: center; gap: 10px; }
#compose .back .blot { position: relative; width: 66px; height: 66px; }
#compose .back .blot canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
#compose .back:active .blot { transform: translateY(6px); }   /* pressed: one whole grid cell down (stays on the scroll grid) */
body.kb #compose .back { top: calc(var(--ph) - 60px); left: 54px; }
body.kb #compose .back .blot { width: 54px; height: 54px; }

/* ---------- the worn scroll (pixel canvas) ---------- */
.cscroll { position: absolute; left: 50%; top: var(--st, 34px); transform: translateX(-50%); }
body.kb .cscroll { --st: 30px; }
#scv { position: absolute; left: 0; top: 0; image-rendering: pixelated; }
#compose .pw { position: absolute; left: 0; right: 0; top: 60px; height: 0; overflow: hidden; }
#compose .paper { position: relative; height: var(--ph, 420px); padding: 26px 40px 0 48px; }   /* 48: clear of the torn left edge line beside the writing rows (seed 8370) */
#compose .ln { display: flex; align-items: flex-start; margin-top: 12px; }
#compose .ln:first-child { margin-top: 0; }
#compose .wr { flex: 1; min-width: 0; position: relative; }
/* each writing row, top to bottom: the typed words (sitting on one shared baseline, --fsm = the biggest size), the tan
   ruled line right under them at that baseline (painted into the scroll canvas), then the syllable numerals below the line.
   A row's own size (--fsr) only shrinks when its words would reach the torn edge. */
#compose .field { position: relative; height: calc(4px + var(--fsm, 48px) * var(--asc, .78) + 3px + 12px + 5px + 16px + 3px); }
#compose .field .mirror { position: absolute; left: 0; right: 0; top: calc(4px + (var(--fsm, 48px) - var(--fsr, 48px)) * var(--asc, .78)); font-family: var(--ui); font-size: var(--fsr, 48px); line-height: 1; height: 1.1em; }
#compose .mirror { white-space: pre; pointer-events: none; transform: translateX(var(--sx, 0px)); }
#compose .mirror .ph { color: #b5a07c; }
/* ONE textarea for all three lines (no iOS ^ v field-hopping): transparent, its line boxes laid on the rows by compose.js */
#clines { position: relative; }
#compose #cpoem { position: absolute; z-index: 2; left: 68px; top: 0; width: 200px; height: 243px; margin: 0; padding: 0; border: 0; resize: none; overflow: hidden;
  white-space: pre; overflow-wrap: normal; word-break: normal; font-family: var(--ui); font-size: max(16px, var(--fs, 32px)); line-height: var(--pitch, 81px);
  color: transparent; -webkit-text-fill-color: transparent; caret-color: transparent; background: transparent; outline: none; box-shadow: none; opacity: 1;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: text; user-select: text; scrollbar-width: none; }
#compose #cpoem::-webkit-scrollbar { display: none; }
#compose #cpoem::selection { background: rgba(26, 24, 28, .2); }
#compose #cpoem:disabled { pointer-events: none; }
/* the pixel caret (a native caret would stretch to the whole 81px line box) */
#compose .caret { position: absolute; top: calc(2px + (var(--fsm, 48px) - var(--fsr, 48px)) * var(--asc, .78)); left: 0; width: 3px; height: calc(var(--fsr, 48px) * var(--asc, .78) + 2px); background: var(--ink); pointer-events: none; animation: cblink 1s steps(1) infinite; }
@keyframes cblink { 50% { opacity: 0; } }
/* the 1px focus primer (keyboard auto-open on iOS): in the viewport so iOS does not scroll, invisible */
.kb-primer { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; margin: 0; pointer-events: none; z-index: -1; caret-color: transparent; color: transparent; background: transparent; }
#compose .mirror .w { position: relative; }
/* syllable numerals under the words, counting up across the line: the sign label's pixel font, faux-bold, 16 px (sharp at 2x / 3x);
   ink while within the target, muted red past it, full ink once the line is exactly right */
#compose .field .mirror .nums { position: absolute; left: 0; right: 0; top: calc(var(--fsr, 48px) * var(--asc, .78) + 3px + 12px + 5px);   /* below the ruled line */ display: flex; justify-content: space-around; gap: 2px;
  font: 400 16px/1 var(--ui); color: #5a5048; letter-spacing: 0; text-shadow: 1px 0 0 currentColor; white-space: nowrap; }
#compose .field .mirror .nums b { font: inherit; display: block; min-width: 8px; text-align: center; }
#compose .field .mirror .nums b.x { color: #b8604a; }
#compose .ln[data-state="ok"] .mirror .nums { color: var(--ink); text-shadow: 1px 0 0 currentColor, 0 1px 0 currentColor, 1px 1px 0 currentColor; }
#compose .field .mirror .w.guess .nums { color: #9a8668; }
#compose .field .mirror .w.guess::before { content: '?'; position: absolute; right: -3px; top: -14px; font: 400 16px/1 var(--small); color: var(--paper-hi); background: var(--wash); padding: 0 2px; }
/* the guides themselves are painted into the scroll canvas on its 6 px grid (compose.js placeRules); this only holds their place */
#compose .crule { position: absolute; left: 0; right: 0; top: calc(4px + var(--fsm, 48px) * var(--asc, .78) + 3px); height: 12px; pointer-events: none; }   /* right under the baseline */
#compose .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; margin: 0; }   /* status for screen readers only: nothing on the scroll */
/* sign (optional): max 12 characters; blank = no author */
/* round 14.1: no separate black 'sign' label; the field's own muted tan placeholder reads 'Sign? (optional)'. The only black
   text on the scroll is what the user typed (poem + name) */
/* round 15.10f5: typed name = poem line 3; placeholder pretext smaller so "Sign? (optional)" fits the row. */
#compose .sign { display: none; width: 100%; margin: 12px 0 0; align-items: center; justify-content: center; gap: 8px; flex-wrap: nowrap; }
body.ready #compose .sign { display: flex; }
#compose .sign .nm { position: relative; box-sizing: border-box; width: min(240px, 80%); min-height: calc(max(16px, var(--nfs, var(--fs, 32px))) + 8px); display: flex; justify-content: center; align-items: flex-start; text-align: center; }
#compose .sign .nm .rl { position: absolute; left: 0; right: 0; top: 100%; height: 12px; pointer-events: none; }   /* anchor for the painted underline */
#compose .sign input:disabled { visibility: hidden; }
#compose .sign .nmb { position: absolute; left: -4px; right: -4px; top: -8px; bottom: -6px; z-index: 2; -webkit-tap-highlight-color: transparent; }
#compose .sign .nm.edit .nmb { display: none; }
/* pretext: same ChiKareGo family/weight, scaled back (~half of typed name, floor 16px) so the long hint fits */
#compose .sign .nph { position: absolute; left: 50%; top: 3px; transform: translateX(-50%); width: max-content; max-width: 100%; font: 400 var(--phfs, 28px)/1 var(--ui); color: #9c8662; letter-spacing: normal; pointer-events: none; text-align: center; white-space: nowrap; text-shadow: none; }
#compose .sign .nm.edit .nph, #compose .sign .nm.has .nph { display: none; }
#compose .sign input { position: relative; z-index: 1; width: 100%; font: 400 max(16px, var(--nfs, var(--fs, 32px)))/1 var(--ui); color: var(--ink); padding: 3px 0 5px; text-align: center; text-shadow: none; letter-spacing: normal; }
#compose .sign input::placeholder { color: #9c8662; opacity: 1; font-size: var(--phfs, 28px); font-family: var(--ui); font-weight: 400; letter-spacing: normal; text-shadow: none; }
#compose .sign .nm.has input { color: transparent; text-shadow: none; caret-color: var(--ink); font-size: max(16px, var(--nfs, var(--fs, 32px))); }
/* iOS Safari paints a yellow wash on contact autofill. The name the reader sees is the mirror (.nmm),
   so the field itself stays clear: no yellow plate, no second black copy of the name over the brush. */
#compose .sign input:-webkit-autofill,
#compose .sign input:-webkit-autofill:hover,
#compose .sign input:-webkit-autofill:focus,
#compose .sign input:-webkit-autofill:active,
#compose .sign input:autofill {
  -webkit-text-fill-color: transparent;
  caret-color: var(--ink);
  color: transparent;
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  -webkit-box-shadow: 0 0 0 1000px transparent inset !important;
  box-shadow: 0 0 0 1000px transparent inset !important;
  transition: background-color 99999s ease-out 0s;
  animation: hb-autofill 0.01s;
}
@keyframes hb-autofill { from { opacity: 1; } to { opacity: 1; } }
#compose .sign .nm .nmm { position: absolute; left: 50%; top: 3px; z-index: 1; transform: translateX(-50%); width: max-content; max-width: 100%; font: 400 var(--nfs, var(--fs, 32px))/1 var(--ui); color: var(--ink); white-space: pre; pointer-events: none; text-align: center; text-shadow: none; letter-spacing: normal; }
#compose .sign .nm:not(.has) .nmm { display: none; }
/* touch/kb: typed name kerns like poem mirrors; pretext uses its own smaller size */
body.kb #compose .sign input,
body.kb #compose .sign .nm .nmm { letter-spacing: calc(var(--nfs, var(--fs, 32px)) / -16); }
body.kb #compose .sign .nph,
body.kb #compose .sign input::placeholder { letter-spacing: calc(var(--phfs, 28px) / -16); }
/* the wax seal = post button, lower right of the scroll */
#compose .cpost { position: absolute; right: 54px; top: calc(var(--ph) - 78px); display: flex; align-items: center; gap: 10px; }
#compose .cpost .wax { position: relative; width: 66px; height: 66px; display: grid; place-items: center; }
#compose .cpost .wax canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
#compose .cpost:active .wax { transform: translateY(6px); }
body.ready #compose .cpost .wax { animation: chop 1.1s steps(8) infinite; }
body.ready #compose .cpost.stamped .wax { animation: none; }
@keyframes chop { 0%, 60%, 100% { transform: translateY(0); } 20% { transform: translateY(-12px); } 40% { transform: translateY(0); } }   /* hops by whole 6 px grid cells */
/* keyboard up: compact, so lines, tallies, name and Inky all stay above it */
/* round 14.1: on touch devices this compact layout is used for the WHOLE session (keyboard up or down: one stable layout,
   compose.js kbPlan), with big type (32-40px) and the numerals tucked close under the ruled line */
body.kb #compose .paper { padding-top: 4px; }
body.kb #compose .ln { margin-top: 2px; }
body.kb #compose .field { height: calc(4px + var(--fsm, 48px) * var(--asc, .78) + 3px + 12px + 13px + 2px); }
body.kb #compose .field .mirror .nums { top: calc(var(--fsr, 48px) * var(--asc, .78) + 3px + 12px); line-height: 13px; }   /* just clear of the 12 px painted rule */
body.kb #compose .paper { padding-right: 14px; }   /* round 14.4: the torn right edge clips the width (compose.js fits per row), the rest is for the type */
body.kb #compose .field .mirror { letter-spacing: calc(var(--fsr, 48px) / -16); }          /* one font px tighter (compose.js KERN) */
body.kb #compose #cpoem { letter-spacing: calc(max(16px, var(--fs, 32px)) / -16); }
body.kb #compose .sign { position: absolute; margin: 0; left: 54px; right: 54px; top: calc(var(--ph) - 54px); width: auto; justify-content: center; gap: 6px; }
body.kb #compose .sign .nm { width: min(240px, 100%); }
body.kb #compose .cpost { top: calc(var(--ph) - 60px); right: 54px; }
body.kb #compose .cpost .wax { width: 54px; height: 54px; }

/* ---------- the big tilted hanko: 却下 (rejected) / 不可 (not allowed), alternating; worn ink pressed INTO the paper ---------- */
#compose .deny { position: fixed; z-index: 66; left: 0; top: 0; width: 330px; margin-left: -165px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  pointer-events: none; transform-origin: 50% 40%; mix-blend-mode: multiply; }
#compose .deny img { width: 144px; height: 240px; image-rendering: pixelated; display: block; }

/* ---------- red Inky + his pixel bubble (drawn on a canvas, src/pixel-bubble.js) ---------- */
.inky-canvas.red { position: fixed; left: 0; top: 0; pointer-events: none; image-rendering: pixelated; overflow: visible; }   /* canvas sized past any viewport (inky-red.js resize): never clipped */
/* round 14.1: his tap target (never takes focus: compose.js prevents pointerdown / mousedown) */
#compose .rihit { position: fixed; left: 0; top: 0; z-index: 61; display: none; touch-action: none; -webkit-tap-highlight-color: transparent; cursor: pointer; }
/* 'tap to write': the caret pulses on the line where typing resumes until a tap brings the keyboard */
body.await-tap #compose .caret { animation: cpulse 1.2s steps(6) infinite; }
@keyframes cpulse { 0%, 100% { opacity: 1; transform: scaleY(1); } 50% { opacity: .25; transform: scaleY(.8); } }
.cbubble { position: fixed; z-index: 70; left: 0; top: 0; pointer-events: none; display: grid; place-items: center; transform-origin: 0 0;
  font: 400 16px/1.25 var(--ui); color: var(--ink); white-space: nowrap; }
.cbubble .bcv { position: absolute; z-index: -1; image-rendering: pixelated; pointer-events: none; }
.cbubble .bt { position: relative; display: block; padding: 7px 10px 6px; text-align: left; }
.cbubble.big { font-size: 32px; line-height: 1; }
.cbubble.big .bt { color: var(--paper-hi); }
