/* Random Animal Generator — W1 homepage + legal shell
   Field-guide / specimen-card language. Shared by all design-source HTML. */

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

html {
  color-scheme: light;
  background: var(--paper);
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  font-size: var(--fs-16);
  font-weight: 450;
  line-height: var(--lh-ui);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(rgba(28, 23, 16, 0.035) 0.7px, transparent 0.8px);
  background-size: 3px 3px;
  min-height: 100%;
}

img, svg { max-width: 100%; height: auto; display: block; }
button, input { font: inherit; color: inherit; }
a { color: var(--sienna); text-underline-offset: 0.18em; }
a:hover { color: var(--sienna-deep); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: var(--s-4);
  top: -100px;
  z-index: 100;
  background: var(--ink);
  color: var(--paper-raised);
  padding: var(--s-2) var(--s-4);
}
.skip:focus { top: var(--s-2); }

.wrap {
  width: min(var(--max), 100%);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Header ---------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 88%, var(--paper-raised));
  padding-top: var(--safe-t);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  min-height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}

.brand-mark {
  height: 16px; /* QA: must remain legible at 16px */
  width: auto;
  flex: 0 0 auto;
}

.brand-name {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: var(--fs-14);
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* View toggle — same path, not a game control */
.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  flex: 0 0 auto;
}

.view-toggle .view-label {
  font-size: var(--fs-12);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.view-switch {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  background: var(--paper-raised);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.view-switch a,
.view-switch .view-opt {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 5px 12px;
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--ink-muted);
  text-decoration: none;
  line-height: 1.2;
  cursor: pointer;
}

.view-switch a + a,
.view-switch .view-opt + .view-opt {
  border-left: 1px solid var(--rule);
}

.view-switch [aria-checked="true"],
.view-switch a[aria-current="true"] {
  background: var(--ink);
  color: var(--paper-raised);
}

.view-hint {
  display: none;
  margin: 0;
  font-size: var(--fs-12);
  color: var(--ink-faint);
}

@media (min-width: 900px) {
  .view-hint { display: inline; }
  .brand-name { font-size: var(--fs-15); }
}

/* ---------- Tool (first screen) ---------- */
.tool {
  padding-block: var(--s-5) var(--s-6);
}

/* Mobile: display:contents lets us reorder H1, then FILTER, then the plate.
   Desktop: .tool-left is a real column so the H1 sits on top of the controls. */
.tool-grid {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.tool-left { display: contents; }

.tool-h1 { order: 0; }
.filter-block { order: 1; }
.tool-grid > .result-plate { order: 2; }
.primary-slot { order: 3; }
.keyboard-hint { order: 4; }

.tool-h1 {
  font-family: var(--font-display);
  font-weight: 560;
  font-size: var(--fs-h1);
  font-optical-sizing: auto;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}

.filter-block { margin-bottom: var(--s-5); }

.filter-label,
.kicker {
  display: block;
  margin: 0 0 var(--s-2);
  font-family: var(--font-ui);
  font-size: var(--fs-11);
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--paper-raised);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--fs-14);
  font-weight: 600;
  line-height: 1.2;
}

.chip:hover { border-color: var(--ink); color: var(--ink); }

.chip[aria-current="true"],
.chip.is-selected {
  background: var(--sienna);
  border-color: var(--sienna-deep);
  color: #fbf3ea;
}

.keyboard-hint {
  margin: var(--s-4) 0 0;
  font-size: var(--fs-13);
  color: var(--ink-muted);
}

/* Touch-first devices: hide the keyboard hint. Pointer/keyboard devices still see it. */
@media (hover: none) and (pointer: coarse) {
  .keyboard-hint { display: none; }
}

/* Primary generate — in-flow on desktop; sticky thumb zone on small screens */
.cta-generate {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border: 1px solid var(--sienna-deep);
  border-radius: var(--r-md);
  background: var(--sienna);
  color: #fbf3ea;
  font-family: var(--font-ui);
  font-size: var(--fs-16);
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-decoration: none;
}

