/*
 * BITOW — visual system per NOIR's STYLEGUIDE.md.
 *
 * Tokens, type stacks, easing, layering, atmosphere, and the button and panel
 * vocabulary (§13) are inherited unchanged. One thing is worth stating up
 * front: --signal is deliberately NOT used here. Nothing in this interface is
 * hidden — there is a single field, focused on load — so spending the accent
 * would be decoration, and §12 says it points at the next action or it does
 * not appear. Errors stay monochrome, as §12 requires.
 *
 * The QR tile is the one white surface in the system. That is not a style
 * choice: inverted QR codes scan badly on a meaningful share of readers, so
 * the code is always dark-on-light. It reads as a lit panel, which suits.
 */

:root {
  color-scheme: dark;

  /* --- guide tokens, verbatim --- */
  --bg: #000000;
  --fg: #ffffff;
  --fg-dim: rgba(255, 255, 255, 0.58);
  --fg-faint: rgba(255, 255, 255, 0.14);
  --fg-body: rgba(255, 255, 255, 0.72);
  --fg-punct: rgba(255, 255, 255, 0.38);

  --font-display: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --mx: 50%;
  --my: 26%;

  --rule: 1px solid var(--fg-faint);
  --pad: clamp(1rem, 3vw, 1.8rem);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ---------------------------------------------------------- atmosphere -- */

.glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    58vmax 58vmax at var(--mx) var(--my),
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02) 34%,
    transparent 68%
  );
  opacity: 0;
  animation: rise-in 2.4s var(--ease) 0.1s forwards;
}

.grain {
  position: fixed;
  inset: -150%;
  z-index: 3;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift 700ms steps(1) infinite;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(135% 100% at 50% 34%, transparent 54%, rgba(0, 0, 0, 0.66) 100%);
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

@keyframes grain-shift {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-6%, 3%); }
  40%  { transform: translate(4%, -5%); }
  60%  { transform: translate(-3%, -2%); }
  80%  { transform: translate(5%, 4%); }
  100% { transform: translate(0, 0); }
}

/* --------------------------------------------------------------- header -- */

.bar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: calc(var(--pad) * 0.8) var(--pad);
  border-bottom: var(--rule);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.14em;
  line-height: 1;
  text-decoration: none;
}

.brand__name {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 1.9vw, 1.42rem);
  font-weight: 900;
  letter-spacing: 0.17em;
  margin-right: -0.17em;
  color: var(--fg);
}

.brand__by {
  font-family: var(--font-mono);
  font-size: clamp(0.56rem, 0.85vw, 0.68rem);
  letter-spacing: 0.19em;
  margin-right: -0.19em;
  color: var(--fg-dim);
}

.brand:focus-visible { outline: 1px solid var(--fg); outline-offset: 4px; }

.privacy {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0 0 0 auto;
  padding: 0.4em 0.75em;
  border: var(--rule);
  font-size: clamp(0.56rem, 0.8vw, 0.66rem);
  letter-spacing: 0.2em;
  color: var(--fg-dim);
  white-space: nowrap;
}

.privacy__label { margin-right: -0.2em; }

.privacy__dot {
  width: 5px;
  height: 5px;
  background: var(--fg);
  border-radius: 50%;
  flex: 0 0 auto;
}

/* -------------------------------------------------------------- controls -- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.6em 0.95em;
  border: var(--rule);
  background: transparent;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: clamp(0.58rem, 0.82vw, 0.68rem);
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
}

.btn:hover, .btn:focus-visible { color: var(--fg); border-color: var(--fg-dim); outline: none; }
.btn:focus-visible { border-color: var(--fg); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn--ghost { border-color: transparent; }
.btn--ghost:hover, .btn--ghost:focus-visible { border-color: var(--fg-faint); }

.link {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: inherit;
  letter-spacing: 0.16em;
  text-decoration: none;
  border-bottom: 1px solid var(--fg-faint);
  cursor: pointer;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
}

.link:hover, .link:focus-visible { color: var(--fg); border-color: var(--fg-dim); outline: none; }

.field {
  width: 100%;
  min-width: 0;
  padding: 0.7em 0.85em;
  border: var(--rule);
  background: transparent;
  color: var(--fg-body);
  font-family: var(--font-mono);
  font-size: clamp(0.66rem, 0.95vw, 0.78rem);
  letter-spacing: 0.04em;
}

.field:focus-visible { outline: none; border-color: var(--fg); color: var(--fg); }

.field--code {
  resize: vertical;
  line-height: 1.75;
  white-space: pre;
  overflow-x: auto;
  color: var(--fg-punct);
}

/* ----------------------------------------------------------------- sheet -- */

.sheet {
  position: relative;
  z-index: 4;
  flex: 1;
  width: 100%;
  max-width: 58rem;
  margin: 0 auto;
  padding: clamp(2rem, 6vh, 4rem) var(--pad) clamp(3rem, 8vh, 5rem);
  display: flex;
  flex-direction: column;
  gap: clamp(2rem, 5vh, 3.4rem);
}

/* ----------------------------------------------------------------- entry -- */

.entry { animation: rise-in 0.8s var(--ease) 0.15s both; }

.entry__label {
  display: block;
  margin-bottom: 0.7rem;
  font-size: clamp(0.58rem, 0.85vw, 0.68rem);
  letter-spacing: 0.24em;
  color: var(--fg-punct);
}

.entry__field { display: flex; gap: 0.4rem; align-items: stretch; }

.entry__input {
  flex: 1;
  min-width: 0;
  padding: 0.85em 1em;
  border: 1px solid var(--fg-dim);
  background: transparent;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: clamp(0.78rem, 1.5vw, 1rem);
  letter-spacing: 0.04em;
}

