/* texes — ZIP-320 converter
   Aesthetic: warm letterpress bench instrument. Ink and brass, tight mono
   figures, an off-grid editorial layout. Dark, low-glare, no gradients. */

:root {
  --ink:        #16120e;
  --ink-raise:  #1e1813;
  --ink-sink:   #100d0a;
  --line:       #3a2f24;
  --line-soft:  #2a221a;
  --paper:      #ece3d2;
  --paper-dim:  #b8ab97;
  --muted:      #8b7d69;
  --brass:      #d29b3d;
  --brass-deep: #8d6520;
  --jade:       #77a189;
  --rust:       #c9583c;

  --mono: 'Spline Sans Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --display: 'Fraunces', 'Iowan Old Style', Georgia, serif;

  --gut: clamp(1.25rem, 4vw, 3.5rem);
  --ease: cubic-bezier(.2, .7, .3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-weight: 300;
  font-size: clamp(.875rem, .3vw + .81rem, .95rem);
  line-height: 1.65;
  overflow-x: hidden;
}

::selection { background: var(--brass); color: var(--ink-sink); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

.grain {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  opacity: .32; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

.rules {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1100px 620px at 78% -8%, rgba(210, 155, 61, .09), transparent 70%),
    radial-gradient(760px 520px at 4% 104%, rgba(119, 161, 137, .06), transparent 72%),
    repeating-linear-gradient(90deg, var(--line-soft) 0 1px, transparent 1px 96px);
  opacity: .7;
}

main, .masthead, .footer { position: relative; z-index: 1; }

/* ------------------------------------------------------------ masthead -- */

.masthead {
  display: flex; flex-wrap: wrap; gap: 1.25rem 2rem;
  align-items: flex-end; justify-content: space-between;
  padding: clamp(1.25rem, 3vw, 2.25rem) var(--gut) 1.1rem;
  border-bottom: 1px solid var(--line-soft);
  animation: rise .8s var(--ease) both;
}

.wordmark {
  display: flex; align-items: baseline; gap: .55rem;
  text-decoration: none; color: var(--paper);
}
.wordmark__t {
  font-family: var(--display);
  font-variation-settings: 'SOFT' 50, 'WONK' 1, 'opsz' 100;
  font-weight: 600; font-size: clamp(1.6rem, 3.4vw, 2.1rem);
  letter-spacing: -.02em; line-height: 1;
}
.wordmark:hover .wordmark__t { color: var(--brass); }
.wordmark__sub {
  font-size: .625rem; letter-spacing: .22em; text-transform: uppercase;
  color: var(--muted); border-left: 1px solid var(--line);
  padding-left: .55rem; transform: translateY(-.15em);
}

.masthead__meta { display: flex; gap: clamp(1.25rem, 3vw, 2.5rem); margin: 0; }
.masthead__meta div { display: grid; gap: .1rem; }
.masthead__meta dt {
  font-size: .58rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
}
.masthead__meta dd {
  margin: 0; font-size: .74rem; font-weight: 500; color: var(--paper-dim);
  font-variant-numeric: tabular-nums;
}
#meta-net[data-live] { color: var(--jade); }

/* ---------------------------------------------------------------- hero -- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
  gap: 0 clamp(1.5rem, 5vw, 5rem);
  align-items: start;
  padding: clamp(2.5rem, 7vw, 5.5rem) var(--gut) clamp(2rem, 5vw, 3.5rem);
}

.kicker {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: .6rem; margin: 0 0 1.4rem;
  font-size: .625rem; letter-spacing: .26em; text-transform: uppercase;
  color: var(--brass);
  animation: rise .8s var(--ease) .06s both;
}
.kicker__dot {
  width: 6px; height: 6px; background: var(--brass); border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(210, 155, 61, .14);
  animation: pulse 3.4s var(--ease) infinite;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-variation-settings: 'SOFT' 50, 'WONK' 1, 'opsz' 144;
  font-weight: 450;
  font-size: clamp(2.15rem, 6.2vw, 4.4rem);
  line-height: .98; letter-spacing: -.028em;
  text-wrap: balance;
  animation: rise .9s var(--ease) .12s both;
}
h1 em {
  font-style: italic; font-weight: 600; color: var(--brass);
  font-variation-settings: 'SOFT' 50, 'WONK' 1, 'opsz' 144;
}

.hero__note {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  transform: translateY(1.1rem);
  animation: rise .9s var(--ease) .2s both;
}
.hero__note p { margin: 0 0 .9rem; color: var(--paper-dim); max-width: 42ch; }
.hero__note-foot {
  font-size: .72rem; letter-spacing: .04em; color: var(--muted);
  padding-left: .75rem; border-left: 2px solid var(--brass-deep);
}

code {
  font-family: var(--mono); font-size: .92em; font-weight: 500;
  color: var(--brass); background: rgba(210, 155, 61, .08);
  padding: .05em .3em; border-radius: 2px;
}

/* ------------------------------------------------------------- machine -- */

.machine {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: clamp(1rem, 2.5vw, 2rem);
  align-items: stretch;
  margin: 0 var(--gut);
  padding: clamp(1.25rem, 3vw, 2.25rem);
  background: linear-gradient(180deg, var(--ink-raise), var(--ink-sink));
  border: 1px solid var(--line);
  box-shadow:
    inset 0 1px 0 rgba(236, 227, 210, .05),
    0 32px 60px -30px rgba(0, 0, 0, .85);
  animation: rise 1s var(--ease) .28s both;
}

.field { display: flex; flex-direction: column; min-width: 0; }

.field__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: .6rem; min-height: 1.75rem;
}
.field__head label, .field__title {
  font-size: .6rem; letter-spacing: .22em; text-transform: uppercase; color: var(--muted);
}
.field__actions { display: flex; gap: .4rem; }

.detect {
  font-size: .625rem; letter-spacing: .12em; text-transform: uppercase;
  padding: .18rem .5rem; border: 1px solid var(--line);
  color: var(--muted); white-space: nowrap;
  transition: color .3s var(--ease), border-color .3s var(--ease);
}
.detect[data-state="ok"]  { color: var(--jade); border-color: rgba(119, 161, 137, .45); }
.detect[data-state="bad"] { color: var(--rust); border-color: rgba(201, 88, 60, .45); }

textarea#input {
  font-family: var(--mono); font-size: clamp(.82rem, 1.5vw, 1rem);
  font-weight: 400; line-height: 1.5; letter-spacing: .01em;
  color: var(--paper); background: var(--ink-sink);
  border: 1px solid var(--line);
  padding: .9rem 1rem; resize: none; width: 100%;
  word-break: break-all;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}
