/*
 * Kistrl Share components · direction A "Front door".
 * Reads only custom properties from tokens.css; no literal colours. Classes use the ks- prefix;
 * states use the hidden attribute, aria-busy, aria-invalid, aria-pressed and data-kind.
 * See design/README.md for the markup of each screen and design/reference.html for a working page.
 */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, ol, ul, figure, pre { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.ks-icon { width: 1.25em; height: 1.25em; flex: none; }
.ks-visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.ks-skip {
  position: absolute; left: var(--space-sm); top: -100px; z-index: 50;
  padding: 10px var(--space-sm); border-radius: var(--radius-control);
  background: var(--primary); color: var(--primary-foreground);
}
.ks-skip:focus { top: var(--space-xs); }

/* ---------- Page frame ---------- */
.ks-wrap {
  width: 100%; max-width: var(--page-max); margin-inline: auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}
.ks-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); padding-block: var(--space-md); }
.ks-brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--brand-ink); text-decoration: none;
  font-weight: 600; font-size: 1.0625rem; letter-spacing: -0.01em;
}
.ks-brand__bird { width: 34px; height: 26px; color: var(--brand-bird); }
.ks-brand__product { font-weight: 400; color: var(--brand-ink-soft); }
.ks-nav { display: flex; gap: var(--space-md); font-size: 0.9375rem; }
.ks-nav a { color: var(--brand-ink-soft); text-decoration: none; }
.ks-nav a:hover { color: var(--brand-ink); text-decoration: underline; }

/* ---------- Hero: copy beside the card; stacks below 900px ---------- */
.ks-hero {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, var(--card-width));
  gap: var(--space-2xl); align-items: center;
  padding-block: var(--space-xl) var(--space-3xl);
}
.ks-hero__copy { display: grid; gap: var(--space-sm); align-content: start; min-width: 0; }
.ks-eyebrow {
  font-size: var(--text-caption); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--eyebrow);
}
.ks-hero__title {
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: var(--text-display); line-height: var(--display-leading);
  letter-spacing: var(--display-tracking); text-wrap: balance; max-width: 13ch;
  color: var(--hero-ink);
}
.ks-hero__lede { font-size: var(--text-lede); color: var(--hero-ink-soft); max-width: 36ch; text-wrap: pretty; }
.ks-points { display: grid; gap: 10px; margin-top: var(--space-2xs); }
.ks-points li { display: flex; align-items: center; gap: 10px; color: var(--hero-ink); }
.ks-points .ks-icon { color: var(--point-icon); }

/* ---------- Card: holds one screen at a time ---------- */
.ks-card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--card-edge); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--card-pad);
  min-width: 0;
}
.ks-screen { display: grid; gap: var(--space-md); }
.ks-screen__head { display: grid; gap: var(--space-2xs); }
.ks-card__title {
  font-family: var(--font-heading); font-weight: var(--heading-weight);
  font-size: var(--text-title); line-height: 1.25; letter-spacing: var(--heading-tracking);
  text-wrap: balance;
}
.ks-card__text { color: var(--muted-foreground); }

/* ---------- Status pill (screen header) and inline status messages ---------- */
.ks-status {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  padding: var(--space-3xs) 10px var(--space-3xs) var(--space-2xs); border-radius: var(--radius-pill);
  font-size: var(--text-caption); font-weight: 600;
  background: var(--muted); color: var(--muted-foreground);
}
.ks-status--ok { background: var(--success); color: var(--success-foreground); }
.ks-status .ks-icon { width: 16px; height: 16px; }

/* role="status" message under a form; data-kind="info" | "error" (set by ui.js setStatus) */
.ks-message {
  padding: 10px 14px; border-radius: var(--radius-input);
  background: var(--muted); color: var(--card-foreground); font-size: 0.9375rem;
}
.ks-message[data-kind="error"] { background: var(--destructive-surface); color: var(--destructive-foreground); }

