:root {
  --ink: #33323d;
  --ink-soft: #8a8794;
  --paper: rgba(255, 255, 255, 0.82);
  --line: rgba(51, 50, 61, 0.08);
  --accent: #ff6b57;
  --radius: 22px;
  font-size: 15px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", "Comic Sans MS", system-ui, sans-serif;
  color: var(--ink);
  background: #dceffb;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- brand ---------- */
.brand {
  position: fixed;
  top: 22px;
  left: 26px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.brand-dot {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(255, 107, 87, 0.4);
  transition: background 0.4s, box-shadow 0.4s;
}
.brand h1 {
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1;
}
.brand p {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-top: 3px;
}

/* ---------- side panel ---------- */
.panel {
  position: fixed;
  top: 86px;
  left: 26px;
  bottom: 96px;
  width: 252px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 5;
}

.characters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.char-card {
  flex: 1;
  background: var(--paper);
  backdrop-filter: blur(14px);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 12px 10px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 10px 30px rgba(60, 70, 90, 0.10);
}
.char-card:hover { transform: translateY(-2px); }
.char-card.active {
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(60, 70, 90, 0.16);
}
.char-card .swatch {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  margin: 0 auto 7px;
}
.char-card .name {
  font-weight: 900;
  font-size: 0.95rem;
}
.char-card .tag {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.animations {
  flex: 1;
  overflow-y: auto;
  background: var(--paper);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 10px 30px rgba(60, 70, 90, 0.10);
  scrollbar-width: thin;
  scrollbar-color: rgba(51, 50, 61, 0.18) transparent;
}
.anim-group {
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  margin: 14px 4px 7px;
}
.anim-group:first-child { margin-top: 2px; }
.anim-chip {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink);
  background: transparent;
  border: none;
  border-radius: 13px;
  padding: 8px 12px;
  margin-bottom: 3px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.anim-chip:hover { background: var(--line); }
.anim-chip:active { transform: scale(0.98); }
.anim-chip.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
.anim-chip .dur {
  float: right;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.55;
}

.record-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--ink);
  background: var(--paper);
  backdrop-filter: blur(14px);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 11px 14px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(60, 70, 90, 0.10);
  transition: transform 0.15s, border-color 0.2s;
}
.record-btn:hover { transform: translateY(-2px); border-color: var(--accent); }
.record-btn[hidden] { display: none; }
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff3b30;
  box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.22);
}

.chip-delete {
  float: right;
  font-size: 0.75rem;
  opacity: 0.4;
  padding: 0 2px;
  transition: opacity 0.15s, color 0.15s;
}
.chip-delete:hover { opacity: 1; color: #ff3b30; }

.credits {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.5;
}
.credits a { color: var(--ink-soft); }

/* ---------- emotion bar ---------- */
.emotions {
  position: fixed;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--paper);
  backdrop-filter: blur(14px);
  border-radius: 999px;
  padding: 12px 9px;
  box-shadow: 0 12px 34px rgba(60, 70, 90, 0.14);
  z-index: 5;
}
.emotion {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
}
.emotion:hover { transform: scale(1.15); }
.emotion.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ---------- bottom controls ---------- */
.controls {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 22px;
  background: var(--paper);
  backdrop-filter: blur(14px);
  border-radius: 999px;
  padding: 12px 24px;
  box-shadow: 0 12px 34px rgba(60, 70, 90, 0.14);
  z-index: 5;
  white-space: nowrap;
}
.controls .label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-soft);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.toggle input { display: none; }
.toggle .knob {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #d6d3dd;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle .knob::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.toggle input:checked + .knob { background: var(--accent); }
.toggle input:checked + .knob::after { left: 19px; }

.slider {
  display: flex;
  align-items: center;
  gap: 9px;
}
.slider input[type="range"] {
  width: 90px;
  accent-color: var(--accent);
}
.slider .value {
  font-size: 0.78rem;
  font-weight: 800;
  min-width: 40px;
}

.button {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 900;
  color: var(--ink);
  background: var(--line);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.button:hover { background: rgba(51, 50, 61, 0.14); }
.button:active { transform: scale(0.96); }

/* ---------- webcam recorder ---------- */
.recorder {
  position: fixed;
  top: 50%;
  right: 22px;
  transform: translateY(-50%);
  z-index: 10;
  transition: opacity 0.25s, transform 0.25s;
}
.recorder.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(24px);
}
.recorder-card {
  width: 356px;
  background: var(--paper);
  backdrop-filter: blur(16px);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 18px 50px rgba(60, 70, 90, 0.22);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.recorder-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.recorder-card h2 {
  font-size: 1.02rem;
  font-weight: 900;
}
.recorder-card header p {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: 2px;
}
.rec-close {
  border: none;
  background: var(--line);
  color: var(--ink-soft);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}
.rec-close:hover { background: rgba(51, 50, 61, 0.16); }

.rec-stage {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #1c1b22;
}
.rec-stage video,
.rec-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* selfie mirror — the solver mirrors to match */
}
.rec-countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}
.rec-countdown[hidden] { display: none; }
.rec-timer {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 0.8rem;
  font-weight: 900;
  color: #fff;
  background: rgba(255, 59, 48, 0.85);
  border-radius: 999px;
  padding: 4px 10px;
}
.rec-status {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-soft);
  text-align: center;
  min-height: 1.2em;
}
.rec-actions { display: flex; justify-content: center; }
.rec-record {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 900;
  color: #fff;
  background: #ff3b30;
  border: none;
  border-radius: 999px;
  padding: 10px 28px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(255, 59, 48, 0.35);
  transition: transform 0.12s, background 0.15s;
}
.rec-record:hover { transform: scale(1.04); }
.rec-record.recording {
  background: var(--ink);
  box-shadow: 0 8px 20px rgba(51, 50, 61, 0.3);
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.rec-save {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.rec-save[hidden] { display: none; }
.rec-save input {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  outline: none;
}
.rec-save input:focus { border-color: var(--accent); }
.rec-save-buttons { display: flex; gap: 7px; flex-wrap: wrap; }
.rec-primary {
  background: var(--accent);
  color: #fff;
}
.rec-primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }

@media (max-width: 760px) {
  .recorder { right: 12px; left: 12px; }
  .recorder-card { width: auto; }
}

/* ---------- loading ---------- */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #dceffb;
  z-index: 20;
  transition: opacity 0.4s;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading p {
  font-weight: 800;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.loading-blocks { display: flex; gap: 10px; }
.loading-blocks i {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: var(--accent);
  animation: hop 0.9s ease-in-out infinite;
}
.loading-blocks i:nth-child(2) { background: #2ec4b6; animation-delay: 0.12s; }
.loading-blocks i:nth-child(3) { background: #ffd166; animation-delay: 0.24s; }
@keyframes hop {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-14px); }
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 92px;
    width: auto;
    max-height: 42vh;
  }
  .controls {
    left: 12px;
    right: 12px;
    transform: none;
    justify-content: space-between;
    gap: 10px;
    overflow-x: auto;
  }
  .brand { left: 16px; top: 14px; }
}