textarea#input::placeholder { color: #5c5040; }
textarea#input:focus {
  outline: none; border-color: var(--brass);
  box-shadow: 0 0 0 1px var(--brass), inset 0 0 24px rgba(210, 155, 61, .06);
}

.samples {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  margin-top: .75rem;
}
.samples__label {
  font-size: .58rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
  margin-right: .15rem;
}
.chip, .ghost {
  font-family: var(--mono); font-size: .66rem; letter-spacing: .08em;
  color: var(--paper-dim); background: transparent;
  border: 1px solid var(--line); padding: .28rem .55rem;
  cursor: pointer;
  transition: color .2s var(--ease), border-color .2s var(--ease),
              background-color .2s var(--ease), transform .2s var(--ease);
}
.chip:hover, .ghost:hover:not(:disabled) {
  color: var(--ink-sink); background: var(--brass); border-color: var(--brass);
  transform: translateY(-1px);
}
.chip:active, .ghost:active:not(:disabled) { transform: translateY(0); }
.chip:focus-visible, .ghost:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}
.ghost:disabled { opacity: .35; cursor: not-allowed; }
.ghost--key { border-color: var(--brass-deep); color: var(--brass); }
.ghost[data-done="1"] {
  color: var(--jade); border-color: rgba(119, 161, 137, .5); background: transparent;
}

/* the rail: three-stage pipeline between input and output */
.rail {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; justify-content: center; gap: .5rem;
  min-width: 8.5rem;
  border-left: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft);
  padding: 0 clamp(.75rem, 1.5vw, 1.25rem);
}
.rail__step {
  display: flex; align-items: baseline; gap: .5rem;
  font-size: .66rem; letter-spacing: .04em; color: var(--muted);
  transition: color .35s var(--ease), opacity .35s var(--ease);
  opacity: .45;
}
.rail__idx {
  font-size: .56rem; color: var(--brass-deep); font-variant-numeric: tabular-nums;
}
.rail[data-live="1"] .rail__step { opacity: 1; color: var(--paper-dim); }
.rail[data-live="1"] .rail__step:nth-child(1) { animation: flare .5s var(--ease) 0s; }
.rail[data-live="1"] .rail__step:nth-child(2) { animation: flare .5s var(--ease) .1s; }
.rail[data-live="1"] .rail__step:nth-child(3) { animation: flare .5s var(--ease) .2s; }
.rail[data-live="1"] .rail__idx { color: var(--brass); }

