/* ============================================================================
   SANDFALL — dark obsidian glass laboratory
   Owned by the UI agent. Class names must match js/ui/hud.js.
   ========================================================================== */

:root {
  /* Palette */
  --bg-0: #05060a;          /* deepest blue-black */
  --bg-1: #07070c;          /* stage surround */
  --glass: rgba(14, 15, 22, 0.62);
  --glass-solid: #0d0e15;
  --glass-hi: rgba(255, 205, 150, 0.14);   /* warm 1px border light */
  --glass-hi-soft: rgba(255, 205, 150, 0.07);
  --ink: #eef1f6;
  --ink-dim: #8b90a0;
  --ink-faint: rgba(190, 196, 210, 0.42);

  --amber: #ff9a3c;         /* molten ember accent */
  --amber-hot: #ffbe6a;
  --amber-deep: #d9711d;
  --coral: #ff5a4d;         /* danger */
  --coral-deep: #c9342b;

  --amber-glow: rgba(255, 154, 60, 0.55);
  --amber-ring: rgba(255, 154, 60, 0.9);

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  --font-display: 'Unbounded', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* safe-area shorthands */
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
}

/* Fine grain / noise overlay reused on panels via ::before */
/* (tiny repeating SVG data-URI of soft noise dots) */
:root {
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font-mono);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

body {
  /* 100dvh survives iPad Safari toolbar resize; fallback to vh */
  height: 100vh;
  height: 100dvh;
  position: fixed;
  inset: 0;
}

/* ------------------------------------------------------------------ Stage */
#stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* deep blue-black surround with faint radial ember glow behind canvas */
  background:
    radial-gradient(60% 55% at 50% 46%, rgba(255, 120, 40, 0.11), rgba(255, 120, 40, 0) 62%),
    radial-gradient(120% 120% at 50% 120%, #0a0b12 0%, var(--bg-0) 70%);
  overflow: hidden;
  z-index: 0;
}

#game-canvas {
  /* Letterboxed 16:9, centered. Fits within viewport keeping aspect. */
  width: min(100vw, calc((100dvh) * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  max-width: 100vw;
  max-height: 100dvh;
  aspect-ratio: 16 / 9;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: #05060a;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 205, 150, 0.05),
    0 24px 80px -30px rgba(0, 0, 0, 0.9),
    0 0 120px -40px rgba(255, 120, 40, 0.28);
}

/* ============================================================== HUD ROOT */
#hud-root {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;           /* only children opt back in */
}
#hud-root > * { pointer-events: auto; }

/* Shared glass panel treatment */
.glass {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--glass-hi);
  box-shadow:
    0 10px 40px -18px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 var(--glass-hi-soft);
  overflow: hidden;
}
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  background-size: 120px 120px;
  opacity: 0.04;
  pointer-events: none;
  mix-blend-mode: overlay;
}

/* --------------------------------------------------------- FPS readout */
.fps {
  position: absolute;
  top: calc(10px + var(--sa-t));
  left: calc(12px + var(--sa-l));
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  opacity: 0.7;
  pointer-events: none;
  z-index: 12;
}
.fps b { color: var(--amber); font-weight: 500; opacity: 0.85; }