/* ---------- Form ---------- */
.ks-form { display: grid; gap: var(--space-md); }
.ks-field { display: grid; gap: var(--space-2xs); border: 0; margin: 0; padding: 0; min-width: 0; }
.ks-label { font-weight: var(--label-weight); font-size: 0.9375rem; padding: 0; }
.ks-hint { font-size: var(--text-small); color: var(--muted-foreground); display: flex; justify-content: space-between; gap: var(--space-xs); flex-wrap: wrap; }
.ks-count { font-variant-numeric: tabular-nums; }
.ks-textarea, .ks-select, .ks-input, .ks-copyfield__input {
  width: 100%; background: var(--field); color: var(--field-foreground);
  border: 1px solid var(--input); border-radius: var(--radius-input);
  transition: border-color .15s, box-shadow .15s;
}
.ks-input { min-height: var(--control-height); padding: 10px 14px; }
.ks-textarea {
  min-height: 9.5rem; resize: vertical; padding: var(--space-xs) 14px;
  font-family: var(--font-mono); font-size: 0.9375rem; line-height: 1.55;
}
.ks-textarea::placeholder, .ks-input::placeholder { color: var(--placeholder); font-family: var(--font-sans); }
.ks-textarea:hover, .ks-select:hover, .ks-input:hover { border-color: var(--input-hover); }
.ks-textarea:focus-visible, .ks-select:focus-visible, .ks-input:focus-visible, .ks-copyfield__input:focus-visible {
  outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--ring-soft);
}
.ks-textarea[aria-invalid="true"], .ks-input[aria-invalid="true"] { border-color: var(--destructive); }
.ks-textarea[readonly] { resize: none; background: var(--secret-surface); }
.ks-expiry__row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ks-expiry__or { color: var(--muted-foreground); }
.ks-select {
  flex: 1 1 9rem; min-height: var(--control-height); padding: 10px 40px 10px 14px;
  appearance: none; cursor: pointer;
  background-image: var(--select-chevron); background-repeat: no-repeat;
  background-position: right 14px center; background-size: 14px;
}

/* Checkbox row: "Also require a password" */
.ks-check { display: flex; align-items: center; gap: 10px; cursor: pointer; justify-self: start; }
.ks-check input {
  appearance: none; margin: 0; flex: none; width: 20px; height: 20px; cursor: pointer;
  border: 1px solid var(--input); border-radius: 6px; background: var(--field);
  display: grid; place-content: center;
}
.ks-check input::after {
  content: ""; width: 10px; height: 6px; margin-top: -2px;
  border: solid var(--primary-foreground); border-width: 0 0 2px 2px; rotate: -45deg; opacity: 0;
}
.ks-check input:checked { background: var(--primary); border-color: var(--primary); }
.ks-check input:checked::after { opacity: 1; }
.ks-check input:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.ks-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2xs);
  min-height: var(--control-height); padding: 10px var(--space-md);
  border: 1px solid transparent; border-radius: var(--radius-control);
  font-weight: var(--button-weight); font-size: 1rem; line-height: 1.2; text-decoration: none;
  cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, transform .1s;
}
.ks-btn:active { transform: translateY(1px); }
.ks-btn--block { width: 100%; }
.ks-btn--primary { background: var(--primary); color: var(--primary-foreground); }
.ks-btn--primary:hover { background: var(--primary-hover); }
.ks-btn--secondary { background: var(--secondary); color: var(--secondary-foreground); border-color: var(--border-strong); }
.ks-btn--secondary:hover { background: var(--hover); }
.ks-btn--ghost { background: transparent; color: var(--card-foreground); }
.ks-btn--ghost:hover { background: var(--hover); }
.ks-btn:disabled, .ks-btn[aria-busy="true"] { cursor: progress; opacity: .72; }
.ks-btn[aria-busy="true"] .ks-icon { animation: ks-pulse 1s ease-in-out infinite; }
@keyframes ks-pulse { 50% { opacity: .35; } }

