@import url("tokens.css");

/* ====================================================================
   Base
   ==================================================================== */

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

html, body {
  overflow-x: clip;
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
  /* The masthead is sticky, so focus and anchor jumps must clear it. */
  scroll-padding-top: 4.5rem;
}

body {
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0;
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  font-style: normal;
  overflow-wrap: anywhere;
  min-width: 0;
  text-wrap: balance;
}

h1 {
  font-size: var(--text-display);
  letter-spacing: var(--track-display);
  font-weight: 800;
}

h2 {
  font-size: var(--text-xl);
  letter-spacing: var(--track-tight);
  font-weight: 700;
}

h3 {
  font-size: var(--text-md);
  letter-spacing: var(--track-tight);
  font-weight: 650;
}

p { margin: 0; }

a {
  color: var(--color-accent-hi);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
a:hover { color: var(--color-ink); }

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--color-accent-lo);
  color: var(--color-accent-ink);
}

.shell {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  padding-inline: var(--space-sm);
}

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

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* ====================================================================
   Age gate

   An overlay, not a display:none on <main>. Crawlers still read the page
   — hiding the content from them would cost the search traffic the whole
   site exists for — while a visitor has to pass the wall first.
   ==================================================================== */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-sm);
  background: var(--color-paper);
  overflow-y: auto;
}

:root[data-verified] .gate { display: none; }
:root:not([data-verified]) body { overflow: hidden; }

.gate__panel {
  width: 100%;
  max-width: 30rem;
  padding: var(--space-lg) var(--space-md);
  background: var(--color-paper-2);
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.gate__title {
  font-size: var(--text-xl);
  font-weight: 750;
  letter-spacing: var(--track-tight);
  line-height: var(--leading-tight);
  overflow-wrap: anywhere;
}

.gate__body {
  margin-top: var(--space-sm);
  color: var(--color-ink-2);
  font-size: var(--text-base);
  line-height: var(--leading-body);
}

.gate__actions {
  margin-top: var(--space-md);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  justify-content: center;
}
.gate__actions .btn { flex: 1 1 11rem; text-decoration: none; }

.gate__fine {
  margin-top: var(--space-md);
  font-size: var(--text-xs);
  color: var(--color-ink-3);
  line-height: var(--leading-snug);
}

/* ====================================================================
   Thumbnails — fixed box so a slow image never shifts the row
   ==================================================================== */

.thumb {
  flex: none;
  width: 5.5rem;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-paper-3);
  border: var(--rule) solid var(--color-line);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb--grid {
  width: 100%;
  aspect-ratio: 16 / 10;
}

/* ====================================================================
   Header
   ==================================================================== */

.masthead {
  border-bottom: var(--rule) solid var(--color-line);
  background: var(--color-paper);
  position: sticky;
  top: 0;
  z-index: 20;
}

.masthead__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2xs) var(--space-sm);
  min-height: 3.5rem;
  /* Eight locales means eight nav widths. Russian and German run long
     enough to push the language picker off a 320px screen, so the bar
     wraps rather than hiding its own controls. */
  flex-wrap: wrap;
  padding-block: var(--space-2xs);
}

.wordmark {
  /* Not flex: the name is one word, and flex gaps would split it. */
  display: inline-block;
  font-size: var(--text-md);
  font-weight: 750;
  letter-spacing: var(--track-tight);
  color: var(--color-ink);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark em {
  font-style: normal;
  color: var(--color-accent);
}
.wordmark:hover { color: var(--color-ink); }

.masthead__nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3xs) var(--space-xs);
  min-width: 0;
}

.langpick {
  max-width: 8.5rem;
  min-height: 2.25rem;
  background: transparent;
  border-color: transparent;
  color: var(--color-ink-2);
}
.langpick:hover, .langpick.is-hover {
  color: var(--color-ink);
  border-color: var(--color-line-2);
  background: var(--color-paper-2);
}

.themetoggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--color-ink-2);
  background: transparent;
  border: var(--rule) solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.themetoggle:hover, .themetoggle.is-hover {
  color: var(--color-ink);
  background: var(--color-paper-2);
  border-color: var(--color-line);
}
.themetoggle:active, .themetoggle.is-active { transform: translateY(1px); }
.themetoggle .icon--sun { display: none; }
:root[data-theme="light"] .themetoggle .icon--sun { display: block; }
:root[data-theme="light"] .themetoggle .icon--moon { display: none; }

.history { margin-top: var(--space-xl); }

