/* ===== BETTERMOJIS — mobile-first Bauhaus minimal ===== */
:root {
  --ink: #0a0a0a;
  --paper: #f4f1ea;
  --paper-2: #e9e5d8;
  --yellow: #ffc857;

  --tile: clamp(72px, 22vw, 124px);
  --gap: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--paper); color-scheme: light; }
html, body { margin: 0; padding: 0; color: var(--ink); }
body {
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  background: var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  /* `overflow-x: clip` blocks horizontal scroll WITHOUT creating a new scroll
     container — important, otherwise the sticky topbar stops sticking. */
  overflow-x: clip;
}
html { overflow-x: clip; }

/* ===== topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: 4px solid var(--ink);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "brand"
    "search"
    "meta";
  gap: 10px;
  align-items: center;
}

.brand { grid-area: brand; }
.search { grid-area: search; }
.meta { grid-area: meta; }

.brand h1 {
  font-family: "Archivo Black", "Inter", system-ui, sans-serif;
  font-size: clamp(32px, 8vw, 44px);
  line-height: 0.9;
  letter-spacing: -0.025em;
  margin: 0;
}

.brand .tag {
  margin: 4px 0 0;
  font-size: clamp(10px, 2.6vw, 12px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}
.brand .tag .by { opacity: 0.55; }
.brand .tag .by a {
  color: #ff1a1a; /* bright red */
  text-decoration: none;
  letter-spacing: 0.14em;
  opacity: 1;
  font-weight: 800;
}
.brand .tag .by a:hover { text-decoration: underline; text-underline-offset: 3px; }

.search {
  width: 100%;
  font: 700 clamp(16px, 4vw, 18px)/1 "Space Grotesk", system-ui, sans-serif; /* min 16px to stop iOS auto-zoom */
  background: #fff;
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 0;
  padding: 14px 16px;
  outline: none;
  letter-spacing: 0.01em;
  -webkit-appearance: none;
  appearance: none;
  transition: transform 80ms ease, background 80ms ease, box-shadow 80ms ease;
}
.search::-webkit-search-cancel-button { -webkit-appearance: none; }
.search::placeholder { color: #8a857a; font-weight: 500; }
.search:focus { background: var(--yellow); box-shadow: 6px 6px 0 0 var(--ink); transform: translate(-2px, -2px); }

/* search wrap: holds the input + the lang switcher together */
.search-wrap { position: relative; width: 100%; min-width: 0; }
.search-wrap .search { padding-right: 64px; }

/* clear button — slides along just after the typed text.
   Desktop: rectangular "CLEAR [esc]" pill 4rem after the text.
   Mobile:  circular X 2rem after the text. */
.clear-btn {
  --gap: 4rem; /* JS reads this to compute the px gap after text */
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  background: var(--ink);
  color: var(--paper);
  border: 0;
  cursor: pointer;
  padding: 8px 10px;
  font: 800 10px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 0;
  z-index: 2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: left 110ms ease-out, opacity 120ms ease;
}
.clear-btn .kbd { opacity: 0.55; font-weight: 700; }
.clear-btn:hover, .clear-btn:focus-visible { background: #d62828; outline: none; }
.clear-btn .lbl-m { display: none; }
.search-wrap.has-text .clear-btn { opacity: 1; pointer-events: auto; }

@media (max-width: 719px) {
  .clear-btn {
    --gap: 2rem;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    justify-content: center;
  }
  .clear-btn .lbl-d { display: none; }
  .clear-btn .lbl-m { display: inline; }
}

/* lang indicator inside search input (right edge, light) */
.lang-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  font: 800 12px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.1em;
  color: var(--ink);
  opacity: 0.42;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 0;
  transition: opacity 80ms ease;
}
.lang-btn:hover, .lang-btn[aria-expanded="true"] { opacity: 0.95; }
.lang-btn .caret { font-size: 9px; opacity: 0.7; }

.lang-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  background: #fff;
  border: 4px solid var(--ink);
  box-shadow: 8px 8px 0 0 var(--ink);
  z-index: 40;
  padding: 2px;
}
.lang-pop button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  font: 700 12px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.06em;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--ink);
}
.lang-pop button b { font-weight: 800; opacity: 0.55; display: inline-block; min-width: 32px; }
.lang-pop button:hover { background: var(--yellow); }
.lang-pop button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.lang-pop button[aria-selected="true"] b { opacity: 0.7; color: var(--yellow); }

