:root {
  --bg: #050505;
  --fg: #f2f2f0;
  --muted: #8a8a86;
  --line: #2a2a28;
  --accent: #e8e4dc;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  /* Impact first; Anton is the cross-platform condensed fallback. */
  --brand-font: Impact, Haettenschweiler, Anton, "Arial Narrow Bold", "Franklin Gothic Bold", sans-serif;
  --dock-size: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  /*
   * Shared design world is 1200×800. --s = screen pixels per world pixel
   * (fit × camera). All stage metrics are world units × --s so every
   * viewport shows the same composition.
   */
  --s: 1;
}

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

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100%;
  min-height: 100dvh;
  height: 100%;
  height: 100dvh;
  color: var(--fg);
  font-family: "IBM Plex Sans", sans-serif;
  background: var(--bg);
  overflow: hidden;
  touch-action: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Viewport frame — letterboxing shows as this black; never CSS-scaled. */
.world {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
  background: var(--bg);
}

/* World-space backdrop — sized/positioned by JS to the shared world rect. */
.world-bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 1200px;
  height: 800px;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 35%, rgba(255, 255, 255, 0.035), transparent 55%),
    radial-gradient(80% 60% at 50% 100%, rgba(255, 255, 255, 0.02), transparent 50%),
    var(--bg);
}

.world-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: calc(180px * var(--s));
  mix-blend-mode: soft-light;
}

/* Canvas fills the viewport; world→screen via 2D context transform. */
.draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  touch-action: none;
  cursor: crosshair;
}

body.draw-active {
  cursor: crosshair;
}

body.draw-active.tool-eraser {
  cursor: cell;
}

body.draw-active .draw-canvas {
  pointer-events: auto;
}

/*
 * Stage = shared 1200×800 world UI. JS sets left/top/width/height and --s.
 * No per-breakpoint repositioning — mobile just sees a smaller fit of the
 * same composition.
 */
.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1200px;
  height: 800px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(48px * var(--s)) calc(56px * var(--s)) calc(72px * var(--s));
  text-align: center;
  gap: calc(14px * var(--s));
  pointer-events: none;
}

.welcome {
  margin: 0;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: calc(15px * var(--s));
  font-weight: 400;
  letter-spacing: 0.22em;
  text-transform: lowercase;
  color: var(--muted);
  opacity: 0;
  transform: translateY(10px);
  animation: rise-in 900ms var(--ease) 40ms forwards;
}

.brand {
  margin: 0;
  font-family: var(--brand-font);
  font-weight: 400;
  font-style: normal;
  /* ~156 world-px → ~42px on 320-wide phones; larger on desktop fit. */
  font-size: calc(156px * var(--s));
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--fg);
  text-transform: none;
  white-space: nowrap;
  max-width: 100%;
  opacity: 0;
  transform: translateY(12px);
  animation: rise-in 900ms var(--ease) 120ms forwards;
}

.tagline {
  margin: calc(8px * var(--s)) 0 0;
  font-size: calc(18px * var(--s));
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--muted);
  opacity: 0;
  transform: translateY(10px);
  animation: rise-in 900ms var(--ease) 240ms forwards;
}

.actions {
  /* Always column — wrapping to a different arrangement on narrow fits
     would shift the button in world space across devices. */
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: calc(16px * var(--s));
  margin-top: calc(28px * var(--s));
  opacity: 0;
  transform: translateY(10px);
  animation: rise-in 900ms var(--ease) 360ms forwards;
}

.click-btn,
.tool-btn {
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.click-btn {
  appearance: none;
  border: calc(1.5px * var(--s)) solid var(--line);
  background: transparent;
  color: var(--accent);
  font-family: "IBM Plex Sans", sans-serif;
  font-size: calc(16px * var(--s));
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: calc(14px * var(--s)) calc(26px * var(--s));
  border-radius: calc(2px * var(--s));
  cursor: pointer;
  min-height: calc(48px * var(--s));
  min-width: calc(120px * var(--s));
  transition:
    background 180ms var(--ease),
    border-color 180ms var(--ease),
    color 180ms var(--ease),
    transform 180ms var(--ease);
}

.click-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: #4a4a46;
}

.click-btn:active {
  transform: scale(0.97);
}

.click-btn:focus-visible,
.tool-btn:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

.click-btn.is-pressed {
  animation: tap 220ms var(--ease);
}

.counter {
  margin: 0;
  font-size: calc(17px * var(--s));
  color: var(--muted);
  letter-spacing: 0.01em;
  line-height: 1.4;
  max-width: calc(420px * var(--s));
  text-align: center;
}

#count {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  display: inline-block;
  min-width: 1ch;
  transition: transform 180ms var(--ease), color 180ms var(--ease);
}

#count.bump {
  animation: count-bump 280ms var(--ease);
}

/* Tool dock: screen-fixed (not part of the shared world). */
.tool-dock {
  position: fixed;
  z-index: 10;
  right: max(0.85rem, var(--safe-right));
  bottom: max(0.85rem, var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem;
  opacity: 0;
  animation: rise-in 900ms var(--ease) 420ms forwards;
  touch-action: manipulation;
}

.tool-btn {
  width: var(--dock-size);
  height: var(--dock-size);
  display: grid;
  place-items: center;
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.78);
  color: var(--muted);
  border-radius: 2px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition:
    background 180ms var(--ease),
    border-color 180ms var(--ease),
    color 180ms var(--ease);
}

.tool-btn:hover {
  color: var(--accent);
  border-color: #4a4a46;
  background: rgba(12, 12, 12, 0.85);
}

.tool-btn[aria-pressed="true"] {
  color: var(--fg);
  border-color: #6a6a64;
  background: rgba(255, 255, 255, 0.06);
}

.tool-icon {
  display: block;
}

@keyframes rise-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tap {
  0% { transform: scale(1); }
  40% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

@keyframes count-bump {
  0% { transform: translateY(0); }
  35% { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

/* Touch dock sizing only — does not move world content. */
@media (max-width: 520px) {
  :root {
    --dock-size: 52px;
  }

  .tool-dock {
    right: max(0.75rem, var(--safe-right));
    bottom: max(0.75rem, var(--safe-bottom));
    gap: 0.45rem;
  }

  .tool-icon {
    width: 22px;
    height: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .welcome,
  .brand,
  .tagline,
  .actions,
  .tool-dock,
  .click-btn,
  #count {
    animation: none !important;
    transition: none !important;
    opacity: 1;
    transform: none;
  }
}
