/*
  wobblehaus design system: direction K ("the highlighter").
  Rules live in docs/design-system.md. test/design-system.test.ts enforces the basics:
  colours and font families are only ever set here, as tokens, and used through var().
*/

/* == Fonts (self-hosted, SIL Open Font License; see /fonts/*.LICENSE.txt) == */

@font-face {
  font-family: "Funnel Display";
  src: url("/fonts/funnel-display-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Martian Mono";
  src: url("/fonts/martian-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

/* == Tokens == */

:root {
  /* Colour: paper, ink, marker. Everything else is a shade of ink or a functional colour. */
  --paper: #ffffff;
  --surface: #f4f4f4;        /* quiet panels on paper */
  --ink: #0d0d0d;            /* on paper: 19.8:1 */
  --ink-soft: #4a4a4a;       /* on paper: 8.9:1, on surface: 8.1:1 */
  --marker: #f2ff3d;         /* fill only, never text on paper */
  --marker-ink: #0d0d0d;     /* text on marker, both themes: 18:1 */
  --error: #b3261e;          /* on paper: 6.5:1 */
  --focus: #0d0d0d;

  /* Type: who is talking decides the face. */
  --font-name: "Funnel Display", "Instrument Sans", system-ui, sans-serif;  /* the name, app names, buttons */
  --font-text: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;  /* everything you read */
  --font-typed: "Martian Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;  /* only what a person types */

  --text-s: 0.875rem;
  --text-m: 1.0625rem;
  --text-l: 1.25rem;
  --text-xl: clamp(1.5rem, 4.5vw, 2rem);
  --text-title: clamp(2rem, 7vw, 3.25rem);
  --text-hero: clamp(2.25rem, 9vw, 5.25rem);

  /* Space: one scale, used through gap and padding. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;

  /* Shape */
  --line: 2px;
  --radius-s: 12px;
  --radius-m: 18px;
  --radius-pill: 999px;
  --radius-marker: 0.28em 0.14em 0.32em 0.12em;
  --radius-blob: 46% 54% 50% 44% / 54% 46% 54% 46%;

  /* Motion: wobble once, then rest. */
  --ease-jelly: cubic-bezier(0.3, 0.7, 0.4, 1);
  --dur-wobble: 0.9s;
  --dur-swipe: 0.9s;

  --measure: 40rem;
  --page: 64rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d0d0d;
    --surface: #1b1b1b;
    --ink: #f5f5f5;          /* on paper: 18.4:1 */
    --ink-soft: #b8b8b8;     /* on paper: 10:1, on surface: 8.9:1 */
    --error: #ff8a80;        /* on paper: 8.4:1 */
    --focus: #f5f5f5;
    color-scheme: dark;
  }
}

/* == Base == */

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--text-m);
  line-height: 1.55;
}

a {
  color: inherit;
  text-decoration-thickness: var(--line);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 6px;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

h2 {
  font-size: var(--text-xl);
}

p {
  margin: 0;
  text-wrap: pretty;
}

/* == Page frame == */

.site-header,
.page,
.footer {
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding-left: max(var(--space-4), env(safe-area-inset-left, 0px));
  padding-right: max(var(--space-4), env(safe-area-inset-right, 0px));
}

.site-header {
  padding-block: var(--space-5) 0;
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  padding-block: var(--space-7) var(--space-7);
}

.page--narrow {
  max-width: var(--measure);
  gap: var(--space-5);
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  padding-block: var(--space-5) var(--space-7);
  border-top: var(--line) solid var(--ink);
  font-size: var(--text-s);
  color: var(--ink-soft);
}

/* == Brand: the mark + the name == */

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
}

.brand__mark {
  width: 2.25rem;
  height: 2.25rem;
  transform-origin: 50% 100%;
  animation: wobble var(--dur-wobble) var(--ease-jelly) 0.2s both;
}

.brand:hover .brand__mark,
.brand:active .brand__mark {
  animation-name: wobble-again;
}

.brand__name {
  font-family: var(--font-name);
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: -0.05em;
  line-height: 1;
}

@keyframes wobble {
  0% { transform: scale(1, 1); }
  20% { transform: scale(1.14, 0.84); }
  40% { transform: scale(0.92, 1.08); }
  60% { transform: scale(1.04, 0.97); }
  80%, 100% { transform: scale(1, 1); }
}

/* Same motion under a new name, so hover replays it. */
@keyframes wobble-again {
  0% { transform: scale(1, 1); }
  20% { transform: scale(1.14, 0.84); }
  40% { transform: scale(0.92, 1.08); }
  60% { transform: scale(1.04, 0.97); }
  80%, 100% { transform: scale(1, 1); }
}

/* == Marker: one per screen, on the thing that's new or just for you == */

.marker {
  position: relative;
  z-index: 0;
  display: inline-block;
  background: none;
  color: var(--marker-ink);
}

