:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gold: #ffe14a;
  --ink: #fff;
  --dim: rgba(255, 255, 255, 0.62);
}

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

html, body {
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

body { display: grid; place-items: center; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  overflow: hidden;
  background: #050506;
}

#cam, #fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cam {
  object-fit: cover;
  background: #050506;
}

#cam.mirror, #fx.mirror { transform: scaleX(-1); }
#cam.hide-video { opacity: 0; }

#fx {
  z-index: 1;
  pointer-events: none;
}

#pad {
  position: absolute;
  inset: 0 0 250px 0;
  z-index: 4;
}

#pad[hidden] { display: none; }

.bug {
  position: absolute;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #ff4b6e 42%, #c4003a);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
}

#stamp, #hint {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  text-shadow: 0 1px 3px #000;
  font-weight: 700;
}

#stamp {
  left: 16px;
  top: calc(62px + var(--safe-t));
  white-space: pre;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  line-height: 1.25;
}

#hint {
  left: 0;
  right: 0;
  top: 22%;
  text-align: center;
  font-size: 16px;
}

#hud {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(70px + var(--safe-t));
  z-index: 5;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

#hud b {
  display: block;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -0.03em;
}

#hud span { font-size: 15px; font-weight: 700; }
#hud.stop b { color: #ff4040; }
#hud.go b { color: #7dffb3; }
#hud.bad b { color: #ff4040; }
#hud.win b { color: var(--gold); }

#flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}

#flash.bad { background: #ff2040; }
#flash.on { animation: pop 180ms ease-out; }

@keyframes pop {
  from { opacity: 0.8; }
  to { opacity: 0; }
}

#need {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 28%;
  z-index: 2;
  text-align: center;
}

#need[hidden] { display: none; }

.brand {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 18px;
}

#enable {
  border: 0;
  background: var(--ink);
  color: #111;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  padding: 14px 22px;
  border-radius: 999px;
}

#err {
  margin-top: 14px;
  color: var(--dim);
  font-size: 14px;
  line-height: 1.4;
}

#toast {
  position: absolute;
  top: calc(64px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.top, .dock { position: absolute; left: 0; right: 0; z-index: 5; }

.top {
  top: 0;
  display: flex;
  justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 14px 0;
  pointer-events: none;
}

.top button { pointer-events: auto; }

.top button, #shutter, .modes button, .card, #voice button, .bug {
  -webkit-tap-highlight-color: transparent;
}

.top button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  color: var(--ink);
  display: grid;
  place-items: center;
}

.top button svg { width: 24px; height: 24px; }

#torch[aria-pressed="true"] {
  background: var(--gold);
  color: #1a1400;
}

.dock {
  bottom: 0;
  padding-bottom: calc(8px + var(--safe-b));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.45) 24%, rgba(0, 0, 0, 0.78));
}

#voice {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

#voice[hidden] { display: none; }

#voice button {
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

#voice button.on { background: var(--gold); color: #1a1400; }

.shutter-row {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 82px;
  padding: 4px 22px 2px;
}

#last {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: center / cover no-repeat rgba(255, 255, 255, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.85);
}

#last[hidden] { display: none; }

#shutter {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  padding: 4px;
}

#shutter i, #shutter em {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
}

#shutter em {
  display: none;
  font-style: normal;
  font-weight: 800;
  font-size: 14px;
  color: #111;
}

#shutter.play i { display: none; }
#shutter.play em { display: grid; }

#shutter:active i, #shutter:active em {
  transform: scale(0.9);
  background: var(--gold);
}

.modes {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 4px;
}

.modes button {
  border: 0;
  background: none;
  color: var(--dim);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 4px 4px;
}

.modes button[aria-selected="true"] { color: #fff; }

.modes button[aria-selected="true"]::after {
  content: "";
  display: block;
  width: 16px;
  height: 3px;
  margin: 5px auto 0;
  border-radius: 2px;
  background: var(--gold);
}

.tray {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 10px 16px 6px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x;
}

.tray::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 auto;
  width: 72px;
  scroll-snap-align: center;
  border: 0;
  background: none;
  color: inherit;
  text-align: center;
  font: inherit;
}

.thumb {
  width: 64px;
  height: 64px;
  margin: 0 auto 6px;
  border-radius: 50%;
  border: 2px solid transparent;
  overflow: hidden;
  background: #222;
}

.thumb canvas { width: 100%; height: 100%; display: block; }
.card.on .thumb { box-shadow: 0 0 0 2px #111, 0 0 0 4px #fff; }

.card .name {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

@media (prefers-reduced-motion: reduce) {
  #flash.on { animation: none; }
}