.history__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2xs) var(--space-xs);
  padding: var(--space-2xs) var(--space-xs);
  border-bottom: var(--rule) solid var(--color-line);
  font-size: var(--text-sm);
}
.history__row:last-child { border-bottom: 0; }
.history__id {
  font-family: var(--font-mono);
  color: var(--color-ink);
  overflow-wrap: anywhere;
  min-width: 0;
  flex: 1 1 8rem;
}
.history__when {
  color: var(--color-ink-3);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.navlink {
  color: var(--color-ink-2);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 550;
  padding: var(--space-2xs) var(--space-xs);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.navlink:hover, .navlink.is-hover {
  color: var(--color-ink);
  background: var(--color-paper-2);
}
.navlink:active, .navlink.is-active { background: var(--color-paper-3); }
.navlink[aria-current="page"] { color: var(--color-ink); }

/* ====================================================================
   Main
   ==================================================================== */

main { flex: 1 0 auto; }

.hero {
  padding-block: var(--space-xl) var(--space-md);
}

.hero p {
  margin-top: var(--space-xs);
  color: var(--color-ink-2);
  font-size: var(--text-md);
  max-width: var(--measure);
}

/* ====================================================================
   The tool
   ==================================================================== */

.tool {
  background: var(--color-paper-2);
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: var(--space-sm);
  box-shadow: var(--shadow-md);
}

.tool__label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-ink-2);
  margin-bottom: var(--space-2xs);
}

.tool__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}

.input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
  color: var(--color-ink);
  background: var(--color-paper);
  border: var(--rule) solid var(--color-line-2);
  border-radius: var(--radius-md);
  padding: var(--space-xs);
  resize: vertical;
  min-height: 3.25rem;
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.input::placeholder { color: var(--color-ink-3); }
.input:hover, .input.is-hover { border-color: var(--color-ink-3); }
.input:focus-visible {
  border-color: var(--color-focus);
  outline-offset: 1px;
}
.input:disabled, .input.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--color-paper-2);
}
.input[aria-invalid="true"] { border-color: var(--color-warn); }

.tool__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  margin-top: var(--space-xs);
}

.hint {
  font-size: var(--text-xs);
  color: var(--color-ink-3);
  margin-top: var(--space-2xs);
}

/* ---- buttons ------------------------------------------------------- */

.btn {
  --btn-bg: var(--color-paper-3);
  --btn-ink: var(--color-ink);
  --btn-line: var(--color-line-2);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xs);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 650;
  letter-spacing: var(--track-wide);
  line-height: 1;
  white-space: nowrap;
  min-height: 2.875rem;
  padding-inline: var(--space-md);
  color: var(--btn-ink);
  background: var(--btn-bg);
  border: var(--rule) solid var(--btn-line);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.btn:hover, .btn.is-hover { --btn-bg: var(--color-line); }
.btn:active, .btn.is-active { transform: translateY(1px); }

.btn--primary {
  --btn-bg: var(--color-accent-lo);
  --btn-ink: var(--color-accent-ink);
  --btn-line: var(--color-accent-lo);
  flex: 1 1 12rem;
}
.btn--primary:hover, .btn--primary.is-hover {
  --btn-bg: var(--color-accent);
  --btn-line: var(--color-accent);
}

.btn--quiet {
  --btn-bg: transparent;
  --btn-ink: var(--color-ink-2);
  --btn-line: transparent;
  font-weight: 550;
  padding-inline: var(--space-xs);
}
.btn--quiet:hover, .btn--quiet.is-hover {
  --btn-bg: var(--color-paper-3);
  --btn-ink: var(--color-ink);
}

.btn--sm {
  min-height: 2.25rem;
  font-size: var(--text-sm);
  padding-inline: var(--space-xs);
}

.btn:disabled, .btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn[data-state="loading"] { cursor: progress; }
.btn[data-state="loading"] .btn__spinner { display: block; }
.btn__spinner {
  display: none;
  width: 1.05em;
  height: 1.05em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 640ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn[data-state="success"] {
  --btn-bg: var(--color-ok-bg);
  --btn-ink: var(--color-ok);
  --btn-line: var(--color-ok);
}
.btn[data-state="error"] {
  --btn-bg: var(--color-warn-bg);
  --btn-ink: var(--color-warn);
  --btn-line: var(--color-warn);
}

/* ====================================================================
   Progress

   Ramps to 90% over the known duration, then fills the rest only once
   the work is actually done. A bar that reaches 100% while the visitor
   is still waiting is worse than no bar at all.
   ==================================================================== */

.progress {
  height: 3px;
  margin-top: var(--space-xs);
  border-radius: 999px;
  background: var(--color-paper-3);
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.progress[data-on] { opacity: 1; }

.progress__bar {
  height: 100%;
  border-radius: inherit;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--dur-mid) var(--ease-out);
}

.progress[data-on="running"] .progress__bar {
  animation: fill var(--progress-dur, 2500ms) var(--ease-out) forwards;
}
.progress[data-on="done"] .progress__bar {
  animation: none;
  transform: scaleX(1);
}

@keyframes fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(0.9); }
}

@media (prefers-reduced-motion: reduce) {
  .progress[data-on="running"] .progress__bar {
    animation: none;
    transform: scaleX(0.9);
  }
}

/* ====================================================================
   Status + results
   ==================================================================== */

