/* AI Level Architect - graffiti-tagger platformer. Uses the sitewide tokens. */

.ar-tagline { max-width: 52ch; }
.ar-p0-note { color: var(--muted-2); font-size: 0.9em; }

.ar-app {
  max-width: 720px;
  margin: 0 auto;
  /* nothing in the play area should ever be selectable - a long-press on a
     control was popping the iOS text-selection callout (Copy / Look Up ...). */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* keep scroll + pinch, but drop the double-tap-to-zoom gesture over the game
     (canvas/stage/buttons use the stronger touch-action:none for their own touches). */
  touch-action: manipulation;
}

/* -- HUD -- */
.ar-hud {
  display: flex;
  justify-content: center;
  gap: clamp(0.9rem, 4.5vw, 1.75rem);
  margin: 1rem 0 0.75rem;
}
.ar-life-flash { animation: ar-life-pulse 0.45s ease-in-out 2; }
@keyframes ar-life-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); filter: drop-shadow(0 0 7px var(--spray-mint)); }
}

/* sound toggle, tucked in the stage corner */
.ar-mute {
  position: absolute; top: 6px; right: 6px; z-index: 3;
  width: 2rem; height: 2rem; padding: 0; line-height: 1;
  border: 1px solid var(--line-strong); border-radius: 50%;
  background: rgba(10, 9, 16, 0.5); color: var(--paper); font-size: 0.95rem;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.ar-mute:active { transform: scale(0.94); }
@media (hover: hover) { .ar-mute:hover { background: rgba(10, 9, 16, 0.75); } }
.ar-stat { display: flex; flex-direction: column; align-items: center; }
.ar-stat-num {
  font-family: var(--font-display);
  font-size: 1.5rem;
  background: var(--graffiti-gradient);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
}
.ar-stat-label {
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-2);
}

/* -- stage -- */
.ar-stage {
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius, 12px);
  overflow: hidden;
  background: var(--ink);
  touch-action: none; /* the game handles all touch; never scroll/zoom the page here */
}
.ar-canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  position: relative;
  z-index: 1; /* the 2D game sits above the WebGL atmosphere, which shows through its transparent sky */
}
.ar-gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* -- overlays (start / win) -- */
.ar-overlay {
  position: absolute;
  inset: 0;
  z-index: 3; /* above the game canvas (z-index 1) so the input/buttons are clickable */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 9, 16, 0.72);
  backdrop-filter: blur(2px);
}
.ar-overlay[hidden] { display: none; }
.ar-overlay-card {
  text-align: center;
  max-width: 26rem;
}
.ar-overlay-title {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  color: var(--paper);
  margin: 0 0 0.5rem;
}
.ar-overlay-line {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 auto 1.1rem;
}
.ar-overlay-score {
  font-family: var(--font-display);
  color: var(--spray-yellow);
  font-variant-numeric: tabular-nums;
  margin: 0 auto 1.1rem;
  line-height: 1.6;
}
.ar-overlay-score[hidden] { display: none; }

.ar-highline {
  margin: 0 auto 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.ar-highline[hidden] { display: none; }
.ar-highline strong { color: var(--spray-yellow); font-variant-numeric: tabular-nums; }
.ar-initials {
  margin: 0 auto 0.85rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid rgba(255, 210, 63, 0.4);
  border-radius: var(--radius, 12px);
  max-width: 22rem;
}
.ar-initials[hidden] { display: none; }
.ar-initials-label { display: block; font-size: 0.82rem; color: var(--spray-yellow); margin-bottom: 0.45rem; }
.ar-initials-row { display: flex; gap: 0.5rem; justify-content: center; }
.ar-initials-input {
  width: 5.5rem;
  font-family: var(--font-display);
  font-size: 16px; /* >= 16px so iOS doesn't zoom on focus */
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius, 12px);
  color: var(--paper);
  padding: 0.3rem 0.5rem;
}