/* --------------------------------------------------- Top-right controls */
.controls {
  position: absolute;
  top: calc(12px + var(--sa-t));
  right: calc(12px + var(--sa-r));
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: var(--r-md);
  z-index: 12;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  cursor: pointer;
  transition: transform 120ms var(--ease), background 160ms, color 160ms, border-color 160ms;
  touch-action: manipulation;
}
.icon-btn svg { width: 20px; height: 20px; display: block; }
.icon-btn:hover { color: var(--amber-hot); background: rgba(255, 154, 60, 0.1); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn.is-danger:hover { color: var(--coral); background: rgba(255, 90, 77, 0.12); }
.icon-btn:focus-visible {
  outline: none;
  border-color: var(--amber-ring);
  box-shadow: 0 0 0 3px rgba(255, 154, 60, 0.28);
}

/* Confirm popover for CLEAR */
.confirm-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 208px;
  padding: 14px;
  border-radius: var(--r-md);
  z-index: 20;
  transform-origin: top right;
  animation: pop-in 160ms var(--ease);
}
.confirm-pop p {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.confirm-pop .row { display: flex; gap: 8px; }
.confirm-pop button {
  flex: 1;
  height: 38px;
  border-radius: var(--r-sm);
  border: 1px solid var(--glass-hi);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 120ms var(--ease), background 140ms, color 140ms;
}
.confirm-pop button:active { transform: scale(0.94); }
.confirm-pop .confirm-yes {
  background: linear-gradient(180deg, var(--coral), var(--coral-deep));
  color: #fff;
  border-color: transparent;
}
.confirm-pop .confirm-yes:hover { filter: brightness(1.08); }
.confirm-pop button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 154, 60, 0.3);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* -------------------------------------------------- Brush slider (left) */
.brush {
  position: absolute;
  left: calc(14px + var(--sa-l));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 10px;
  border-radius: var(--r-lg);
  z-index: 11;
}
.brush-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  opacity: 0.7;
}
.brush-val {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--amber);
  min-width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.brush-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 6px;
  writing-mode: vertical-lr;      /* vertical orientation, modern */
  direction: rtl;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}
/* track */
.brush-slider::-webkit-slider-runnable-track {
  width: 6px;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255,154,60,0.15), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,205,150,0.08);
}
.brush-slider::-moz-range-track {
  width: 6px;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255,154,60,0.15), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,205,150,0.08);
}
/* thumb */
.brush-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-left: -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--amber-hot), var(--amber-deep));
  border: 1px solid rgba(255, 220, 180, 0.6);
  box-shadow: 0 0 14px var(--amber-glow), 0 2px 6px rgba(0,0,0,0.5);
  cursor: grab;
}
.brush-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--amber-hot), var(--amber-deep));
  border: 1px solid rgba(255, 220, 180, 0.6);
  box-shadow: 0 0 14px var(--amber-glow), 0 2px 6px rgba(0,0,0,0.5);
  cursor: grab;
}
.brush-slider:focus-visible { outline: none; }
.brush-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(255,154,60,0.35), 0 0 14px var(--amber-glow);
}

