:root {
  --ink: #2B2B2B;
  --cream: #F5EEDC;
  --yellow: #F2C94C;
  --sky: #BFE3F2;
  --glow: 0;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8CC47A; color: var(--ink);
  overscroll-behavior: none;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Map ------------------------------------------------------------ */
#viewport {
  position: fixed; inset: 0; z-index: 1; overflow: hidden; touch-action: none;
  cursor: grab; user-select: none; -webkit-user-select: none;
}
#viewport:active { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; width: 1800px; height: 1600px; transform-origin: 0 0; }
#world svg { display: block; }
#world [data-kind] { cursor: pointer; }
.plot:hover > rect:first-child { fill-opacity: .9; }
#g-tags, #g-clouds, #g-hl { pointer-events: none; }

.glow { opacity: var(--glow); }
.halo { opacity: calc(var(--glow) * .6); }

.pnum { font: 800 8px 'Nunito', sans-serif; fill: #3d6b34; opacity: 0; transition: opacity .2s; }
#world[data-num="on"] .pnum { opacity: .9; }

.tag { opacity: 0; transition: opacity .25s; }
.tag text { font-family: 'Caveat', 'Segoe Print', cursive; font-weight: 700; fill: var(--ink); }
#world[data-zoom="in"] .tag, .tag.always { opacity: 1; }

.smoke circle { opacity: 0; fill: #fff; transform-box: fill-box; transform-origin: center; animation: puff 5s linear infinite; }
.smoke circle:nth-child(2) { animation-delay: 1.7s; }
.smoke circle:nth-child(3) { animation-delay: 3.4s; }
@keyframes puff {
  0% { opacity: 0; transform: translate(0, 0) scale(.6); }
  20% { opacity: .75; }
  100% { opacity: 0; transform: translate(6px, -18px) scale(1.7); }
}

.hop { transform-box: fill-box; animation: hop 2.8s ease-in-out infinite; }
@keyframes hop {
  0%, 62%, 100% { transform: translateY(0); }
  70% { transform: translateY(-5px); }
  78% { transform: translateY(0); }
  85% { transform: translateY(-3px); }
}

.wave { fill: none; stroke: #fff; stroke-width: 1.4; stroke-linecap: round; opacity: .55; animation: twinkle 4s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .15; } 50% { opacity: .7; } }

.ring {
  fill: none; stroke: var(--yellow); stroke-width: 4; transform-box: fill-box; transform-origin: center;
  animation: ring 1.2s ease-out infinite;
}
@keyframes ring { 0% { transform: scale(.5); opacity: 1; } 100% { transform: scale(1.7); opacity: 0; } }

/* Light and texture -------------------------------------------- */
#tint { position: fixed; inset: 0; z-index: 2; pointer-events: none; mix-blend-mode: multiply; background: transparent; transition: background 1s; }
#grain {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: .09; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .28 0 0 0 0 .2 0 0 0 1.3 -.25'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Interface ------------------------------------------------------ */
#topbar {
  position: fixed; z-index: 10; left: 12px; right: 12px;
  top: calc(10px + env(safe-area-inset-top));
  display: flex; justify-content: space-between; align-items: center; gap: 10px; pointer-events: none;
}
#brand, #counter {
  border: 2px solid var(--ink); border-radius: 999px; box-shadow: 0 3px 0 rgba(43,43,43,.18);
}
#brand {
  background: var(--cream); padding: 0 18px; line-height: 1.15;
  font-family: 'Caveat', 'Segoe Print', cursive; font-weight: 700; font-size: 30px;
}
#counter { background: var(--yellow); padding: 7px 14px; font-weight: 800; font-size: 14px; white-space: nowrap; }
#counter b { font-size: 16px; }

#search {
  position: fixed; z-index: 11; left: 50%; transform: translateX(-50%);
  top: calc(62px + env(safe-area-inset-top)); width: min(440px, calc(100% - 24px));
}
#q {
  width: 100%; height: 46px; border: 2px solid var(--ink); border-radius: 999px; background: var(--cream);
  padding: 0 16px 0 44px; font: 700 16px 'Nunito', sans-serif; color: var(--ink); outline: none;
  box-shadow: 0 3px 0 rgba(43,43,43,.18);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%232B2B2B' stroke-width='3' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M16 16l5 5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 15px center;
  appearance: none; -webkit-appearance: none;
}
#q:focus { border-color: #B98A00; box-shadow: 0 0 0 3px rgba(242,201,76,.55); }
#q::placeholder { color: #8b8574; font-weight: 700; }
#results {
  list-style: none; margin: 8px 0 0; padding: 4px; background: var(--cream); border: 2px solid var(--ink);
  border-radius: 20px; box-shadow: 0 3px 0 rgba(43,43,43,.18);
}
#results[hidden], #card[hidden], #cardCta[hidden] { display: none; }
#results button {
  width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 14px; cursor: pointer;
  display: flex; flex-direction: column; font-family: inherit; color: var(--ink);
}
#results button:hover, #results button:focus-visible { background: rgba(242,201,76,.35); outline: none; }
#results strong { font-size: 15px; }
#results span { font-size: 13px; color: #6d6757; font-weight: 700; }
#results .none { padding: 10px 12px; font-size: 14px; font-weight: 700; color: #6d6757; }

#controls {
  position: fixed; z-index: 10; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
#controls button {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ink); background: var(--cream);
  font: 800 22px/1 'Nunito', sans-serif; color: var(--ink); cursor: pointer; box-shadow: 0 3px 0 rgba(43,43,43,.18);
}
#controls button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(43,43,43,.18); }
#controls #timeBtn { font-size: 11px; background: var(--yellow); line-height: 1.1; padding: 0; }

#hint {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%); margin: 0;
  bottom: calc(18px + env(safe-area-inset-bottom)); padding: 7px 16px; border-radius: 999px;
  background: rgba(245,238,220,.92); border: 2px solid var(--ink); font-weight: 800; font-size: 13px;
  transition: opacity .6s; pointer-events: none; white-space: nowrap;
}
#hint.gone { opacity: 0; }

#card {
  position: fixed; z-index: 12; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom)); width: min(440px, calc(100% - 24px));
  background: var(--cream); border: 2px solid var(--ink); border-radius: 24px; padding: 16px 20px 18px;
  box-shadow: 0 4px 0 rgba(43,43,43,.2);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
#card h2 { margin: 0 34px 2px 0; font-size: 21px; font-weight: 800; }
#card p { margin: 4px 0 0; font-size: 15px; line-height: 1.4; font-weight: 600; }
#cardSub { color: #6d6757; font-weight: 700 !important; }
#closeCard {
  position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--ink);
  background: #fff; font: 800 20px/1 'Nunito', sans-serif; cursor: pointer; color: var(--ink);
}
.btn {
  display: inline-block; margin-top: 12px; padding: 10px 20px; border: 2px solid var(--ink); border-radius: 999px;
  background: var(--yellow); color: var(--ink); font-weight: 800; font-size: 15px; text-decoration: none;
  box-shadow: 0 3px 0 rgba(43,43,43,.2);
}
.btn.off { background: #e4ddc8; color: #7a745f; pointer-events: none; box-shadow: none; }

@media (min-width: 700px) {
  #brand { font-size: 34px; }
  #counter { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .smoke circle, .hop, .wave, .ring { animation: none; }
}
