:root {
  --bg: #0b0d10;
  --fg: #f5f7fa;
  --muted: #8a94a6;
  --panel: rgba(18, 22, 28, 0.72);
  --border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

button, input {
  font-family: inherit;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Caveat Brush", cursive;
  overflow: hidden;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

#video, #ink, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* mirror the camera so movements feel natural */
  transform: scaleX(-1);
}

#photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
#photo[hidden] { display: none !important; }
#video { z-index: 0; filter: brightness(0.55) saturate(0.8); }
#ink { z-index: 1; pointer-events: none; }
#overlay { z-index: 2; pointer-events: none; }

.stage.photo-mode #video {
  visibility: visible;
  inset: auto 92px 20px auto;
  width: 220px;
  height: 124px;
  z-index: 4;
  border-radius: 18px;
  filter: none;
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.stage.photo-mode #ink,
.stage.photo-mode #overlay {
  transform: none;
}

.photo-tools {
  position: absolute;
  z-index: 6;
  right: 92px;
  bottom: 152px;
  display: flex;
  gap: 8px;
}
.photo-tools[hidden] { display: none !important; }
.photo-exit {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.photo-exit[hidden] { display: none !important; }

.hud {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  cursor: default;
}

.status { display: none !important; }

.gesture {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  white-space: normal;
  text-align: center;
  line-height: 1.35;
  max-width: min(640px, 92vw);
}
.gesture[hidden] { display: none !important; }

.toolbar {
  position: absolute;
  top: 50%;
  right: 18px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: max-content;
  height: max-content;
  padding: 12px 10px;
  transform: translateY(-50%);
  border-radius: 32px;
  cursor: default;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.05) 28%, rgba(255, 255, 255, 0.08)),
    rgba(28, 28, 30, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(40px) saturate(1.85);
  -webkit-backdrop-filter: blur(40px) saturate(1.85);
}

.swatches { display: flex; flex-direction: column; gap: 8px; }

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--c);
  cursor: pointer;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch:focus,
.swatch:focus-visible { outline: none; }
.swatch.active { border-color: #fff; transform: scale(1.1); }
.swatch[data-color="#000000"] { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45); }
.rainbow-swatch {
  border: 0;
  background: conic-gradient(#ff3b30, #ffcc00, #34c759, #0a84ff, #af52de, #ff2d55, #ff3b30);
  box-shadow: none;
}
.rainbow-swatch.active {
  box-shadow: 0 0 0 2px #fff;
}
#color-slot { margin-top: 4px; }
#color-slot .stroke-more {
  top: -6px;
  right: -6px;
}

.color-panel {
  position: fixed;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 220px;
  padding: 12px;
  border-radius: 22px;
  cursor: default;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.05) 22%, rgba(255, 255, 255, 0.08)),
    rgba(28, 28, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(40px) saturate(1.85);
  -webkit-backdrop-filter: blur(40px) saturate(1.85);
}
.color-panel[hidden] { display: none !important; }

.color-field {
  position: relative;
  height: 132px;
  border-radius: 14px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  background: #ff2d55;
}
.color-field-white,
.color-field-black { position: absolute; inset: 0; pointer-events: none; }
.color-field-white { background: linear-gradient(90deg, #fff, transparent); }
.color-field-black { background: linear-gradient(180deg, transparent, #000); }
.color-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.color-hue {
  width: 100%;
  height: 16px;
  margin: 0;
  appearance: none;
  border-radius: 99px;
  background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
  outline: none;
}
.color-hue::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #1c1c1e;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.color-hex {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--fg);
}
.color-preview {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.45);
  flex: 0 0 auto;
}
.color-hex input {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 16px;
  letter-spacing: 0.06em;
  outline: none;
  padding: 0;
}

.size {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.size input {
  width: 28px;
  height: 96px;
  margin: 0;
  accent-color: #ff4d8d;
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: slider-vertical;
}

.btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }

.top-actions {
  position: absolute;
  top: 16px;
  right: 18px;
  z-index: 40;
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: default;
}
.top-actions .icon-btn {
  font-size: 18px;
  line-height: 1;
}

.corner-actions {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 5;
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: default;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
}
.icon-btn svg { display: block; }
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  cursor: default;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  white-space: normal;
  text-align: center;
  line-height: 1.35;
  max-width: min(640px, 92vw);
}

.divider {
  width: 28px;
  height: 1px;
  flex: 0 0 auto;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
}

.brushes { display: flex; flex-direction: column; gap: 6px; }

.stroke-slot { position: relative; }

.stroke-more {
  position: absolute;
  top: -4px;
  right: -4px;
  z-index: 2;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  color: #1c1c1e;
  pointer-events: none;
  border: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}
.stroke-more svg { display: block; }

.stroke-menu {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  cursor: default;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.05) 28%, rgba(255, 255, 255, 0.08)),
    rgba(28, 28, 30, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(40px) saturate(1.85);
  -webkit-backdrop-filter: blur(40px) saturate(1.85);
}
.stroke-menu[hidden] { display: none !important; }