/* ---------- Link ready ---------- */
.ks-copyfield { display: grid; gap: var(--space-2xs); }
.ks-copyfield__row { display: flex; gap: var(--space-2xs); }
.ks-copyfield__input {
  flex: 1; min-width: 0; min-height: var(--control-height); padding: 10px 14px;
  font-family: var(--font-mono); font-size: var(--text-small); text-overflow: ellipsis;
}
.ks-anatomy {
  display: grid; gap: 6px; padding: var(--space-xs) 14px; border-radius: var(--radius-input);
  background: var(--surface-sunken); font-size: var(--text-caption); color: var(--muted-foreground);
}
.ks-anatomy__url { font-family: var(--font-mono); overflow-wrap: anywhere; color: var(--card-foreground); }
.ks-anatomy__key {
  background: var(--key-mark); color: var(--key-mark-foreground);
  border-radius: var(--radius-mark); padding: 0 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
/* Cells grow to fill each row, so a wrapped row never leaves an empty cell; outlines draw the inner rules. */
.ks-summary {
  display: flex; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: var(--radius-input); overflow: hidden;
}
.ks-summary > div { flex: 1 1 8.5rem; outline: 1px solid var(--border); padding: 10px 14px; display: grid; gap: 2px; }
.ks-summary dt { font-size: var(--text-caption); color: var(--muted-foreground); }
.ks-summary dd { font-weight: 600; font-variant-numeric: tabular-nums; }
.ks-actions { display: flex; gap: var(--space-2xs); flex-wrap: wrap; }

/* Disclosure: "Send the link and key separately" */
.ks-disclosure { border-top: 1px solid var(--border); padding-top: var(--space-sm); }
.ks-disclosure > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: var(--space-2xs);
  font-weight: var(--button-weight); color: var(--card-foreground);
  border-radius: var(--radius-input); width: fit-content;
}
.ks-disclosure > summary::-webkit-details-marker { display: none; }
.ks-disclosure > summary::before {
  content: ""; width: 7px; height: 7px; margin-inline: 4px 2px;
  border: solid var(--muted-foreground); border-width: 0 2px 2px 0; rotate: -45deg; transition: rotate .15s;
}
.ks-disclosure[open] > summary::before { rotate: 45deg; }
.ks-disclosure[open] { display: grid; gap: var(--space-sm); }

/* ---------- Notices ---------- */
.ks-notice {
  display: flex; gap: var(--space-xs); align-items: flex-start;
  padding: 14px var(--space-sm); border-radius: var(--radius-input);
  background: var(--muted); color: var(--card-foreground); font-size: 0.9375rem;
}
.ks-notice .ks-icon { margin-top: 1px; color: var(--muted-foreground); }
.ks-notice--warn { background: var(--warning); color: var(--warning-foreground); }
.ks-notice--warn .ks-icon { color: inherit; }
.ks-notice strong { font-weight: 650; }

/* ---------- Revealed secret ---------- */
.ks-secret { display: grid; gap: var(--space-2xs); }
.ks-secret__value {
  font-family: var(--font-mono); font-size: 0.9375rem; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
  padding: var(--space-sm) 18px; border-radius: var(--radius-input);
  background: var(--secret-surface); color: var(--secret-foreground);
  border: 1px solid var(--secret-edge);
  max-height: 18rem; overflow: auto;
}

/* ---------- Gone ---------- */
.ks-empty { display: grid; gap: var(--space-sm); justify-items: start; }
.ks-empty__icon { width: 44px; height: 44px; color: var(--empty-icon); }

/* ---------- Copy feedback ---------- */
.ks-toast {
  position: fixed; left: 50%; bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px)); z-index: 40;
  translate: -50% 0; padding: 10px var(--space-sm); border-radius: var(--radius-pill);
  background: var(--toast); color: var(--toast-foreground); box-shadow: var(--shadow-popover);
  font-size: 0.9375rem; font-weight: var(--button-weight); display: inline-flex; gap: var(--space-2xs); align-items: center;
  transition: opacity .2s, translate .2s;
}
.ks-toast:empty { opacity: 0; translate: -50% 8px; pointer-events: none; }