.cta-generate:hover { background: var(--sienna-deep); color: #fbf3ea; }

.cta-generate:disabled,
.cta-generate.is-disabled {
  background: var(--paper-inset);
  border-color: var(--rule);
  color: var(--ink-faint);
  cursor: not-allowed;
}

.primary-slot { margin-top: var(--s-2); }

/* On small screens the in-flow desktop control is reserved for the sticky bar.
   A visually hidden but layout-preserving spacer is not used; the bar is fixed. */
@media (max-width: 899px) {
  .brand-name { display: none; } /* H1 immediately below carries the product name */

  /* Keep Card / Wheel discoverable after the default header would have scrolled away. */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
  }

  /* Expose filter / hint / generate as siblings so FILTER can sit above the plate. */
  .tool-controls { display: contents; }

  .filter-block { margin-bottom: 0; }

  .result-image-frame {
    max-height: 30vh;
  }

  html {
    scroll-padding-top: calc(var(--header-h) + var(--safe-t));
  }

  .result-plate { padding: var(--s-3); }

  .result-name { margin-top: var(--s-3); }

  .tool-grid > .result-plate { margin-bottom: var(--s-1); }

  body.page-home {
    padding-bottom: calc(var(--sticky-cta-h) + var(--safe-b) + 16px);
  }

  .primary-slot--tool .cta-generate {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: auto;
    min-height: 52px;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 14px 20px calc(14px + var(--safe-b));
    box-shadow: 0 -1px 0 var(--rule);
  }

  /* Only one large primary in the thumb zone */
  .result-actions .cta-reroll { display: none; }
}

@media (min-width: 900px) {
  .tool { padding-block: var(--s-7) var(--s-8); }

  .tool-grid {
    display: grid;
    grid-template-columns: minmax(260px, 0.92fr) minmax(360px, 1.15fr);
    gap: var(--s-7) var(--s-8);
    align-items: start;
  }

  .tool-left {
    display: flex;
    flex-direction: column;
    gap: var(--s-5);
    min-width: 0;
  }

  .tool-h1, .tool-grid > .result-plate, .tool-controls { order: initial; }

  .tool-controls { min-width: 0; }

  .cta-generate { min-height: 56px; font-size: var(--fs-18); }
}

/* ---------- Result plate ---------- */
.result-plate {
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  box-shadow: 0 0 0 1px var(--paper-raised), 0 0 0 5px var(--paper-raised), 0 0 0 6px var(--rule);
  padding: var(--s-4);
  min-width: 0;
}

@media (min-width: 900px) {
  .result-plate { padding: var(--s-5); }
}

.result-label {
  margin: 0 0 var(--s-3);
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--ink-muted);
}

.result-image-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--paper-inset);
  border: 1px solid var(--rule);
  overflow: hidden;
  display: grid;
  place-items: stretch;
}

.result-image-frame img,
.result-image-frame .result-art,
.result-image-frame .placeholder-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 40%;
  background: #f4ecdb;
}

/* Wheel is a medallion view of the same result — not a spinner game */
body.view-wheel .result-image-frame {
  aspect-ratio: 1;
  width: min(100%, 420px);
  margin-inline: auto;
  border-radius: 50%;
  border: 0;
  box-shadow:
    0 0 0 2px var(--rule-strong),
    0 0 0 8px var(--paper-raised),
    0 0 0 9px var(--rule);
}

@media (max-width: 899px) {
  /* After the general Wheel width so the medallion stays circular and compact. */
  body.view-wheel .result-image-frame {
    max-height: none;
    width: min(100%, 220px);
  }
}

body.view-wheel .result-image-frame img,
body.view-wheel .result-image-frame .result-art,
body.view-wheel .result-image-frame .placeholder-art {
  object-fit: cover;
  transform: scale(1.14);
  transform-origin: 45% 60%;
}

body.view-wheel .result-plate { text-align: center; }
body.view-wheel .result-actions { justify-content: center; }
body.view-wheel .result-credit { text-align: center; }

.result-name {
  margin: var(--s-4) 0 var(--s-2);
  font-family: var(--font-display);
  font-weight: 560;
  font-size: var(--fs-name);
  font-optical-sizing: auto;
  letter-spacing: -0.02em;
  line-height: var(--lh-tight);
}

.result-fact {
  margin: 0 0 var(--s-3);
  font-family: var(--font-display);
  font-size: var(--fs-16);
  font-weight: 400;
  line-height: var(--lh-body);
  color: var(--ink);
}

