/*
 * Enclaven ceremony pages (register.html / assert.html) — presentation
 * only. This file styles the small popup window (480x640, opened via
 * `window.open('popup,width=480,height=640')` from the extension) that a
 * WebAuthn ceremony runs behind. Nothing here changes what `ui.ts` puts in
 * `#status`/`#fingerprint`, or when — it only dresses the fixed DOM contract
 * those functions already render into (`#app[data-state]`, `#status`,
 * `#fingerprint`, `.fp-group`).
 *
 * Every colour comes from `@enclaven/ui/tokens.css`, loaded before this
 * file. Never redefine a colour here — if a hue is missing, that is a gap in
 * the token set, not something to patch locally.
 */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.25rem 1rem;
}

a {
  color: var(--plate);
}

:focus-visible {
  outline: 2px solid var(--plate);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
   CARD — the whole visible surface of the ceremony window
   ============================================================ */
main#app {
  width: 100%;
  max-width: 27rem;
}

.card {
  background: var(--sheet-2);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  /* The accent bar is the one place state reads at a glance without reading
     any text — colour alone never carries the message, `#status` always does. */
  border-top: 3px solid var(--rule-strong);
  transition: border-top-color 0.2s ease;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--sheet);
}

.card-head .mark {
  flex: none;
  color: var(--ink);
}

.card-head .wordmark {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.stage-chip {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: 2px;
  border: 1px solid var(--rule-strong);
  color: var(--ink-2);
  white-space: nowrap;
}

/* The chip's label is decorative shorthand for the state `#status` already
   states in full — generated content is never the only place a fact lives. */
.stage-chip::before {
  content: 'Checking';
}

.card-body {
  padding: 1.1rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.card-body h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.008em;
  line-height: 1.2;
  margin: 0;
  color: var(--ink);
}

.status-line {
  margin: 0;
  font-size: 0.94rem;
  color: var(--ink-2);
  max-width: 42ch;
}

.card-foot {
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--rule);
  background: var(--sheet);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}

/* ============================================================
   LOADING — quiet, no colour claim yet
   ============================================================ */
.dots {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  height: 0.5rem;
}
.dots i {
  width: 0.32rem;
  height: 0.32rem;
  border-radius: 50%;
  background: var(--ink-3);
  display: block;
}
#app:not([data-state='loading']) .dots {
  display: none;
}
@media (prefers-reduced-motion: no-preference) {
  .dots i {
    animation: dot-pulse 1.1s ease-in-out infinite;
  }
  .dots i:nth-child(2) {
    animation-delay: 0.15s;
  }
  .dots i:nth-child(3) {
    animation-delay: 0.3s;
  }
  @keyframes dot-pulse {
    0%,
    80%,
    100% {
      opacity: 0.25;
    }
    40% {
      opacity: 1;
    }
  }
}

/* ============================================================
   STAMP — the refusal treatment (blocked). A decision, not an outage.
   Hidden on every other state; `#status` carries the real explanation.
   ============================================================ */
.stamp {
  display: none;
  margin: 0.15rem 0 0.1rem;
}
.stamp svg {
  display: block;
  width: 100%;
  max-width: 15rem;
  height: auto;
}
.stamp .sf {
  fill: none;
  stroke: var(--seal);
}
.stamp text {
  fill: var(--seal);
  font-family: var(--font-mono);
  font-weight: 700;
}

/* ============================================================
   FINGERPRINT — device-key comparison chips (promotion ceremony,
   assert.html only). `.fp-group` spans come from ui.ts's `showFingerprint`.
   ============================================================ */
.fingerprint-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
/* No JS toggle needed: hide the whole labelled block whenever the page's own
   `hidden` attribute (set by ui.ts) has not been lifted off #fingerprint. */
.fingerprint-block:has(#fingerprint[hidden]) {
  display: none;
}

.fp-caption {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

#fingerprint {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.7rem;
  background: var(--ui-sunk);
  border: 1px solid var(--hold-edge);
  border-radius: 6px;
}

.fp-group {
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  color: var(--ink);
  background: var(--sheet-2);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 0.18rem 0.4rem;
  white-space: nowrap;
}

.fp-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-2);
}

/* ============================================================
   STATE ACCENTS — every state is legible from #status alone; these are
   reinforcement only, keyed off the same `data-state` register.ts/assert.ts
   already set via `setState`. No colour is invented here, and none of the
   four is used outside the one job tokens.css assigns it.
   ============================================================ */

/* ready: the enclave is verified; nothing has been decided yet, so this is
   deliberately the quietest state, not a "success" colour. */
#app[data-state='ready'] .card {
  border-top-color: var(--rule-strong);
}
#app[data-state='ready'] .stage-chip {
  color: var(--ledger);
  background: var(--ledger-wash);
  border-color: var(--ledger-edge);
}
#app[data-state='ready'] .stage-chip::before {
  content: 'Enclave verified';
}

/* waiting: the OS passkey prompt is up — this is Enclaven's own "someone
   is waiting on a person" state, which is exactly what --hold is for. */
#app[data-state='waiting'] .card {
  border-top-color: var(--hold);
}
#app[data-state='waiting'] .stage-chip {
  color: var(--hold);
  background: var(--hold-wash);
  border-color: var(--hold-edge);
}
#app[data-state='waiting'] .stage-chip::before {
  content: 'Awaiting you';
}
#app[data-state='waiting'] .status-line {
  color: var(--ink);
  font-weight: 600;
}

/* done: sealed / verified — --ledger's job exactly. */
#app[data-state='done'] .card {
  border-top-color: var(--ledger);
}
#app[data-state='done'] .stage-chip {
  color: var(--ledger);
  background: var(--ledger-wash);
  border-color: var(--ledger-edge);
}
#app[data-state='done'] .stage-chip::before {
  content: 'Done';
}
#app[data-state='done'] .status-line {
  color: var(--ledger);
  font-weight: 600;
}

/*
 * blocked: the refusal. Full counterstamp treatment — brand colour at full
 * strength, because this is the screen it exists for (a decision, painted as
 * a decision, not as breakage). Never used for `error` below, which is an
 * ordinary technical hiccup, not the vault staying shut on purpose.
 */
#app[data-state='blocked'] .card {
  border-top-color: var(--seal);
}
#app[data-state='blocked'] .card-body {
  align-items: center;
  text-align: center;
}
#app[data-state='blocked'] .status-line {
  max-width: 46ch;
}
#app[data-state='blocked'] .stage-chip {
  color: var(--seal);
  background: var(--seal-wash);
  border-color: var(--seal-edge);
}
#app[data-state='blocked'] .stage-chip::before {
  content: 'Held closed';
}
#app[data-state='blocked'] .stamp {
  display: block;
}

/*
 * error: an ordinary ceremony hiccup (cancelled, timed out, unsupported
 * authenticator) — recoverable by trying again, and deliberately NOT painted
 * in the refusal colour. tokens.css is explicit that --seal is never for an
 * "ordinary error"; this state gets typographic weight instead of a hue.
 */
#app[data-state='error'] .card {
  border-top-color: var(--rule-strong);
}
#app[data-state='error'] .status-line {
  color: var(--ink);
  font-weight: 600;
  border-left: 2px solid var(--ink-3);
  padding-left: 0.6rem;
}
#app[data-state='error'] .stage-chip {
  color: var(--ink-2);
}
#app[data-state='error'] .stage-chip::before {
  content: 'Stopped';
}