.ar-build-form {
  display: flex;
  flex-direction: column; /* input on its own full-width row, Build button below it */
  gap: 0.55rem;
  margin: 0 auto 0.85rem;
  max-width: 30rem;
}
.ar-build-form .ar-build { width: 100%; }
.ar-theme-input {
  width: 100%;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius, 12px);
  color: var(--paper);
  padding: 0.5rem 0.85rem;
  /* MUST stay >= 16px: iOS Safari auto-zooms the whole page when you focus an
     input with a smaller font, which zoomed the game into an unusable view. */
  font-size: 16px;
}
.ar-theme-input::placeholder { color: var(--muted-2); }
.ar-overlay-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}
.ar-status {
  margin: 0.75rem 0 0;
  min-height: 1.1em;
  font-size: 0.85rem;
  color: var(--spray-yellow);
}
.ar-status[hidden] { display: none; }

/* -- generation splash (shown while the AI builds a level) -- */
.ar-splash {
  position: absolute;
  inset: 0;
  z-index: 4; /* above the overlay */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 1.5rem;
  background: rgba(10, 9, 16, 0.82);
  backdrop-filter: blur(3px);
}
.ar-splash[hidden] { display: none; }
.ar-blocks {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 62px;
}
.ar-blocks span {
  width: 12px;
  height: 18px;
  border-radius: 3px 3px 0 0;
  background: var(--graffiti-gradient);
  background-size: 100% 320%;
  box-shadow: 0 0 10px rgba(47, 209, 255, 0.35);
  animation: ar-rise 1.05s ease-in-out infinite;
}
.ar-blocks span:nth-child(2) { animation-delay: 0.12s; }
.ar-blocks span:nth-child(3) { animation-delay: 0.24s; }
.ar-blocks span:nth-child(4) { animation-delay: 0.36s; }
.ar-blocks span:nth-child(5) { animation-delay: 0.48s; }
.ar-blocks span:nth-child(6) { animation-delay: 0.60s; }
.ar-blocks span:nth-child(7) { animation-delay: 0.72s; }
@keyframes ar-rise {
  0%, 100% { height: 18px; background-position: 0 100%; opacity: 0.55; }
  50% { height: 58px; background-position: 0 0; opacity: 1; }
}
.ar-splash-title {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: clamp(1.25rem, 6vw, 1.9rem);
  margin: 0;
  text-align: center;
  max-width: 100%;
  overflow-wrap: break-word;
  text-wrap: balance;
  background: var(--graffiti-gradient);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: ar-shimmer 3.5s linear infinite;
}
@keyframes ar-shimmer { to { background-position: 220% center; } }
.ar-splash-msg {
  margin: 0;
  min-height: 1.3em;
  color: var(--muted);
  font-size: 0.9rem;
}
.ar-progress {
  width: min(82%, 22rem);
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.ar-progress-bar {
  height: 100%;
  width: 6%;
  border-radius: 999px;
  background: var(--graffiti-gradient);
  background-size: 220% auto;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
  transition: width 0.15s linear;
  animation: ar-shimmer 2.5s linear infinite;
}
.ar-splash-clear {
  margin: -0.3rem 0 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--spray-mint);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.ar-splash-clear[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) {
  .ar-blocks span, .ar-splash-title, .ar-progress-bar { animation: none; }
}

/* -- how to play & scoring modal -- */
.ar-help {
  position: absolute;
  inset: 0;
  z-index: 6; /* above the start overlay and the build splash */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 9, 16, 0.82);
  backdrop-filter: blur(3px);
}
.ar-help[hidden] { display: none; }
.ar-help-card {
  position: relative;
  width: min(30rem, 100%);
  max-height: 100%;
  overflow-y: auto;
  text-align: left;
  padding: 1.4rem 1.5rem 1.5rem;
  border-radius: 0.9rem;
  background: linear-gradient(180deg, var(--surface-2, #16121f), var(--surface, #0f0c16));
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px -16px rgba(0, 0, 0, 0.7);
}
.ar-help-close {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 0.4rem;
}
.ar-help-close:hover, .ar-help-close:focus-visible { color: var(--paper); background: rgba(255, 255, 255, 0.08); }
.ar-help-title {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
  background: var(--graffiti-gradient);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ar-help-intro { color: var(--muted); line-height: 1.5; font-size: 0.9rem; margin: 0 0 1rem; }
.ar-help-h {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  color: var(--spray-yellow);
  margin: 1.1rem 0 0.5rem;
}
.ar-help-list { margin: 0; padding-left: 1.1rem; color: var(--paper); line-height: 1.65; font-size: 0.9rem; }
.ar-help-list li { margin-bottom: 0.2rem; }
.ar-help-list strong { color: var(--spray-mint); }
.ar-kbd {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0.05rem 0.35rem;
  text-align: center;
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--paper);
  background: var(--surface-2, #1b1626);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 0.3rem;
}
.ar-help-score {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  color: var(--paper);
}
.ar-help-score td { padding: 0.3rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.ar-help-score td:last-child { text-align: right; white-space: nowrap; color: var(--spray-yellow); font-variant-numeric: tabular-nums; }
.ar-help-note { color: var(--muted); font-size: 0.8rem; line-height: 1.5; margin: 0.5rem 0 0; }
.ar-help-note.ar-help-speed { color: var(--spray-mint); }
.ar-help-score .ar-help-note { display: block; color: var(--muted); font-size: 0.72rem; margin: 0.1rem 0 0; }

/* -- touch controls -- */
/* a bar BELOW the game canvas - keeps the controls out of the play area entirely */
.ar-touch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  max-width: 560px;
  margin: 0.6rem auto 0;
  padding: 0 0.4rem;
}
.ar-touch[hidden] { display: none; }
.ar-touch-left { display: flex; gap: 0.5rem; }
/* The <button> itself is the (generous, invisible) tap target; the visible ring
   is a smaller ::before centred inside it. So a near-miss around the ring still
   registers - the whole square is clickable, not just the circle you see. */
.ar-btn {
  pointer-events: auto;
  width: 6.75rem;
  height: 6.75rem;
  padding: 0;
  border: none;
  background: transparent;
  color: rgba(243, 239, 230, 0.92);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  font-size: 1.55rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* block the long-press selection menu */
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.ar-btn::before { /* the visible ring - smaller than the tap target */
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 4.4rem;
  height: 4.4rem;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  pointer-events: none;
}
.ar-btn:active::before { background: rgba(47, 209, 255, 0.28); border-color: var(--spray-cyan); }
.ar-btn::after { /* invisible tap halo - extends the clickable area past the ring so
   a near-miss in the empty space around the circle still registers. Absolutely
   positioned (out of flow) so it never moves the ring or changes the layout. */
  content: "";
  position: absolute;
  inset: -0.6rem;
  border-radius: 50%;
  pointer-events: auto;
}
.ar-btn-jump { width: 8.25rem; height: 8.25rem; font-size: 1.85rem; }
.ar-btn-jump::before { width: 5.6rem; height: 5.6rem; border-color: rgba(43, 232, 154, 0.6); }
.ar-btn-jump:active::before { background: rgba(43, 232, 154, 0.22); border-color: var(--spray-mint); }
/* spray/paint button - only shown in boss arenas (the pink one) */
.ar-touch-right { display: flex; align-items: center; gap: 0.4rem; }
.ar-btn-spray[hidden] { display: none; }
.ar-btn-spray::before { border-color: rgba(255, 47, 126, 0.6); }
.ar-btn-spray:active::before { background: rgba(255, 47, 126, 0.25); border-color: var(--spray-pink); }
.ar-btn-spray .ar-arrow { fill: var(--spray-pink); }
/* SVG arrows: the path centroid sits at the viewBox centre, so they're optically
   centred in the ring (the old Unicode triangle glyphs weren't). */
.ar-arrow {
  width: 1.55rem;
  height: 1.55rem;
  display: block;
  fill: currentColor;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
  pointer-events: none;
}
.ar-btn-jump .ar-arrow { width: 1.9rem; height: 1.9rem; }

/* desktop with a precise pointer plays with the keyboard - hide the touch pad */
@media (hover: hover) and (pointer: fine) {
  .ar-touch { display: none !important; }
}

.ar-controls-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted-2);
  margin: 0.75rem 0 0;
}
/* on touch devices the on-screen pad is enough - drop the keyboard hint */
@media (hover: none), (pointer: coarse) {
  .ar-controls-hint { display: none; }
}

/* -- landscape on a phone: fit the whole game in the short viewport -- */
/* In portrait the canvas is sized by WIDTH; rotated to a short landscape screen
   that makes it taller than the viewport, pushing the controls off-screen. Here we
   size the stage by HEIGHT (so the canvas fits vertically) and overlay the touch
   pad on the bottom corners - the only place for it when there's no room below. */
@media (orientation: landscape) and (pointer: coarse) and (max-height: 600px) {
  /* reclaim vertical space for the play area */
  .section-heading, .ar-tagline, .ar-controls-hint { display: none; }
  .ar-hud { margin: 0.3rem 0 0.35rem; gap: 1.3rem; }
  .ar-stat-num { font-size: 1.15rem; }
  .ar-stat-label { font-size: 0.55rem; }

  .ar-app { max-width: none; }
  .ar-stage {
    height: calc(100dvh - 84px);   /* room for the site nav + the compact HUD */
    aspect-ratio: 16 / 11;         /* matches the 384x264 canvas exactly */
    width: auto;
    max-width: 100%;
    margin: 0 auto;
  }
  .ar-canvas { width: 100%; height: 100%; }

  /* the start / win / build overlays: scroll internally if the form is tall */
  .ar-overlay { align-items: flex-start; overflow-y: auto; padding: 0.6rem; }
  .ar-overlay-card { margin: auto; }
  .ar-overlay-title { font-size: clamp(1.2rem, 5vw, 1.7rem); }

  /* On-screen pad, lifted UP and IN from the screen corners so it clears the phone's
     home-indicator / browser gesture zone (where taps get swallowed) and sits under
     the thumbs. Filled, higher-contrast rings so it's unmistakably there and tappable
     - the faint outline-only version was easy to miss against the game. */
  .ar-touch {
    position: fixed;
    left: 0; right: 0;
    bottom: max(1.4rem, env(safe-area-inset-bottom));
    max-width: none;
    margin: 0;
    padding: 0 clamp(1rem, 4vw, 2.75rem);
    pointer-events: none;   /* only the buttons catch touches, not the whole bar */
    z-index: 40;
  }
  .ar-touch-left, .ar-touch-right { pointer-events: none; }
  .ar-btn { pointer-events: auto; width: 5.5rem; height: 5.5rem; }
  .ar-btn::before {
    width: 3.9rem; height: 3.9rem;
    background: rgba(16, 14, 24, 0.5);
    border-color: rgba(255, 255, 255, 0.55);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  }
  .ar-btn:active::before { background: rgba(47, 209, 255, 0.42); border-color: var(--spray-cyan); }
  .ar-btn-jump { width: 6.5rem; height: 6.5rem; }
  .ar-btn-jump::before { width: 4.6rem; height: 4.6rem; background: rgba(43, 232, 154, 0.3); border-color: var(--spray-mint); }
  .ar-btn-jump:active::before { background: rgba(43, 232, 154, 0.5); }

  /* boss fight: spray + jump both live on the right. Side-by-side crowds the corner
     and stacks two actions under one thumb, so stack them vertically instead -
     jump (primary) stays at the corner thumb-rest, spray sits clearly above it
     (DOM order is spray,jump so plain column puts jump on the bottom). */
  .ar-touch-right { flex-direction: column; gap: 0.7rem; align-items: center; }
  .ar-btn-spray::before { background: rgba(255, 47, 126, 0.28); border-color: var(--spray-pink); }
  .ar-btn-spray:active::before { background: rgba(255, 47, 126, 0.5); }
}