/* skeleton placeholder — visible only while search is floating */
.search-skeleton { display: none; }
.topbar { grid-template-areas: "brand" "search" "meta"; }
.topbar .brand { grid-area: brand; }
.topbar .search-skeleton, .topbar .search-wrap { grid-area: search; }
.topbar .meta { grid-area: meta; }

/* initial mode: topbar collapses to just the brand; floating search is the
   only search affordance until the user starts typing. */
body.initial .search-skeleton { display: none; }
body.initial .meta { display: none; }
body.initial .topbar { padding-bottom: 10px; }

/* float the wrap (input + lang btn together) in initial mode */
body.initial .search-wrap {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 40px));
  width: min(620px, 92vw);
}
body.initial .search {
  font-size: clamp(20px, 4.5vw, 26px);
  padding: 22px 24px;
  padding-right: 72px;
  border-width: 6px;
  box-shadow: 14px 14px 0 0 var(--ink);
  animation: pulse-orange 1s ease-in-out infinite;
}
body.initial .search:focus {
  background: var(--yellow);
  box-shadow: 16px 16px 0 0 var(--ink);
  transform: translate(-2px, -2px);
  animation: none;
}
@keyframes pulse-orange {
  0%, 100% { background: #fff; }
  50% { background: #ffd9a8; }
}

/* transition flash — flash the search input itself, not the whole screen */
.search.flashing {
  animation: flashSearchBg 220ms steps(4) 1;
}
@keyframes flashSearchBg {
  0%, 50%, 100% { background: #fff; }
  25%, 75%     { background: #d62828; color: #fff; }
}

.meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 700 12px/1 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  white-space: nowrap;
}
.meta .ghost { color: var(--ink); text-decoration: none; padding: 4px 7px; border: 2px solid var(--ink); }
.meta .ghost:hover, .meta .ghost:focus-visible { background: var(--yellow); outline: none; }

/* mobile: anchor the floating search at a fixed distance from the top
   instead of centering vertically. Otherwise iOS shifts it when the
   software keyboard opens, sometimes off-screen entirely. */
@media (max-width: 719px) {
  body.initial .search-wrap {
    top: 180px;
    transform: translateX(-50%);
  }
  /* keep the topbar's search stable on iOS — don't lift on focus */
  .search:focus { transform: none; }
  body.initial .search:focus { transform: none; }

  /* iOS Safari quirk: position: sticky lives in LAYOUT viewport coords,
     so it appears to shift when the URL bar expands/collapses (the
     visual viewport changes but layout doesn't). Switching to fixed +
     spacer keeps the topbar anchored to the visible top of the screen. */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }
  .topbar-spacer {
    height: var(--topbar-h, 86px);
  }
}
.topbar-spacer { display: none; }
@media (max-width: 719px) {
  .topbar-spacer { display: block; }
}

/* tablet+ → brand | search | meta inline */
@media (min-width: 720px) {
  .topbar {
    padding: 16px 22px;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand search meta";
    gap: 18px;
    align-items: center;
  }
  .brand h1 { font-size: clamp(28px, 4vw, 42px); }
  .brand .tag { font-size: 11px; }
  body.initial .search-skeleton { height: 52px; }
}

/* ===== grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: var(--gap);
  padding: 14px;
  align-content: start;
  min-height: 200px;
}
@media (min-width: 720px) { .grid { padding: 22px; gap: 10px; } }

#sentinel { height: 1px; }

/* ===== tile ===== */
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-radius: 0;
  overflow: hidden;
  transition: transform 90ms ease;
  -webkit-tap-highlight-color: transparent;
}
.tile:focus { outline: none; }
.tile:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; z-index: 2; }
.tile:hover { transform: translateY(-2px); }

.glyph {
  font-size: calc(var(--tile) * 0.5);
  line-height: 1;
  font-family:
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji",
    "Twemoji Mozilla", "EmojiOne Color", "Android Emoji",
    system-ui, sans-serif;
  user-select: none;
  pointer-events: none;
}

/* ===== actions ===== */
.actions {
  position: absolute;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
}
.act {
  font: 800 10px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 8px 4px;
  background: var(--ink);
  color: var(--paper);
  pointer-events: auto;
  border-right: 1px solid #2a2a2a;
  user-select: none;
}
.act:last-child { border-right: 0; }