/* ------------------------------------------------ Sand color picker */
.sandcolor {
  position: absolute;
  left: calc(14px + var(--sa-l));
  bottom: calc(150px + var(--sa-b));
  width: 190px;
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: var(--r-lg);
  z-index: 12;
}
.sandcolor.is-visible {
  display: flex;
  animation: sandcolor-in 180ms ease;
}
@keyframes sandcolor-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.sandcolor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sandcolor-title {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  opacity: 0.8;
}
.sandcolor-preview {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18), 0 1px 4px rgba(0,0,0,0.4);
}
/* saturation / brightness field */
.sandcolor-sv {
  position: relative;
  width: 100%;
  height: 118px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  cursor: crosshair;
  touch-action: none;
}
.sandcolor-sv-thumb,
.sandcolor-hue-thumb {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 1px 4px rgba(0,0,0,0.5);
  pointer-events: none;
}
/* hue slider */
.sandcolor-hue {
  position: relative;
  width: 100%;
  height: 16px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  cursor: pointer;
  touch-action: none;
  background: linear-gradient(to right,
    #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%,
    #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}
.sandcolor-hue-thumb {
  top: 50%;
  background: transparent;
}
/* hex field */
.sandcolor-hexinput {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: rgba(0,0,0,0.28);
  color: var(--ink, #f4ecdd);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
}
.sandcolor-hexinput:focus-visible {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(255,154,60,0.3);
}
.sandcolor-swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.sandcolor-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 7px;
  border: none;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.sandcolor-swatch:active { transform: scale(0.88); }
.sandcolor-swatch.is-active {
  box-shadow: 0 0 0 2px #0a0912, 0 0 0 4px var(--amber), 0 0 10px var(--amber-glow);
}
.sandcolor-swatch.is-natural {
  background: conic-gradient(from 210deg, #d9b46a, #e3c078, #c8a052, #cfa85c, #d9b46a);
}
.sandcolor-swatch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #0a0912, 0 0 0 4px rgba(255,154,60,0.6);
}

/* ----------------------------------------------------- Bottom bar dock */
.dock {
  position: absolute;
  left: 50%;
  bottom: calc(12px + var(--sa-b));
  transform: translateX(-50%);
  width: min(1100px, calc(100vw - 24px - var(--sa-l) - var(--sa-r)));
  border-radius: var(--r-lg);
  z-index: 11;
  transition: transform 340ms var(--ease), opacity 300ms;
}
.dock.is-collapsed {
  transform: translateX(-50%) translateY(calc(100% + 24px + var(--sa-b)));
  opacity: 0;
  pointer-events: none;
}

/* collapse / expand handle sits above the dock */
.dock-handle {
  position: absolute;
  left: 50%;
  top: -34px;
  transform: translateX(-50%);
  width: 52px;
  height: 26px;
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--glass-hi);
  border-bottom: none;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 160ms, transform 120ms var(--ease);
}
.dock-handle:hover { color: var(--amber-hot); }
.dock-handle:active { transform: translateX(-50%) scale(0.94); }
.dock-handle svg { width: 18px; height: 18px; transition: transform 320ms var(--ease); }
.dock-handle:focus-visible {
  outline: none;
  color: var(--amber-hot);
  box-shadow: 0 0 0 3px rgba(255,154,60,0.3);
}
/* When collapsed, a floating re-open handle is shown instead */
.reopen {
  position: absolute;
  left: 50%;
  bottom: calc(10px + var(--sa-b));
  transform: translateX(-50%);
  z-index: 11;
  width: 56px;
  height: 30px;
  border-radius: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 160ms, transform 120ms var(--ease);
}
.reopen.is-visible { display: flex; }
.reopen:hover { color: var(--amber-hot); }
.reopen:active { transform: translateX(-50%) scale(0.94); }
.reopen svg { width: 18px; height: 18px; }
.reopen:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255,154,60,0.3); }

.dock-inner {
  padding: 12px 12px 12px;
}

/* Palette scroller */
.palette {
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,154,60,0.4) transparent;
}
.palette::-webkit-scrollbar { height: 6px; }
.palette::-webkit-scrollbar-track { background: transparent; }
.palette::-webkit-scrollbar-thumb {
  background: rgba(255,154,60,0.35);
  border-radius: 4px;
}
.palette::-webkit-scrollbar-thumb:hover { background: rgba(255,154,60,0.6); }

/* Category group */
.cat-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 8px;
  border-right: 1px solid rgba(255, 205, 150, 0.08);
  flex: 0 0 auto;
}
.cat-group:last-child { border-right: none; }
.cat-label {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
  opacity: 0.6;
  padding-left: 2px;
}
.cat-chips {
  display: flex;
  gap: 6px;
}

/* Element chip */
.chip {
  flex: 0 0 auto;
  width: 62px;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  transition: transform 120ms var(--ease), background 160ms, border-color 160ms;
  touch-action: manipulation;
}
.chip:hover { background: rgba(255, 255, 255, 0.06); }
.chip:active { transform: scale(0.93); }
.chip:focus-visible {
  outline: none;
  border-color: var(--amber-ring);
  box-shadow: 0 0 0 3px rgba(255,154,60,0.28);
}
.chip .dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.25), inset 0 -2px 4px rgba(0,0,0,0.4);
  flex: 0 0 auto;
}
/* Rainbow dust gets an animated conic swatch */
.chip .dot.rainbow {
  background: conic-gradient(from 0deg, #ff5aa0, #ffca3a, #8ce62e, #2f7bd9, #b45aff, #ff5aa0) !important;
  animation: spin 6s linear infinite;
}
/* Eraser gets a hatch */
.chip .dot.eraser {
  background:
    repeating-linear-gradient(45deg, #2a2a34 0 4px, #16161d 4px 8px) !important;
}
.chip .name {
  font-family: var(--font-mono);
  font-size: 8.5px;
  line-height: 1.05;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  text-align: center;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.is-selected {
  border-color: var(--amber-ring);
  background: rgba(255, 154, 60, 0.12);
  box-shadow: 0 0 0 1px var(--amber-ring), 0 0 18px -2px var(--amber-glow);
}
.chip.is-selected .dot {
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.3),
    0 0 12px var(--amber-glow);
}
.chip.is-selected .name { color: var(--amber-hot); }

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- Toast */
.toast-wrap {
  position: absolute;
  left: 50%;
  bottom: calc(150px + var(--sa-b));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--glass-hi);
  box-shadow: 0 8px 30px -10px rgba(0,0,0,0.8), 0 0 22px -8px var(--amber-glow);
  white-space: nowrap;
  animation: toast-in 260ms var(--ease);
}
.toast.is-out { animation: toast-out 260ms var(--ease) forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.96); }
}