.marker::before {
  content: "";
  position: absolute;
  inset: 0.12em -0.08em 0.02em;
  z-index: -1;
  background: var(--marker);
  border-radius: var(--radius-marker);
  transform-origin: 0% 60%;
  animation: swipe var(--dur-swipe) var(--ease-jelly) 0.5s both;
}

@keyframes swipe {
  0% { transform: scale(0, 1); }
  55% { transform: scale(1.06, 0.72); }
  70% { transform: scale(0.98, 1.14); }
  85% { transform: scale(1.01, 0.96); }
  100% { transform: scale(1, 1); }
}

/* == Hero == */

.hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-5);
  padding-top: var(--space-6);
}

.hero__title {
  font-size: var(--text-hero);
  max-width: 15em;
}

.hero__line {
  display: block;
}

.hero__lede {
  max-width: 32em;
  font-size: var(--text-l);
  color: var(--ink-soft);
}

/* == Say box: where a person types. The cursor lives here and nowhere else. == */

.say-box {
  width: 100%;
  max-width: 34rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius-m);
}

.say-box__label {
  font-size: var(--text-s);
  font-weight: 600;
  color: var(--ink-soft);
}

.say-box__list {
  position: relative;
  height: 1.6em;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-typed);
  font-size: clamp(0.75rem, 3.6vw, var(--text-s)); /* a 26-character sentence fits a 320px phone */
  font-weight: 500;
}

/* Each sentence types out in turn. --n is its length in characters. */
.say-box__list li {
  position: absolute;
  inset: 0 auto auto 0;
  width: 0;
  visibility: hidden; /* until its turn, so only one cursor shows */
  overflow: hidden;
  white-space: nowrap;
  border-right: var(--line) solid var(--ink);
  animation:
    say 12s steps(var(--n), end) infinite,
    caret 1s steps(1, end) infinite;
}

/* Lengths match the sentences in public/index.html (inline styles are blocked by our CSP). */
.say-box__list li:nth-child(1) { --n: 26; }
.say-box__list li:nth-child(2) { --n: 26; animation-delay: 4s, 0s; }
.say-box__list li:nth-child(3) { --n: 25; animation-delay: 8s, 0s; }

@keyframes say {
  0% { width: 0; visibility: visible; }
  18%, 30% { width: calc(var(--n) * 1ch); visibility: visible; }
  33%, 100% { width: 0; visibility: hidden; }
}

@keyframes caret {
  50% { border-right-color: transparent; }
}

/* == Buttons == */

.button {
  display: inline-block;
  font-family: var(--font-name);
  font-weight: 800;
  font-size: var(--text-l);
  line-height: 1.2;
  color: var(--marker-ink);
  background: var(--marker);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 0.85rem 1.75rem;
  text-decoration: none;
  cursor: pointer;
  justify-self: start;
  transition: transform 0.15s var(--ease-jelly), box-shadow 0.15s var(--ease-jelly);
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 3px 0 var(--ink);
}

.button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.button--quiet {
  color: var(--ink);
  background: var(--paper);
}

/* == Promises == */

.promises {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.promise-list {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.promise-list li {
  padding-top: var(--space-4);
  border-top: var(--line) solid var(--ink);
  font-size: var(--text-l);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

/* == Sign-up == */

.signup {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-m);
}

.signup__note {
  color: var(--ink-soft);
}

.waitlist {
  display: grid;
  gap: var(--space-5);
  max-width: var(--measure);
}

.field {
  display: grid;
  gap: var(--space-2);
}

label {
  font-weight: 600;
}

.field__hint {
  font-size: var(--text-s);
  color: var(--ink-soft);
}

.field__error {
  font-weight: 600;
  color: var(--error);
}

input[type="email"],
input[type="text"],
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius-s);
  padding: var(--space-3) var(--space-4);
}

textarea {
  resize: vertical;
  min-height: 5.5rem;
}

input[aria-invalid="true"] {
  border-color: var(--error);
}

/* Honeypot: out of sight and out of the tab order. */
.field--trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* == Message pages (thank you, errors) == */

.lede {
  font-size: var(--text-l);
  color: var(--ink-soft);
}

.message__title {
  font-size: var(--text-title);
}

/* == Wider screens == */

@media (min-width: 48rem) {
  .site-header {
    padding-block: var(--space-6) 0;
  }

  .page {
    padding-block: var(--space-7) var(--space-8);
  }

  .say-box__list {
    font-size: var(--text-m);
  }

  .promise-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-6);
  }

  .signup {
    padding: var(--space-7);
  }
}

/* == Less motion: everything is shown at rest == */

@media (prefers-reduced-motion: reduce) {
  .brand__mark,
  .marker::before,
  .say-box__list li {
    animation: none;
  }

  .say-box__list {
    height: auto;
    display: grid;
    gap: var(--space-1);
  }

  .say-box__list li {
    position: static;
    width: auto;
    border-right: 0;
    visibility: visible;
  }

  .button {
    transition: none;
  }

  .button:hover,
  .button:active {
    transform: none;
  }
}