.emoji-panel {
  position: fixed;
  z-index: 8;
  display: flex;
  flex-direction: column;
  width: 360px;
  height: 420px;
  cursor: default;
  padding: 10px 10px 8px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.05) 22%, rgba(255, 255, 255, 0.08)),
    rgba(28, 28, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(40px) saturate(1.85);
  -webkit-backdrop-filter: blur(40px) saturate(1.85);
}
.emoji-panel[hidden] { display: none !important; }

.emoji-search {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
}
.emoji-search::placeholder { color: var(--muted); }

.emoji-tones {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 0 2px;
}
.emoji-tone {
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid transparent;
  cursor: pointer;
}
.emoji-tone.active { border-color: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35); }

.emoji-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  align-content: start;
  margin: 6px 0;
}
.emoji-grid::-webkit-scrollbar { width: 8px; }
.emoji-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.28);
  border-radius: 99px;
}
.emoji-cell {
  height: 36px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.emoji-cell:hover { background: rgba(255, 255, 255, 0.16); }
.emoji-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 28px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.emoji-cats { display: flex; }
.emoji-cat {
  flex: 1;
  height: 30px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.emoji-cat.active,
.emoji-cat:hover { background: rgba(255, 255, 255, 0.18); }

.brush,
.stroke-opt {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.brush:hover,
.stroke-opt:hover { transform: scale(1.06); background: rgba(255, 255, 255, 0.16); }
.brush.active,
.brush.on,
.stroke-opt.active {
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.stroke-opt svg { display: block; }

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  padding: 4px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}
.toggle input { accent-color: #ff2d55; }

/* --- Pick-a-brush overlay --- */
#picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  cursor: crosshair;
  background: rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(2px) saturate(1.2);
  -webkit-backdrop-filter: blur(2px) saturate(1.2);
}

.picker-msg {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--fg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.picker-msg kbd {
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 11px;
  font-family: inherit;
  border: 1px solid var(--border);
}

.pick-highlight {
  outline: 2px solid #0a84ff !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px rgba(10, 132, 255, 0.25) !important;
  transition: outline-color 0.1s ease;
}

/* --- Shatter layer --- */
#shatter-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
  /* Mirrored same as the video/canvas so tile coordinates line up. */
  transform: scaleX(-1);
}

.shard {
  position: absolute;
  will-change: transform, opacity;
  /* Smooth hand-off between tile and the ink underneath. */
  image-rendering: auto;
}

.permit {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 40;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  background: rgba(28, 28, 30, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
}
.permit[hidden] { display: none !important; }

.intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 10, 14, 0.42);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  font-family: Inter, system-ui, sans-serif;
}
.intro[hidden] { display: none !important; }

.intro-card {
  width: min(480px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 28px 26px 22px;
  border-radius: 28px;
  color: var(--fg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05) 22%, rgba(255, 255, 255, 0.08)),
    rgba(28, 28, 30, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12);
}

.intro h1 {
  margin: 0;
  font-family: "Caveat Brush", cursive;
  font-size: 52px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.intro-lead {
  margin: 14px 0 0;
  font-size: 15px;
  line-height: 1.45;
  color: rgba(245, 247, 250, 0.78);
}

.intro-gestures {
  list-style: none;
  margin: 22px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.intro-gestures li {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.intro-emoji {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 77, 141, 0.16);
  font-size: 20px;
}

.intro-gestures strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}

.intro-gestures li span span {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(245, 247, 250, 0.66);
}

.intro-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 18px;
}

.intro-foot button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  background: #ff4d8d;
  color: #fff;
  font-family: Inter, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.intro-foot button:hover { background: #ff6ba3; }
.intro-foot button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

@keyframes shard-fall {
  to {
    transform:
      translate(var(--dx), var(--dy))
      rotate(var(--rot))
      scale(var(--scale));
    opacity: 0;
  }
}