/* ========================================================= TITLE SCREEN */
#title-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(70% 60% at 50% 42%, rgba(255,120,40,0.14), rgba(0,0,0,0) 60%),
    radial-gradient(140% 110% at 50% 130%, #0a0b12 0%, #05060a 70%);
  overflow: hidden;
  transition: opacity 600ms var(--ease), transform 600ms var(--ease);
  will-change: opacity, transform;
}
#title-screen.is-hiding {
  opacity: 0;
  transform: scale(1.06);
  pointer-events: none;
}
#title-screen.is-gone { display: none; }

.title-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  max-width: 92vw;
}

.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(48px, 12vw, 128px);
  letter-spacing: 0.06em;
  line-height: 0.95;
  color: var(--ink);
  display: flex;
  gap: 0.01em;
  background: linear-gradient(180deg, #fff6ec 0%, #ffc98a 40%, var(--amber) 78%, var(--amber-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 30px rgba(255,120,40,0.4));
}
.wordmark span {
  display: inline-block;
  animation: grain-settle 720ms var(--ease) backwards;
  animation-delay: calc(var(--i) * 70ms + 120ms);
}
@keyframes grain-settle {
  from { opacity: 0; transform: translateY(-42px) rotate(-6deg); }
  60%  { opacity: 1; }
  to   { opacity: 1; transform: translateY(0) rotate(0); }
}

.tagline {
  margin: 18px 0 0;
  font-family: var(--font-mono);
  font-size: clamp(12px, 2.4vw, 16px);
  letter-spacing: 0.34em;
  text-transform: lowercase;
  color: var(--ink-dim);
  animation: fade-up 700ms var(--ease) 640ms backwards;
}

.play-btn {
  margin-top: 40px;
  min-height: 64px;
  padding: 0 46px;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  border: 1px solid rgba(255, 220, 180, 0.35);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--amber-hot) 0%, var(--amber) 46%, var(--amber-deep) 100%);
  color: #241004;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.18em;
  cursor: pointer;
  box-shadow:
    0 12px 40px -12px rgba(255,120,40,0.7),
    inset 0 1px 0 rgba(255,255,255,0.5);
  transition: transform 120ms var(--ease), box-shadow 200ms, filter 200ms;
  animation: fade-up 700ms var(--ease) 760ms backwards;
  touch-action: manipulation;
}
.play-btn:hover {
  filter: brightness(1.06) saturate(1.06);
  box-shadow: 0 16px 54px -12px rgba(255,140,50,0.85), inset 0 1px 0 rgba(255,255,255,0.6);
}
.play-btn:active { transform: scale(0.96); }
.play-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(255,154,60,0.4), 0 12px 40px -12px rgba(255,120,40,0.7);
}
.play-glyph {
  width: 0;
  height: 0;
  border-left: 15px solid #2a1204;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  margin-left: 2px;
}