/* desktop / mouse: actions hidden until hover */
@media (hover: hover) and (pointer: fine) {
  .actions { transform: translateY(100%); transition: transform 110ms ease; }
  .tile:hover .actions, .tile:focus-visible .actions { transform: translateY(0); }
}
/* touch: hide tile action bar entirely. Tap on a tile still copies. */
@media (hover: none), (pointer: coarse) {
  .actions { display: none; }
}

.act:hover, .act:focus-visible { background: var(--yellow); color: var(--ink); outline: none; }
.act:active { background: var(--yellow); color: var(--ink); }

/* ===== empty + loading + toast ===== */
.empty {
  padding: 60px 22px;
  text-align: center;
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(24px, 4.5vw, 48px);
  line-height: 1;
  letter-spacing: -0.02em;
}
.empty .sub {
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  margin-top: 16px;
}

/* (the full-screen .flash overlay was removed — flash is now on .search itself) */
.flash { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font: 800 13px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.12em;
  padding: 14px 20px;
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 0 var(--yellow);
  z-index: 20;
  animation: pop 1.6s ease forwards;
  max-width: calc(100vw - 32px);
  word-break: break-all;
}
@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%, 10px); }
  10%  { opacity: 1; transform: translate(-50%, 0); }
  85%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 6px); }
}

/* ===== footer ===== */
.foot {
  padding: 28px 22px calc(44px + env(safe-area-inset-bottom));
  border-top: 4px solid var(--ink);
  margin-top: 32px;
  background: var(--paper);
  font-size: 13px;
  line-height: 1.5;
}
.foot p { margin: 0 auto 10px; max-width: 720px; }
.foot .src { font-weight: 700; letter-spacing: 0.04em; opacity: 0.7; font-size: 12px; }
.foot a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.foot a:hover { background: var(--yellow); }

/* ===== demo mode (?demo=1) ===== */
/* Grow every tile 1.5× while in demo so the cycling grid is easier to read
   in screen recordings / shared screenshots. Everything that's anchored to
   --tile (grid columns, glyph font-size, the centre overlay) scales with it. */
body.demo-mode { --tile: clamp(108px, 33vw, 186px); }

.demo-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.demo-stage {
  display: flex;
  align-items: center;
  justify-content: center;
}
.demo-emoji {
  /* Sized off the *base* (non-demo) tile clamp so the centre overlay stays
     the same physical size whether or not demo mode is scaling --tile. */
  width: calc(clamp(72px, 22vw, 124px) * 2.8);
  height: calc(clamp(72px, 22vw, 124px) * 2.8);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 4px solid var(--ink);
  border-left-width: 6px;
  border-bottom-width: 6px;
  box-shadow: -12px 12px 0 0 var(--ink);
  font-family: "Archivo Black", "Inter", system-ui, sans-serif;
  font-size: calc(clamp(72px, 22vw, 124px) * 1.8);
  line-height: 1;
  color: var(--ink);
  transform-origin: center;
  padding: 14%;
  overflow: hidden;
}
/* The Twemoji SVG fills the inner space; padding gives the box breathing room. */
.demo-emoji-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  /* image-rendering hint helps some browsers keep SVG strokes sharp */
  image-rendering: -webkit-optimize-contrast;
}
.demo-emoji.bounce {
  animation: demo-bounce 360ms cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes demo-bounce {
  0%   { transform: scale(.86); }
  55%  { transform: scale(1.12); }
  100% { transform: scale(1.00); }
}
@media (max-width: 600px) {
  .demo-emoji { box-shadow: -8px 8px 0 0 var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ── cross-promo: fixed bottom strip linking the rest of the suite ── */
body { padding-bottom: 52px; }
.suite-strip { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; padding: 9px 14px; background: var(--paper, #faf6ec); border-top: 3px solid var(--ink, #1a1a1a); }
.suite-strip .suite-lbl { font-size: .6rem; text-transform: uppercase; letter-spacing: .1em; opacity: .6; }
.suite-strip a { font-size: .74rem; font-weight: 700; text-decoration: none; color: var(--ink, #1a1a1a); border: 1px solid var(--ink, #1a1a1a); border-radius: 2px; padding: 3px 9px; }
.suite-strip a:hover { background: var(--accent, #c4513a); border-color: var(--accent, #c4513a); color: #fff; }
