/* Hyperfax — the public message box on every logged-out tabbitha.cloud page.
   Served by home at /hyperfax.css; hyperfax.js mounts the card into
   <div id="hyperfax" data-page="/…"> inside a .hf-gate. The gate is the whole
   viewport and never scrolls: the card is the centred hero, the page's own
   token strip sits at the bottom (Duck, 2026-09-22). Colours come from the
   host page's variables with the front page's palette as fallback. */

html.hf-locked, html.hf-locked body { overflow: hidden !important; height: 100%; }

.hf-gate {
  --hf-bg: var(--bg, #f5f0e8);
  --hf-paper: var(--paper, #ede5d3);
  --hf-ink: var(--ink, #1a1a18);
  --hf-mid: var(--ink-mid, var(--mid, #4a4a46));
  --hf-light: var(--ink-light, #8a8580);
  --hf-rule: var(--rule, #d4ccba);
  --hf-accent: var(--accent, #b8472f);
  --hf-accent-soft: var(--accent-soft, #e8d4cc);
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--hf-bg); color: var(--hf-ink);
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 14px; line-height: 1.4;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) 0 env(safe-area-inset-left, 0);
}
.hf-gate * { box-sizing: border-box; }
#hyperfax { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 12px; }

/* ── the token strip at the bottom ─────────────────────────────── */
.hf-token {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 8px;
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom, 0)); border-top: 1px solid var(--hf-rule);
  background: var(--hf-bg); font-size: 11.5px; color: var(--hf-mid);
}
.hf-token label { text-transform: uppercase; letter-spacing: .08em; font-size: 10px; }
.hf-token input { flex: 1 1 120px; max-width: 260px; min-width: 0; font: inherit; padding: 5px 8px; background: var(--hf-paper); color: var(--hf-ink); border: 1px solid var(--hf-rule); border-radius: 4px; }
.hf-token button { font: inherit; padding: 5px 10px; background: var(--hf-ink); color: var(--hf-bg); border: none; border-radius: 4px; cursor: pointer; letter-spacing: .04em; }
.hf-token .err { flex-basis: 100%; text-align: center; color: var(--hf-accent); font-size: 11px; }
.hf-token .err:empty { display: none; }

/* ── the stage: the form, the confirm, the scene share one box ──── */
.hf { position: relative; width: min(100%, 560px); height: 100%; max-height: 640px; }
.hf > * { position: absolute; inset: 0; }
.hf-card { display: flex; flex-direction: column; justify-content: center; gap: clamp(6px, 1.4vh, 12px); padding: 0 2px; margin: 0; }
.hf-title { margin: 0; font-size: clamp(1.15rem, 4.2vw, 1.7rem); line-height: 1.1; letter-spacing: .02em; font-weight: 700; }
.hf-title small { display: block; font-size: clamp(.72rem, 2.6vw, .95rem); font-weight: 400; color: var(--hf-mid); margin-top: 3px; letter-spacing: 0; }
.hf-title .glyph { margin-right: .35em; }
.hf-card textarea {
  width: 100%; height: clamp(74px, 22dvh, 190px); resize: none; font: inherit; line-height: 1.4;
  padding: 9px 11px; background: var(--hf-paper); color: var(--hf-ink); border: 1px solid var(--hf-rule); border-radius: 6px;
}
.hf-card textarea:focus, .hf-card input:focus { outline: 2px solid var(--hf-accent-soft); outline-offset: 1px; border-color: var(--hf-accent); }
.hf-row { display: flex; gap: 8px; align-items: stretch; }
.hf-row input { flex: 1 1 auto; min-width: 0; font: inherit; padding: 8px 11px; background: var(--hf-paper); color: var(--hf-ink); border: 1px solid var(--hf-rule); border-radius: 6px; }
.hf-send { flex: none; font: inherit; font-weight: 700; letter-spacing: .06em; padding: 8px 18px; background: var(--hf-accent); color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.hf-send:disabled { opacity: .5; cursor: default; }
.hf-hp { position: absolute !important; left: -9999px !important; width: 1px !important; height: 1px !important; opacity: 0; pointer-events: none; }
.hf-note { font-size: clamp(.66rem, 2.3vw, .78rem); color: var(--hf-light); display: flex; justify-content: space-between; gap: 8px; }
.hf-note .count { font-variant-numeric: tabular-nums; }
.hf-note.warn { color: var(--hf-accent); }

/* ── confirm (in-page, never alert/confirm) ─────────────────────── */
.hf-confirm { display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--hf-bg) 88%, transparent); }
.hf-confirm .box { width: min(100%, 420px); background: var(--hf-paper); border: 1px solid var(--hf-rule); border-radius: 8px; padding: 16px 18px; box-shadow: 0 10px 30px rgba(0,0,0,.12); }
.hf-confirm p { margin: 0 0 12px; font-size: clamp(.8rem, 3vw, .95rem); overflow-wrap: anywhere; }
.hf-confirm q { font-style: italic; }
.hf-confirm .btns { display: flex; gap: 8px; justify-content: flex-end; }
.hf-confirm button { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--hf-rule); background: var(--hf-bg); color: var(--hf-ink); cursor: pointer; }
.hf-confirm button.go { background: var(--hf-accent); color: #fff; border-color: var(--hf-accent); font-weight: 700; }

/* ── the sending scene ──────────────────────────────────────────── */
.hf-scene { overflow: hidden; perspective: 900px; }
.hf-scene [data-part] { position: absolute; }
.hf-status { position: absolute; left: 0; right: 0; bottom: 2px; text-align: center; font-size: clamp(.68rem, 2.4vw, .8rem); color: var(--hf-mid); letter-spacing: .04em; }

/* the letter */
.hf-letter {
  left: 50%; top: 22%; width: min(66%, 300px); height: 34%; transform: translateX(-50%);
  background: #fbf7ee; color: var(--hf-ink); border: 1px solid var(--hf-rule); border-radius: 3px; box-shadow: 0 6px 18px rgba(0,0,0,.12);
  padding: 8px 10px; font-size: clamp(.55rem, 2vw, .7rem); line-height: 1.35; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere;
  transform-origin: 50% 50%; backface-visibility: visible;
}
.hf-letter::after { content: ''; position: absolute; inset: 0; background: linear-gradient(transparent 60%, #fbf7ee); }
[data-stage="fold"] .hf-letter { animation: hfFold .85s cubic-bezier(.6,0,.3,1) forwards; }
@keyframes hfFold {
  0% { transform: translateX(-50%) rotateX(0); }
  55% { transform: translateX(-50%) rotateX(-120deg); }
  100% { transform: translateX(-50%) rotateX(-180deg) scaleY(.55); filter: brightness(.95); }
}
[data-stage="envelope"] .hf-letter { animation: hfSlideIn .8s ease-in forwards; }
@keyframes hfSlideIn {
  0% { transform: translateX(-50%) rotateX(-180deg) scaleY(.55); opacity: 1; }
  100% { transform: translateX(-50%) translateY(90%) rotateX(-180deg) scaleY(.3); opacity: 0; }
}
.hf-scene.past-envelope .hf-letter { display: none; }

/* the envelope */
.hf-env { left: 50%; top: 52%; width: min(58%, 260px); height: 22%; transform: translateX(-50%) translateY(60px); opacity: 0; transition: transform .5s ease, opacity .4s ease; }
.hf-env .body { position: absolute; inset: 0; background: #e6d8b8; border: 1px solid #c9b78f; border-radius: 4px; overflow: hidden; }
.hf-env .body::before, .hf-env .body::after { content: ''; position: absolute; top: 0; width: 50%; height: 100%; }
.hf-env .body::before { left: 0; background: linear-gradient(to bottom right, transparent 49.5%, #d8c9a4 50%); }
.hf-env .body::after { right: 0; background: linear-gradient(to bottom left, transparent 49.5%, #d8c9a4 50%); }
.hf-env .flap { position: absolute; left: 0; right: 0; top: 0; height: 52%; background: #d4c39a; border: 1px solid #c9b78f; clip-path: polygon(0 0, 100% 0, 50% 100%); transform-origin: top center; transform: rotateX(180deg); transition: transform .6s ease .1s; z-index: 2; }
.hf-env .addr { position: absolute; left: 10%; bottom: 12%; font-size: clamp(.5rem, 1.8vw, .65rem); color: #5b4d32; letter-spacing: .04em; line-height: 1.3; }
[data-stage="envelope"] .hf-env, [data-stage="seal"] .hf-env, [data-stage="tube"] .hf-env { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-stage="seal"] .hf-env .flap, [data-stage="tube"] .hf-env .flap { transform: rotateX(0); }
[data-stage="tube"] .hf-env { animation: hfTube .9s cubic-bezier(.7,-.2,.4,1) .2s forwards; }
@keyframes hfTube {
  0% { transform: translateX(-50%) translateY(0) scale(1); }
  35% { transform: translateX(-50%) translateY(6%) scale(.55, .8); border-radius: 40px; }
  100% { transform: translateX(-50%) translateY(-220%) scale(.4, .7); opacity: 0; }
}
.hf-scene.past-tube .hf-env, .hf-scene.past-tube .hf-wax, .hf-scene.past-tube .hf-stamp, .hf-scene.past-tube .hf-tube { display: none; }

/* wax seal + stamp */
.hf-wax { left: 50%; top: 58%; width: clamp(28px, 8vw, 44px); height: clamp(28px, 8vw, 44px); margin-left: calc(clamp(28px, 8vw, 44px) / -2); border-radius: 50%; background: radial-gradient(circle at 35% 35%, #d9634a, #8f2e1e 70%); box-shadow: 0 2px 4px rgba(0,0,0,.35), inset 0 0 0 3px rgba(255,255,255,.12); color: #f7d9cf; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: clamp(.8rem, 3vw, 1.1rem); z-index: 3; opacity: 0; transform: scale(3); }
[data-stage="seal"] .hf-wax { animation: hfWax .55s cubic-bezier(.3,1.6,.5,1) forwards; }
@keyframes hfWax { 0% { opacity: 0; transform: scale(3); } 60% { opacity: 1; transform: scale(.85); } 100% { opacity: 1; transform: scale(1); } }
.hf-stamp { left: calc(50% + min(29%, 130px) - clamp(30px, 9vw, 46px)); top: 54%; width: clamp(30px, 9vw, 46px); height: clamp(36px, 10vw, 52px); border: 2px dashed #b8472f; background: #f6e9dc; color: #b8472f; font-size: clamp(.8rem, 3vw, 1.2rem); display: flex; align-items: center; justify-content: center; z-index: 3; opacity: 0; transform: rotate(-30deg) scale(2); }
[data-stage="seal"] .hf-stamp { animation: hfSlap .4s ease-out .35s forwards; }
@keyframes hfSlap { 0% { opacity: 0; transform: rotate(-30deg) scale(2); } 100% { opacity: 1; transform: rotate(-8deg) scale(1); } }
[data-stage="tube"] .hf-wax, [data-stage="tube"] .hf-stamp { animation: hfRide .9s cubic-bezier(.7,-.2,.4,1) .2s forwards; opacity: 1; }
@keyframes hfRide { 0% { opacity: 1; } 100% { transform: translateY(-900%) scale(.3); opacity: 0; } }

/* the pneumatic tube */
.hf-tube { left: 50%; top: -5%; width: min(22%, 90px); height: 70%; margin-left: calc(min(22%, 90px) / -2); border-left: 2px solid rgba(90,80,60,.25); border-right: 2px solid rgba(90,80,60,.25); background: linear-gradient(to right, rgba(255,255,255,.35), transparent 30%, transparent 70%, rgba(0,0,0,.05)); border-radius: 0 0 40px 40px; opacity: 0; transition: opacity .3s; }
[data-stage="tube"] .hf-tube { opacity: 1; }

/* the centrepiece: the letter fills the screen, then shrinks into the printer scene */
.hf-sheet { position: fixed; inset: 0; z-index: 120; background: #fbf7ee; color: var(--hf-ink); display: flex; align-items: center; justify-content: center; transform: scale(0); opacity: 0; pointer-events: none; padding: 6vmin; }
.hf-sheet pre { margin: 0; font: inherit; font-size: clamp(.8rem, 2.4vw, 1.2rem); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 60ch; max-height: 100%; overflow: hidden; }
.hf-sheet.expand { animation: hfExpand .7s cubic-bezier(.5,0,.2,1) forwards; }
@keyframes hfExpand { 0% { transform: scale(.05); opacity: 0; border-radius: 40%; } 30% { opacity: 1; } 100% { transform: scale(1); opacity: 1; border-radius: 0; } }
.hf-sheet.shrink { animation: hfShrink .7s cubic-bezier(.5,0,.2,1) forwards; }
@keyframes hfShrink { 0% { transform: scale(1); opacity: 1; } 100% { transform: translate(var(--hf-dx, 0px), var(--hf-dy, 0px)) scale(.08); opacity: 1; } }
.hf-sheet.gone { display: none; }

/* the printer scene */
.hf-pscene { position: absolute; inset: 0; opacity: 0; transition: opacity .4s ease; }
[data-stage="shrink"] .hf-pscene, [data-stage="feed"] .hf-pscene, [data-stage="print"] .hf-pscene, [data-stage="done"] .hf-pscene, [data-stage="jam"] .hf-pscene { opacity: 1; }
.hf-printer { position: absolute; left: 50%; bottom: 9%; width: min(72%, 330px); height: 21%; transform: translateX(-50%); background: linear-gradient(#e9e6e0, #cfcac0); border: 1px solid #a8a296; border-radius: 10px 10px 6px 6px; box-shadow: 0 10px 20px rgba(0,0,0,.15), inset 0 2px 0 rgba(255,255,255,.6); }
.hf-printer .slot { position: absolute; left: 12%; right: 12%; top: -4px; height: 8px; background: #2a2a28; border-radius: 4px; box-shadow: inset 0 2px 3px rgba(0,0,0,.8); }
.hf-printer .feedslot { position: absolute; right: 8%; top: 28%; width: 14%; height: 7px; background: #3a3a36; border-radius: 3px; }
.hf-printer .lcd { position: absolute; left: 8%; bottom: 18%; width: 46%; height: 42%; background: #1b2a1f; color: #9fe6a8; border-radius: 4px; font-size: clamp(.5rem, 1.8vw, .66rem); line-height: 1.25; padding: 4px 6px; overflow: hidden; letter-spacing: .04em; box-shadow: inset 0 0 6px rgba(0,0,0,.8); white-space: nowrap; }
.hf-printer .lcd .bars { display: flex; gap: 2px; height: 30%; margin-top: 2px; align-items: flex-end; }
.hf-printer .lcd .bars i { flex: 1; background: #9fe6a8; height: 30%; opacity: .5; }
[data-stage="feed"] .lcd .bars i { animation: hfScreech .12s linear infinite alternate; }
[data-stage="feed"] .lcd .bars i:nth-child(2n) { animation-duration: .09s; }
[data-stage="feed"] .lcd .bars i:nth-child(3n) { animation-duration: .15s; }
@keyframes hfScreech { 0% { height: 10%; opacity: .4; } 100% { height: 100%; opacity: 1; } }
.hf-printer .light { position: absolute; right: 10%; bottom: 22%; width: 8px; height: 8px; border-radius: 50%; background: #6a6; box-shadow: 0 0 6px #6c6; }
[data-stage="print"] .hf-printer .light { animation: hfBlink .35s steps(2) infinite; }
/* the print state after the send (data-print from /hyperfax/status): amber while the paper is pending, green once it printed, steady amber held, red blinking offline */
[data-stage="done"][data-print="pending"] .hf-printer .light { background: #dcb040; box-shadow: 0 0 6px #ecc25a; animation: hfBlink 1.4s steps(2) infinite; }
[data-stage="done"][data-print="held"] .hf-printer .light { background: #dcb040; box-shadow: 0 0 6px #ecc25a; }
[data-stage="done"][data-print="failed"] .hf-printer .light { background: #d5544a; box-shadow: 0 0 6px #e8675c; animation: hfBlink .7s steps(2) infinite; }
[data-stage="done"][data-print="printed"] .hf-printer .light { background: #5c5; box-shadow: 0 0 8px #7e7; }
@keyframes hfBlink { to { background: #d84; box-shadow: 0 0 6px #fa5; } }
.hf-printer .brand { position: absolute; right: 8%; bottom: 40%; font-size: clamp(.5rem, 1.6vw, .6rem); color: #6b6459; letter-spacing: .1em; }
/* the small letter that feeds in from the top */
.hf-mini { left: 50%; top: 4%; width: clamp(34px, 10vw, 54px); height: clamp(24px, 7vw, 38px); margin-left: calc(clamp(34px, 10vw, 54px) / -2); background: #fbf7ee; border: 1px solid var(--hf-rule); border-radius: 2px; box-shadow: 0 3px 8px rgba(0,0,0,.15); opacity: 0; z-index: 2; }
[data-stage="feed"] .hf-mini { animation: hfFeed .9s ease-in forwards; }
@keyframes hfFeed { 0% { opacity: 1; transform: translateY(0) rotate(0); } 70% { opacity: 1; transform: translateY(calc(var(--hf-feed, 300px) - 20px)) rotate(4deg) scaleY(.9); } 100% { opacity: 0; transform: translateY(var(--hf-feed, 300px)) scaleY(.2); } }
/* the receipt coming out */
.hf-paper { position: absolute; left: 50%; bottom: calc(9% + 21% - 2px); width: min(64%, 290px); transform: translateX(-50%); max-height: calc(100% - 9% - 21% - 14px); overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; container-type: inline-size; background: #fffdf8; box-shadow: 0 -2px 10px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.05); height: 0; transition: height .12s linear; z-index: 1; }
.hf-paper pre { margin: 0; padding: 6px 4cqw 4px; font-family: Consolas, ui-monospace, Menlo, monospace; font-size: calc(92cqw / 25.2); line-height: 1.25; white-space: pre-wrap; overflow-wrap: anywhere; color: #222; }
.hf-paper pre .h1 { font-weight: 700; font-size: 1.8em; line-height: 1.1; }
.hf-paper pre .h2 { font-weight: 700; }
.hf-paper pre b { font-weight: 700; }
.hf-paper pre .dim { color: #777; }
.hf-paper .tear { height: 7px; background: linear-gradient(135deg, transparent 50%, #fffdf8 50%) 0 0 / 7px 7px, linear-gradient(45deg, transparent 50%, #fffdf8 50%) 0 0 / 7px 7px; background-color: var(--hf-bg); margin-top: -1px; flex: none; opacity: 0; }
[data-stage="done"] .hf-paper .tear { opacity: 1; }
.hf-done { position: absolute; left: 0; right: 0; bottom: 0; height: 9%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 10px; padding: 0 10px; font-size: clamp(.62rem, 2.2vw, .8rem); line-height: 1.2; text-align: center; color: var(--hf-mid); opacity: 0; transition: opacity .4s; }
.hf-done span { max-width: 100%; }
[data-stage="done"] .hf-done { opacity: 1; }
.hf-done button, .hf-jam button { font: inherit; padding: 4px 10px; border-radius: 5px; border: 1px solid var(--hf-rule); background: var(--hf-paper); color: var(--hf-ink); cursor: pointer; }
.hf-done code { color: var(--hf-ink); }
.hf-jam { display: none; position: absolute; inset: 14% 6%; align-items: center; justify-content: center; text-align: center; }
[data-stage="jam"] .hf-jam { display: flex; }
.hf-jam .box { background: var(--hf-paper); border: 1px solid var(--hf-accent); border-radius: 8px; padding: 14px 16px; max-width: 380px; }
.hf-jam h3 { margin: 0 0 6px; font-size: clamp(.9rem, 3.4vw, 1.1rem); color: var(--hf-accent); }
.hf-jam p { margin: 0 0 10px; font-size: clamp(.75rem, 2.8vw, .9rem); }
[data-stage="jam"] .hf-printer, [data-stage="jam"] .hf-paper, [data-stage="jam"] .hf-mini, [data-stage="jam"] .hf-letter, [data-stage="jam"] .hf-env, [data-stage="jam"] .hf-wax, [data-stage="jam"] .hf-stamp, [data-stage="jam"] .hf-tube { display: none; }

@media (prefers-reduced-motion: reduce) {
  .hf-scene *, .hf-sheet { animation-duration: .01s !important; transition-duration: .01s !important; }
}