/* ---------- How it works ---------- */
.ks-how { padding-block: var(--space-3xl); border-top: 1px solid var(--section-rule); display: grid; gap: var(--space-xl); }
.ks-how__head { display: grid; gap: var(--space-xs); max-width: 46rem; }
.ks-how__title {
  font-family: var(--font-heading); font-weight: var(--heading-weight);
  font-size: var(--text-section); line-height: 1.15; letter-spacing: var(--heading-tracking); text-wrap: balance;
}
.ks-how__lede { color: var(--muted-foreground); font-size: var(--text-lede); max-width: 60ch; }
.ks-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-lg); counter-reset: step; }
.ks-step { display: grid; gap: var(--space-2xs); align-content: start; counter-increment: step; }
.ks-step::before {
  content: counter(step); display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--step-edge); color: var(--step-ink);
  font-weight: 600; font-size: var(--text-small); font-variant-numeric: tabular-nums; margin-bottom: var(--space-3xs);
}
.ks-step h3 { font-size: 1.0625rem; font-weight: 620; }
.ks-step p { color: var(--muted-foreground); }
.ks-ledger-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--ledger-surface); }
.ks-ledger { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
.ks-ledger caption { text-align: left; font-weight: 620; padding: 14px 18px var(--space-3xs); }
.ks-ledger th, .ks-ledger td { text-align: left; padding: var(--space-xs) 18px; border-top: 1px solid var(--border); vertical-align: top; }
.ks-ledger thead th { border-top: 0; font-size: var(--text-caption); font-weight: 600; color: var(--muted-foreground); }
.ks-ledger td:last-child { color: var(--muted-foreground); }
.ks-yes, .ks-no { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.ks-no { color: var(--success-foreground); }
.ks-yes { color: var(--card-foreground); }

.ks-footer { padding-block: var(--space-lg) var(--space-2xl); color: var(--muted-foreground); font-size: var(--text-small); display: flex; gap: var(--space-2xs) var(--space-md); flex-wrap: wrap; justify-content: space-between; }
.ks-footer a { color: inherit; }

/* ---------- Responsive, motion, forced colours ---------- */
@media (max-width: 900px) {
  .ks-hero { grid-template-columns: minmax(0, 1fr); gap: var(--space-lg); padding-block: var(--space-sm) var(--space-2xl); }
  .ks-steps { grid-template-columns: minmax(0, 1fr); gap: var(--space-md); }
}
@media (max-width: 520px) {
  .ks-nav a:not(:first-child) { display: none; }
  .ks-copyfield__row { flex-direction: column; }
  .ks-copyfield__row .ks-btn { width: 100%; }
  .ks-card { padding: var(--card-pad-sm); }
  .ks-actions .ks-btn { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
}
@media (forced-colors: active) {
  .ks-btn, .ks-card, .ks-notice, .ks-status, .ks-message { border: 1px solid CanvasText; }
  .ks-anatomy__key { outline: 1px solid CanvasText; }
  .ks-check input:checked::after { border-color: Canvas; }
}

/* Inline SVG sprite holder (added in public/: the reference page used an inline style, which the CSP blocks). */
.ks-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Scrambled ciphertext preview on the reveal screen (decorative, aria-hidden). Added in public/. */
.ks-cipher {
  display: flex; gap: var(--space-2xs); align-items: flex-start;
  padding: var(--space-xs) 14px; border-radius: var(--radius-input);
  background: var(--secret-surface); border: 1px solid var(--secret-edge);
  color: var(--muted-foreground); user-select: none;
}
.ks-cipher .ks-icon { margin-top: 2px; color: var(--link); }
.ks-cipher__text {
  font-family: var(--font-mono); font-size: var(--text-small); line-height: 1.6;
  overflow-wrap: anywhere; min-width: 0;
}
/* Decoding: keep the revealed textarea steady while characters churn. */
.ks-textarea[aria-busy="true"] { cursor: progress; }
