/* Design tokens pulled from LandingPage.pen variables */
:root {
  --paper: #F6F1EA;
  --ink: #1A1613;
  --ink-secondary: #746B61;
  --rule: #E3DCCF;
  --accent: #2563EB;
  --surface-primary: #FFFFFF;
  --surface-secondary: #FDE2D9;
  --text-primary: #1A1A1A;
  --text-secondary: #4B5563;
  --text-muted: #9CA3AF;
  --border-subtle: #E5E7EB;
  --accent-soft: #DBEAFE;
  --font-heading: 'Funnel Sans', sans-serif;
  --font-body: 'Funnel Sans', sans-serif;
  --radius-full: 9999px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  background: none;
}

/* ---------- Hero ---------- */

.hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: var(--accent-soft);
  padding: 64px;
  overflow: hidden;
}

/* Landing state is a single fixed screen: the hero fills the viewport, no scrolling. */
html:has(body[data-state="empty"]) {
  overflow: hidden;
}

body[data-state="empty"] {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-state="empty"] .hero {
  flex: 1;
  min-height: 0;
}

body[data-state="filled"] .hero {
  padding: 48px 64px;
}

.heading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}

.heading-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.heading-row .plain {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 52px;
  color: var(--text-primary);
  line-height: 1.1;
}

.heading-row .script {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  font-size: 60px;
  color: var(--accent);
  line-height: 1.1;
}

.word-app {
  display: inline-flex;
  align-items: baseline;
  gap: 14px;
  position: relative;
}

.word-app .count {
  position: relative;
}

/* Hand-drawn marker stroke, so the underline matches the Caveat handwriting. The stroke keeps its
   thickness (non-scaling-stroke) while the wobble stretches to the width of the number. */
.word-app .underline {
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -6px;
  height: 12px;
  background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 12' preserveAspectRatio='none'><path d='M3 6C16 4.8 28 7.2 42 6C56 4.8 68 7.2 82 6C88 5.5 93 6 97 6' fill='none' stroke='%232563EB' stroke-width='5' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>") no-repeat center / 100% 100%;
}

/* ---------- Back button (results state only) ---------- */

.back-button {
  position: absolute;
  top: 24px;
  left: 32px;
  z-index: 2;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: #FFFFFF;
  box-shadow: 0 6px 16px rgba(30, 58, 138, 0.2);
  transition: transform 0.15s, background 0.15s;
}

.back-button svg {
  width: 20px;
  height: 20px;
}

.back-button:hover {
  background: #1D4ED8;
  transform: translateX(-2px);
}

.back-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

body[data-state="empty"] .back-button {
  display: none;
}

/* ---------- Search bar ---------- */

.search-bar {
  display: flex;
  align-items: center;
  width: 640px;
  max-width: 100%;
  padding: 8px 8px 8px 24px;
  background: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  position: relative;
  z-index: 1;
  box-shadow: 0 8px 24px rgba(30, 58, 138, 0.15);
}

.search-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-placeholder {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text-primary);
  padding: 0 12px;
}

.search-placeholder::placeholder {
  color: var(--text-muted);
}