.fact-source {
  display: inline;
  margin-left: 0.15em;
  font-family: var(--font-ui);
  font-style: normal;
  font-weight: 650;
  font-size: 0.78em;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.result-fact a.fact-source:hover { color: var(--ink); }

.result-credit {
  margin: 0 0 var(--s-4);
  font-size: var(--fs-12);
  color: var(--ink-faint);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
}

.cta-reroll,
.cta-save,
.cta-share,
.cta-tryagain {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-size: var(--fs-14);
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  background: var(--paper-raised);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}

/* Outlined Re-roll: stronger than Save / Share, but not a second solid primary. */
.cta-reroll {
  min-height: 44px;
  padding-inline: 18px;
  background: var(--paper-raised);
  border: 2px solid var(--ink);
  color: var(--ink);
  font-size: var(--fs-15);
  font-weight: 700;
}

.cta-reroll:hover {
  background: var(--paper-inset);
  color: var(--ink);
  border-color: var(--ink);
}
.cta-save:hover, .cta-share:hover, .cta-tryagain:hover { border-color: var(--ink); }

.status {
  margin: var(--s-3) 0 0;
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-13);
  font-weight: 600;
  border-left: 3px solid var(--rule-strong);
  color: var(--ink-muted);
}

.status.is-success {
  border-left-color: var(--moss);
  background: var(--moss-soft);
  color: var(--moss);
}

.status.is-error {
  border-left-color: var(--oxide);
  background: var(--oxide-soft);
  color: var(--oxide);
}

.status.is-transient {
  border-left-color: var(--rule-strong);
  background: var(--paper-inset);
}

.share-url {
  margin: var(--s-2) 0 0;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--paper);
  font-size: var(--fs-13);
  color: var(--ink);
}

/* Image states */
.image-fail,
.image-loading {
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--s-5);
  background: var(--paper-inset);
  color: var(--ink-muted);
  font-size: var(--fs-14);
  min-height: 180px;
}

.image-loading::after {
  content: "";
  width: 28px;
  height: 1px;
  background: var(--rule-strong);
  margin-top: var(--s-3);
}

.empty-filter {
  padding: var(--s-6) var(--s-4);
  text-align: center;
  border: 1px dashed var(--rule-strong);
  background: var(--paper);
}

.empty-filter p {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-18);
}

/* Result enter animation — 180ms fade + 6px shift only */
@keyframes plate-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.result-plate.is-updating .result-image-frame,
.result-plate.is-updating .result-name,
.result-plate.is-updating .result-fact {
  animation: plate-in var(--dur) var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  .result-plate.is-updating .result-image-frame,
  .result-plate.is-updating .result-name,
  .result-plate.is-updating .result-fact {
    animation: none;
  }
}

/* ---------- Below the fold ---------- */
.below {
  border-top: 1px solid var(--rule);
  padding-block: var(--s-8) var(--s-8);
}

.below h2 {
  font-family: var(--font-display);
  font-weight: 560;
  font-size: clamp(1.65rem, 1.35rem + 1vw, var(--fs-32));
  font-optical-sizing: auto;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 var(--s-4);
}

.below h3 {
  font-family: var(--font-display);
  font-weight: 560;
  font-size: var(--fs-24);
  font-optical-sizing: auto;
  letter-spacing: -0.015em;
  margin: 0 0 var(--s-3);
}

.below p, .below li, .below dd {
  font-family: var(--font-display);
  font-size: var(--fs-17);
  font-weight: 400;
  line-height: var(--lh-body);
  color: var(--ink);
}

.below p { margin: 0 0 var(--s-4); max-width: var(--measure); }
.below p:last-child { margin-bottom: 0; }

.block + .block { margin-top: var(--s-8); }

.use-grid {
  display: grid;
  gap: var(--s-6);
}

@media (min-width: 900px) {
  .use-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--s-6);
    align-items: start;
  }
  .use-grid .use-case {
    padding-right: var(--s-4);
    border-top: 1px solid var(--rule);
    padding-top: var(--s-4);
  }
  .use-grid .use-case p { max-width: none; }
}

.use-index {
  display: block;
  margin-bottom: var(--s-2);
  font-family: var(--font-ui);
  font-size: var(--fs-11);
  font-weight: 650;
  letter-spacing: 0.14em;
  color: var(--sienna);
}

.how-list {
  margin: 0 0 var(--s-5);
  padding: 0;
  list-style: none;
  counter-reset: how;
  max-width: 68ch;
}