.title-footer {
  margin-top: 34px;
  font-family: var(--font-mono);
  font-size: clamp(10px, 1.8vw, 12px);
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  animation: fade-up 700ms var(--ease) 880ms backwards;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Drifting ember particles — transform/opacity only */
.title-embers {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}
.ember {
  position: absolute;
  bottom: -20px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--amber-hot), var(--amber) 55%, rgba(255,120,40,0) 72%);
  filter: blur(1px);
  opacity: 0;
  animation: ember-rise linear infinite;
}
.ember:nth-child(1) { left: 12%; animation-duration: 11s; animation-delay: 0s;   width: 5px; height: 5px; }
.ember:nth-child(2) { left: 24%; animation-duration: 14s; animation-delay: 2.4s; width: 8px; height: 8px; }
.ember:nth-child(3) { left: 38%; animation-duration: 9s;  animation-delay: 1.2s; }
.ember:nth-child(4) { left: 50%; animation-duration: 13s; animation-delay: 3.6s; width: 4px; height: 4px; }
.ember:nth-child(5) { left: 61%; animation-duration: 10s; animation-delay: 0.8s; width: 7px; height: 7px; }
.ember:nth-child(6) { left: 72%; animation-duration: 15s; animation-delay: 4.2s; }
.ember:nth-child(7) { left: 83%; animation-duration: 12s; animation-delay: 2s;   width: 5px; height: 5px; }
.ember:nth-child(8) { left: 90%; animation-duration: 8s;  animation-delay: 5s;   width: 4px; height: 4px; }
.ember:nth-child(9) { left: 6%;  animation-duration: 16s; animation-delay: 3s;   width: 8px; height: 8px; }
@keyframes ember-rise {
  0%   { opacity: 0; transform: translateY(0) translateX(0) scale(0.8); }
  12%  { opacity: 0.9; }
  70%  { opacity: 0.7; }
  100% { opacity: 0; transform: translateY(-104vh) translateX(28px) scale(1.1); }
}

/* ================================================== Responsive tweaks */

/* Portrait / narrow — let the palette own more width, tuck brush into dock */
@media (max-width: 760px), (orientation: portrait) {
  .brush {
    /* compact horizontal pill, top-left, clear of the top-right controls */
    position: absolute;
    left: calc(10px + var(--sa-l));
    top: calc(34px + var(--sa-t, 0px));
    transform: none;
    width: max-content;
    max-width: 46vw;
    flex-direction: row;
    padding: 8px 12px;
    border-radius: var(--r-md);
    justify-content: center;
  }
  .brush-label { writing-mode: horizontal-tb; }
  .brush-slider {
    writing-mode: horizontal-tb;
    direction: ltr;
    width: 160px;
    height: 22px;
  }
  .brush-slider::-webkit-slider-runnable-track { width: auto; height: 6px; }
  .brush-slider::-moz-range-track { width: auto; height: 6px; }
  .brush-slider::-webkit-slider-thumb { margin-left: 0; margin-top: -8px; }
  .dock {
    width: calc(100vw - 20px - var(--sa-l) - var(--sa-r));
    bottom: calc(10px + var(--sa-b));
  }
  .dock-inner { display: flex; flex-direction: column; }
  .chip { width: 56px; }
  /* tuck the color picker below the top-left brush pill, clear of the dock */
  .sandcolor {
    bottom: auto;
    top: calc(96px + var(--sa-t, 0px));
  }
}

/* Short landscape (Chromebook-ish) — keep everything compact */
@media (max-height: 560px) {
  .brush { padding: 12px 8px; gap: 8px; }
  .brush-slider { width: 110px; }
  .chip { width: 58px; min-height: 58px; }
  .wordmark { font-size: clamp(40px, 10vw, 96px); }
  /* keep the color picker compact so it never overflows a short viewport */
  .sandcolor { bottom: calc(96px + var(--sa-b)); padding: 10px; gap: 8px; }
  .sandcolor-sv { height: 76px; }
}

/* prefers-reduced-motion — kill title choreography */
@media (prefers-reduced-motion: reduce) {
  .wordmark span,
  .tagline,
  .play-btn,
  .title-footer { animation: none !important; }
  .ember { animation: none !important; opacity: 0 !important; }
  .chip .dot.rainbow { animation: none !important; }
  #title-screen { transition: opacity 200ms linear; }
  #title-screen.is-hiding { transform: none; }
}