.entry__input::placeholder { color: var(--fg-punct); letter-spacing: 0.12em; }
.entry__input:focus-visible { outline: none; border-color: var(--fg); }

.entry__status {
  margin: 0.85rem 0 0;
  min-height: 1.4em;
  font-size: clamp(0.6rem, 0.9vw, 0.72rem);
  letter-spacing: 0.14em;
  color: var(--fg-punct);
}

/* Errors are white, never coloured — STYLEGUIDE §12. */
.entry__status.is-error { color: var(--fg); }
.entry__status.is-ok { color: var(--fg-dim); }

.entry__examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 0;
  font-size: clamp(0.58rem, 0.85vw, 0.66rem);
  letter-spacing: 0.14em;
  color: var(--fg-punct);
}

/* ---------------------------------------------------------------- result -- */

.result {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(1.4rem, 4vw, 2.6rem);
  align-items: start;
  padding-top: clamp(1.4rem, 4vh, 2.2rem);
  border-top: var(--rule);
  animation: rise-in 0.7s var(--ease) both;
}

.result__code { display: flex; flex-direction: column; align-items: center; gap: 0.7rem; }

/*
 * The one white surface. QR codes must be dark-on-light to scan reliably, so
 * this tile does not follow the dark palette — deliberately.
 */
.tile {
  padding: 0;
  line-height: 0;
  background: #ffffff;
  border: 1px solid var(--fg-faint);
}

.tile svg { display: block; width: clamp(9rem, 22vw, 13rem); height: auto; }

.result__detail { min-width: 0; display: flex; flex-direction: column; gap: 1.1rem; }

.facts { margin: 0; display: flex; flex-direction: column; gap: 0.45rem; }

.facts__row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-size: clamp(0.6rem, 0.9vw, 0.7rem);
  letter-spacing: 0.16em;
}

.facts dt { color: var(--fg-punct); min-width: 6.5rem; }
.facts dd { margin: 0; color: var(--fg); }

.address {
  margin: 0;
  padding: 0.85em 1em;
  border: var(--rule);
  color: var(--fg);
  font-size: clamp(0.7rem, 1.1vw, 0.85rem);
  letter-spacing: 0.04em;
  line-height: 1.8;
  word-break: break-all;
  user-select: all;
}

.result__detail .btn { align-self: flex-start; }

/* ----------------------------------------------------------------- share -- */

.share {
  display: flex;
  flex-direction: column;
  gap: clamp(1.8rem, 5vh, 2.8rem);
  padding-top: clamp(1.4rem, 4vh, 2.2rem);
  border-top: var(--rule);
  animation: rise-in 0.7s var(--ease) 0.1s both;
}

.share__head { margin-bottom: 0.9rem; }

.share__title {
  margin: 0 0 0.4rem;
  font-size: clamp(0.6rem, 0.9vw, 0.72rem);
  font-weight: 500;
  letter-spacing: 0.24em;
  color: var(--fg);
}

.share__note {
  margin: 0;
  max-width: 52ch;
  font-size: clamp(0.6rem, 0.9vw, 0.7rem);
  line-height: 1.9;
  letter-spacing: 0.03em;
  color: var(--fg-punct);
}

.share__row { display: flex; gap: 0.4rem; align-items: stretch; }
.share__row--stack { flex-direction: column; }

.share__actions { display: flex; align-items: center; gap: 0.9rem; }

.share__size {
  font-size: clamp(0.55rem, 0.8vw, 0.63rem);
  letter-spacing: 0.14em;
  color: var(--fg-punct);
}

/* --------------------------------------------------------------- preview -- */

.preview { margin-top: 1.2rem; }

.preview__label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: clamp(0.55rem, 0.8vw, 0.62rem);
  letter-spacing: 0.22em;
  color: var(--fg-punct);
}

/*
 * The preview renders the snippet exactly as pasted. It inherits currentColor,
 * so this frame proves the card adapts to whatever page it lands on.
 */
.preview__frame {
  padding: clamp(1rem, 3vw, 1.6rem);
  border: 1px dashed var(--fg-faint);
  color: var(--fg-body);
  overflow-x: auto;
}

/* ------------------------------------------------------------------ foot -- */

.foot {
  position: relative;
  z-index: 4;
  padding: var(--pad);
  border-top: var(--rule);
  text-align: center;
}

.foot p {
  margin: 0 0 0.6rem;
  font-size: clamp(0.55rem, 0.8vw, 0.64rem);
  letter-spacing: 0.14em;
  line-height: 1.9;
  color: var(--fg-punct);
}

.foot p:last-child { margin-bottom: 0; }

/* ----------------------------------------------------------------- toast -- */

.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 0.6em 1.1em;
  border: 1px solid var(--fg-dim);
  background: var(--bg);
  color: var(--fg);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  animation: rise-in 0.3s var(--ease) both;
}

/* ------------------------------------------------------------- utilities -- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 50;
  padding: 0.6em 1em;
  background: var(--bg);
  border: 1px solid var(--fg);
  color: var(--fg);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
}

.skip-link:focus { left: 0.5rem; top: 0.5rem; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------ responsive -- */

@media (max-width: 42rem) {
  .result { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .result__detail { width: 100%; align-items: center; }
  .facts__row { justify-content: center; }
  .facts dt { min-width: 0; }
  .result__detail .btn { align-self: center; }
}

@media (max-width: 30rem) {
  .entry__field { flex-wrap: wrap; }
  .entry__input { flex-basis: 100%; }
  .share__row { flex-direction: column; }
}

/* -------------------------------------------------------- reduced motion -- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .grain { animation: none; }

  .glow, .entry, .result, .share, .toast {
    animation-duration: 0.01ms;
    animation-delay: 0s;
  }

  * { transition-duration: 0.01ms !important; }
}