.out {
  display: block; min-height: 5.2rem;
  font-size: clamp(.82rem, 1.5vw, 1rem); font-weight: 500; line-height: 1.5;
  letter-spacing: .01em; word-break: break-all;
  color: var(--brass); background: var(--ink-sink);
  border: 1px solid var(--line); border-left: 2px solid var(--brass-deep);
  padding: .9rem 1rem;
  user-select: all;
  transition: border-color .3s var(--ease);
}
.out__idle { color: #5c5040; font-weight: 300; user-select: none; }
.field--out[data-state="ok"] .out { border-left-color: var(--jade); }
.field--out[data-state="bad"] .out { border-left-color: var(--rust); color: var(--muted); }

.error {
  margin: .6rem 0 0; min-height: 1.2rem;
  font-size: .72rem; line-height: 1.5; color: var(--rust);
}
.error:not(:empty)::before { content: '✕  '; font-weight: 600; }

/* ----------------------------------------------------------- inspector -- */

.inspector { margin: clamp(2.5rem, 6vw, 4.5rem) var(--gut) 0; }

.inspector__head {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto;
  gap: .5rem clamp(1rem, 3vw, 2.5rem);
  align-items: baseline;
  padding-bottom: 1rem; border-bottom: 1px solid var(--line-soft);
}
.inspector__head h2 {
  margin: 0; font-family: var(--display);
  font-variation-settings: 'SOFT' 50, 'WONK' 1, 'opsz' 60;
  font-weight: 450; font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  letter-spacing: -.01em; white-space: nowrap;
}
.inspector__head p { margin: 0; color: var(--muted); font-size: .74rem; max-width: 58ch; }
.inspector__head .ghost { justify-self: end; }

.bytes {
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  gap: 1px;
  margin-top: 1.5rem;
  border: 1px solid var(--line-soft);
  background: var(--line-soft);
}
.byte {
  background: var(--ink-sink); padding: .6rem .2rem .45rem; text-align: center;
  display: grid; gap: .15rem;
}
.byte__hex {
  font-size: clamp(.62rem, 1.15vw, .84rem); font-weight: 500;
  font-variant-numeric: tabular-nums; color: var(--brass);
}
.byte__idx { font-size: .5rem; color: #4e4436; font-variant-numeric: tabular-nums; }
.bytes[data-state="idle"] .byte__hex { color: #4a4034; }
/* cell reveal is staggered per byte from app.js */

/* --------------------------------------------------------------- notes -- */

.notes { margin: clamp(3rem, 8vw, 6rem) var(--gut) 0; }
.notes > h2 {
  margin: 0 0 2rem; font-family: var(--display);
  font-variation-settings: 'SOFT' 50, 'WONK' 1, 'opsz' 90;
  font-weight: 450; font-size: clamp(1.5rem, 3.6vw, 2.4rem);
  letter-spacing: -.02em;
}
.notes__grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: clamp(1.25rem, 3vw, 2.5rem);
}
.note {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  transition: border-color .4s var(--ease);
}
.note--offset { transform: translateY(clamp(.75rem, 2vw, 2rem)); }
.note:hover { border-top-color: var(--brass); }
.note h3 {
  display: flex; align-items: baseline; gap: .6rem; margin: 0 0 .6rem;
  font-family: var(--mono); font-size: .82rem; font-weight: 600; letter-spacing: .01em;
  color: var(--paper);
}
.note__num {
  font-size: .6rem; letter-spacing: .1em; color: var(--brass);
  text-transform: uppercase; min-width: 1.4rem;
}
.note p { margin: 0; color: var(--muted); font-size: .78rem; }

/* -------------------------------------------------------------- footer -- */

.footer {
  margin-top: clamp(4rem, 10vw, 8rem);
  padding: clamp(1.75rem, 4vw, 2.5rem) var(--gut) clamp(2.5rem, 5vw, 3.5rem);
  border-top: 1px solid var(--line-soft);
  display: grid; gap: .9rem;
}
.footer__lead {
  margin: 0; font-family: var(--display);
  font-variation-settings: 'SOFT' 50, 'WONK' 1, 'opsz' 40;
  font-size: 1rem; color: var(--paper-dim); max-width: 40ch;
}
.footer__links { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; }
.footer__links a {
  color: var(--paper-dim); text-decoration: none; font-size: .74rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: .1rem;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.footer__links a:hover { color: var(--brass); border-bottom-color: var(--brass); }
.footer__fine { margin: 0; font-size: .68rem; color: #6b5f4e; max-width: 60ch; }

/* ----------------------------------------------------------- keyframes -- */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hero__note { animation-name: rise-offset; }
@keyframes rise-offset {
  from { opacity: 0; transform: translateY(calc(1.1rem + 14px)); }
  to   { opacity: 1; transform: translateY(1.1rem); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(210, 155, 61, .14); }
  50%      { box-shadow: 0 0 0 8px rgba(210, 155, 61, 0); }
}
@keyframes flare {
  from { color: var(--brass); transform: translateX(-3px); }
  to   { color: var(--paper-dim); transform: translateX(0); }
}
@keyframes cell {
  from { opacity: 0; transform: scale(.86); }
  to   { opacity: 1; transform: scale(1); }
}

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

@media (max-width: 1000px) {
  .machine { grid-template-columns: 1fr; }
  .rail {
    flex-direction: row; justify-content: space-between; flex-wrap: wrap;
    gap: .5rem 1rem; padding: .85rem 0;
    border-left: 0; border-right: 0;
    border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
  }
  .bytes { grid-template-columns: repeat(10, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .hero__note { transform: none; margin-top: 1.75rem; animation-name: rise; }
  .masthead { align-items: flex-start; }
  .masthead__meta { width: 100%; justify-content: space-between; }
  .inspector__head { grid-template-columns: 1fr; }
  .inspector__head .ghost { justify-self: start; }
  .bytes { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .note--offset { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .hero__note { opacity: 1; transform: translateY(1.1rem); }
}