.search-button {
  padding: 12px 28px;
  background: var(--accent);
  border-radius: var(--radius-full);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

/* ---------- Decorative clouds ---------- */

.cloud {
  position: absolute;
  pointer-events: none;
}

/* Clouds sit at mirrored offsets around the search bar (the .search-anchor centre).
   --sx/--sy are the cloud's side (-1 left/top, +1 right/bottom). Clouds stay level (--tilt: 0). */
.search-anchor {
  position: relative;
  width: 640px;
  max-width: 100%;
  margin-top: 40px;

  /* --u is the cloud scale unit: 1% of the viewport width, or 1.6% of its height if that is
     smaller. It is 14.4px at the 1440x900 reference size, where every cloud size and offset
     below equals its original pixel value; larger screens grow from there. */
  --u: min(1vw, 1.6vh);
  --dx: clamp(280px, 36vw, calc(36.1 * var(--u)));
  --dy-top: clamp(60px, 30vh, calc(16.67 * var(--u)));
  /* bottom clouds are full size: cap the offset so they never run past the hero's bottom edge */
  --dy-bottom: clamp(40px, calc(50vh - max(215px, 14.93 * var(--u))), calc(13.9 * var(--u)));
  --scale-top: 0.85;
  --scale-bottom: 1;
  --tilt: 0deg;
}

/* Results state: the hero is short and the search bar sits low, so keep the top clouds closer. */
body[data-state="filled"] .search-anchor {
  --u: 14.4px;
  /* the hero is a fixed-height strip here, so clouds keep their size but spread with the width */
  --dx: max(280px, 36vw);
  --dy-top: 105px;
}

.cloud {
  left: 50%;
  top: 50%;
  translate: calc(-50% + var(--sx) * var(--dx)) calc(-50% + var(--sy) * var(--dy));
  rotate: calc(var(--sx) * var(--sy) * var(--tilt));
  z-index: 0;
  filter: drop-shadow(0 12px 20px rgba(30, 58, 138, 0.08));
}

.cloud-large       { --sx: -1; --sy: -1; --dy: var(--dy-top);    scale: var(--scale-top);    width: max(420px, calc(29.17 * var(--u))); height: auto; aspect-ratio: 420 / 260; }
.cloud-medium      { --sx:  1; --sy: -1; --dy: var(--dy-top);    scale: var(--scale-top);    width: max(260px, calc(18.06 * var(--u))); height: auto; aspect-ratio: 260 / 160; }
.cloud-small       { --sx:  1; --sy:  1; --dy: var(--dy-bottom); scale: var(--scale-bottom); width: max(160px, calc(11.11 * var(--u))); height: auto; aspect-ratio: 160 / 100; }
.cloud-bottom-left { --sx: -1; --sy:  1; --dy: var(--dy-bottom); scale: var(--scale-bottom); width: max(220px, calc(15.28 * var(--u))); height: auto; aspect-ratio: 220 / 136; }

.heading-wrap .connector {
  position: absolute;
  left: calc(100% - 110px);
  top: -13px;
  width: 180px;
  height: 140px;
  pointer-events: none;
}

body[data-state="filled"] .connector {
  display: none;
}

@media (max-width: 1100px) {
  .heading-wrap .connector {
    display: none;
  }
}

body[data-state="filled"] .cloud-small,
body[data-state="filled"] .cloud-bottom-left {
  display: none;
}

/* ---------- Results ---------- */

.results {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 64px 64px;
  background: var(--surface-primary);
}

.results-list {
  width: 900px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.column-header {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 4px 12px;
}

.info-spacer {
  flex: 1;
}

.match-column {
  width: 80px;
  display: flex;
  justify-content: flex-end;
}

.match-label {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-secondary);
}

/* Index Row component */

.index-row {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 24px 4px;
  border-top: 1px solid var(--border-subtle);
}

.index-row .info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 16px 0 0;
  min-width: 0;
}

.index-row .name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.index-row .app-name {
  font-family: 'Funnel Sans', sans-serif;
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
}

.index-row .best-match-label {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
}

.index-row .description {
  font-family: 'Funnel Sans', sans-serif;
  font-weight: normal;
  font-size: 14px;
  color: var(--ink-secondary);
}

.index-row .score-column {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.index-row .score-value {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 20px;
  color: #1BB24D;
}

.index-row .score-label {
  font-family: 'Fredoka', sans-serif;
  font-weight: normal;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--ink-secondary);
  text-transform: uppercase;
}

/* ---------- State visibility ---------- */

body[data-state="empty"] .results {
  display: none;
}

body[data-state="filled"] .results {
  display: flex;
}

/* ---------- Live search additions ---------- */

.search-bar.busy .search-button {
  opacity: 0.7;
  pointer-events: none;
}

a.index-row {
  color: inherit;
  text-decoration: none;
}

a.index-row:hover .app-name {
  color: var(--accent);
}

a.index-row:focus-visible,
.search-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.index-row .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.index-row .tag {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.results-list.loading #results-rows {
  opacity: 0.4;
  transition: opacity 0.15s;
}

.results-list.no-results .column-header {
  display: none;
}

.status {
  margin: 32px 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 16px;
}

.status-error {
  color: #B91C1C;
}

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  .hero,
  body[data-state="filled"] .hero {
    padding: 40px 20px;
  }

  .heading-row {
    gap: 8px;
  }

  .heading-row .plain {
    font-size: 30px;
  }

  .heading-row .script {
    font-size: 36px;
  }

  .search-bar {
    width: 100%;
  }

  .search-anchor {
    --dx: 34vw;
    --dy-top: 28vh;
    --dy-bottom: 22vh;
    --scale-top: 0.42;
    --scale-bottom: 0.42;
  }

  body[data-state="filled"] .search-anchor {
    --dx: 34vw;
    --dy-top: 95px;
  }

  .cloud {
    opacity: 0.6;
  }

  .back-button {
    top: 16px;
    left: 16px;
    width: 40px;
    height: 40px;
  }

  .results {
    padding: 24px 20px 48px;
  }

  .index-row .score-column,
  .match-column {
    width: 52px;
  }
}