.status {
  display: none;
  align-items: flex-start;
  gap: var(--space-2xs);
  margin-top: var(--space-xs);
  padding: var(--space-xs);
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.status[data-tone] { display: flex; }
.status[data-tone="working"] { color: var(--color-ink-2); background: var(--color-paper-3); }
.status[data-tone="error"]   { color: var(--color-warn); background: var(--color-warn-bg); border-color: var(--color-warn); }
.status[data-tone="success"] { color: var(--color-ok);   background: var(--color-ok-bg);   border-color: var(--color-ok); }
.status strong { display: block; font-weight: 650; }
.status span { color: inherit; opacity: 0.85; }

.results {
  list-style: none;
  margin: var(--space-md) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}

.result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2xs) var(--space-xs);
  padding: var(--space-xs);
  background: var(--color-paper-2);
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-md);
  animation: rise var(--dur-slow) var(--ease-out) both;
}

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

.result__id {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-ink);
  overflow-wrap: anywhere;
  min-width: 0;
  flex: 1 1 10rem;
}

.result__meta {
  font-size: var(--text-xs);
  color: var(--color-ink-3);
  font-variant-numeric: tabular-nums;
}

.result__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3xs);
  margin-left: auto;
}

.select {
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--color-ink);
  background: var(--color-paper-3);
  border: var(--rule) solid var(--color-line-2);
  border-radius: var(--radius-sm);
  padding: var(--space-3xs) var(--space-2xs);
  min-height: 2.25rem;
  cursor: pointer;
}
.select:hover { border-color: var(--color-ink-3); }
.select:disabled { opacity: 0.45; cursor: not-allowed; }

/* ====================================================================
   Saved: favourites + creators. Text only, never media.
   ==================================================================== */

.saved { margin-top: var(--space-xl); }

.saved__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-xs);
  flex-wrap: wrap;
  margin-bottom: var(--space-xs);
}

.saved__count {
  font-size: var(--text-xs);
  color: var(--color-ink-3);
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: var(--space-md) var(--space-sm);
  border: var(--rule) dashed var(--color-line-2);
  border-radius: var(--radius-md);
  color: var(--color-ink-3);
  font-size: var(--text-sm);
  text-align: center;
}

.chips {
  list-style: none;
  margin: 0 0 var(--space-xs);
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3xs);
  padding: var(--space-3xs) var(--space-2xs);
  background: var(--color-paper-3);
  border: var(--rule) solid var(--color-line-2);
  border-radius: 999px;
  font-size: var(--text-sm);
  color: var(--color-ink-2);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.chip:hover, .chip.is-hover { color: var(--color-ink); border-color: var(--color-ink-3); }
.chip[aria-pressed="true"], .chip.is-selected {
  background: var(--color-accent-bg);
  border-color: var(--color-accent);
  color: var(--color-ink);
}

/* ====================================================================
   Prose (how-to, faq, legal)
   ==================================================================== */

.prose { padding-block: var(--space-lg) var(--space-xl); }
.prose > * + * { margin-top: var(--space-sm); }
.prose h2 { margin-top: var(--space-xl); }
.prose h3 { margin-top: var(--space-md); }
.prose p, .prose li { max-width: var(--measure); color: var(--color-ink-2); }
.prose ol, .prose ul { padding-left: 1.25rem; margin-block: 0; }
.prose li + li { margin-top: var(--space-2xs); }
.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-paper-3);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.faq-item + .faq-item { margin-top: var(--space-md); }
.faq-item h3 { color: var(--color-ink); }

/* ====================================================================
   Footer
   ==================================================================== */

.footer {
  flex: none;
  border-top: var(--rule) solid var(--color-line);
  margin-top: var(--space-2xl);
  padding-block: var(--space-md) var(--space-xl);
  font-size: var(--text-sm);
  color: var(--color-ink-3);
}

.footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs) var(--space-sm);
  margin-bottom: var(--space-sm);
}
.footer__links a {
  /* Eight links wrapping on a phone need a real tap target, not a line
     box. 28px clears the 24px floor in WCAG 2.5.8. */
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  color: var(--color-ink-2);
  text-decoration: none;
  white-space: nowrap;
}
.footer__links a:hover { color: var(--color-ink); text-decoration: underline; }

.footer__note {
  max-width: var(--measure);
  line-height: var(--leading-snug);
}
.footer__note + .footer__note { margin-top: var(--space-2xs); }

/* ====================================================================
   Responsive
   ==================================================================== */

@media (min-width: 40rem) {
  .shell { padding-inline: var(--space-md); }
  .tool { padding: var(--space-md); }
  .tool__field { flex-direction: column; }
}

@media (max-width: 30rem) {
  .navlink { padding-inline: var(--space-3xs); font-size: var(--text-xs); }
  .langpick { max-width: 6rem; font-size: var(--text-xs); }
  .wordmark { font-size: var(--text-base); }
}

@media (max-width: 24rem) {
  .btn { padding-inline: var(--space-sm); }
  .btn--primary { flex-basis: 100%; }
}

/* ====================================================================
   Reduced motion
   ==================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .result { animation: fade 140ms linear both; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
  .btn__spinner { animation: spin 1.4s linear infinite !important; }
}