.how-list li {
  counter-increment: how;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: var(--s-3);
  margin: 0 0 var(--s-4);
}

.how-list li::before {
  content: counter(how, decimal-leading-zero);
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  font-weight: 650;
  letter-spacing: 0.06em;
  color: var(--sienna);
  padding-top: 0.35em;
}

.internal-links {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.internal-links li {
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-display);
  font-size: var(--fs-18);
  margin: 0;
}

.internal-links a {
  display: flex;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  color: var(--ink);
  text-decoration: none;
}

.internal-links a:hover { color: var(--sienna); }

.internal-links a::after {
  content: "→";
  color: var(--sienna);
  font-family: var(--font-ui);
}

.lead-line {
  margin-bottom: var(--s-4);
}

.faq { margin: 0; padding: 0; max-width: 68ch; }
.faq dt {
  font-family: var(--font-display);
  font-size: var(--fs-18);
  font-weight: 560;
  margin: var(--s-5) 0 var(--s-2);
}
.faq dt:first-child { margin-top: 0; }
.faq dd {
  margin: 0;
}

.cta-back {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid var(--sienna-deep);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--sienna);
  font-family: var(--font-ui);
  font-size: var(--fs-16);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.cta-back:hover { background: var(--sienna); color: #fbf3ea; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--rule);
  padding-block: var(--s-5) var(--s-6);
  background: color-mix(in srgb, var(--paper) 70%, var(--paper-inset));
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-6);
  align-items: baseline;
  justify-content: space-between;
}

.footer-name {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-16);
  font-weight: 500;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  font-size: var(--fs-14);
  font-weight: 600;
}

.footer-nav a { color: var(--ink); text-decoration: none; }
.footer-nav a:hover { color: var(--sienna); text-decoration: underline; }

.footer-contact {
  margin: 0;
  font-size: var(--fs-13);
  color: var(--ink-muted);
}

.footer-contact a { color: var(--ink-muted); }

/* ---------- Legal shell ---------- */
body.page-legal { background-image: none; background-color: var(--paper); }

.legal-preview-bar {
  background: var(--ink);
  color: var(--paper-raised);
  font-size: var(--fs-13);
  padding: 8px var(--gutter);
}

.legal-preview-bar a { color: #f1d2c2; }

.legal-page {
  padding-block: var(--s-8) var(--s-9);
}

.legal-page h1 {
  font-family: var(--font-display);
  font-weight: 560;
  font-size: clamp(2rem, 1.6rem + 1.4vw, 3rem);
  letter-spacing: -0.02em;
  margin: 0 0 var(--s-3);
}

.legal-meta {
  margin: 0 0 var(--s-2);
  font-size: var(--fs-14);
  color: var(--ink-muted);
}

.legal-body {
  margin-top: var(--s-6);
  max-width: 66ch;
}

.legal-body h2 {
  font-family: var(--font-display);
  font-weight: 560;
  font-size: var(--fs-20);
  margin: var(--s-7) 0 var(--s-3);
}

.legal-body p, .legal-body li {
  font-family: var(--font-display);
  font-size: var(--fs-17);
  line-height: var(--lh-body);
  margin: 0 0 var(--s-4);
}

.legal-body ul { padding-left: 1.2em; margin: 0 0 var(--s-4); }

.design-note {
  margin: 0 0 var(--s-6);
  padding: var(--s-3) var(--s-4);
  border: 1px dashed var(--stamp);
  background: color-mix(in srgb, var(--oxide-soft) 55%, var(--paper-raised));
  font-family: var(--font-ui) !important;
  font-size: var(--fs-13) !important;
  line-height: 1.45 !important;
  color: var(--sienna-deep);
  max-width: none;
}

/* ---------- States gallery (design only) ---------- */
.states-index { padding: var(--s-6) 0; }
.states-index h1 {
  font-family: var(--font-display);
  font-size: var(--fs-32);
  margin: 0 0 var(--s-3);
}
.states-index ol { max-width: 60ch; }
.state-section {
  border-top: 2px solid var(--ink);
  padding-block: var(--s-6) var(--s-8);
}
.state-banner {
  margin: 0 0 var(--s-5);
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sienna);
}

/* Implementation-only: make credit and licence names clearly clickable. */
.result-credit a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.result-credit a:hover { color: var(--ink); }
