* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #12050d;
  --card: #2a0e22;
  --line: #62214b;
  --text: #fff1f6;
  --muted: #dca9c1;
  --accent: #ff4d8d;
  --other: #ffc857;
  --heat: linear-gradient(135deg, #d5135f, #e8431f);
  --glow: 0 0 18px rgb(255 46 118 / .55);
  /* How far the player is drawn past each edge, so its controls fall out of view. */
  --crop-x: 64px;
  --crop-y: 90px;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(120% 55% at 50% -5%, rgb(255 35 110 / .42), transparent 70%),
    radial-gradient(90% 50% at 105% 105%, rgb(255 110 40 / .3), transparent 70%),
    radial-gradient(80% 45% at -10% 80%, rgb(150 30 160 / .3), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.4 system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

.center { justify-content: center; align-items: center; text-align: center; }

h1 { font-size: 28px; margin-bottom: 16px; }
h2 { font-size: 18px; }

form#loginForm { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; text-align: left; }

/* 16px inputs stop iOS from zooming on focus. */
input[type="password"], input[type="search"] {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

button {
  min-height: 48px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  touch-action: manipulation;
}
button:disabled { opacity: .4; }
button.primary { background: var(--heat); border-color: transparent; color: #fff; box-shadow: var(--glow); }
button.link { background: none; border: none; color: var(--accent); min-height: 40px; padding: 0 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.error { color: var(--other); min-height: 22px; margin-top: 12px; }

header { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 40px; color: var(--muted); font-size: 14px; }
#partner { margin-right: auto; }
header > * { white-space: nowrap; }
header button.link { font-size: 14px; }
#asked { display: flex; flex-direction: column; gap: 8px; padding: 12px; text-align: center; border: 1px solid var(--accent); border-radius: 14px; }
#asked .row button { flex: 1; }
#time { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.dot::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--line); }
.dot.on::before { background: var(--accent); }

section { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }

.row { display: flex; gap: 8px; }

#length { border: 0; display: flex; gap: 6px; }
#length legend { font-weight: 700; margin-bottom: 6px; }
#length label { flex: 1; }
#length input { position: absolute; opacity: 0; }
#length span { display: grid; place-items: center; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 14px; }
#length input:checked + span { background: var(--heat); border-color: transparent; color: #fff; font-weight: 700; box-shadow: var(--glow); }
#length input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
#length:disabled { opacity: .4; }

#niches { list-style: none; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
#niches button { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; font-weight: 500; }
#niches small { color: var(--muted); }

#options { list-style: none; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
#options li:first-child { margin-top: auto; }
#options li:last-child { margin-bottom: auto; }
#options button { width: 100%; }
.choice { min-height: 56px; display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; border-width: 2px; }
.choice.mine { border-color: var(--accent); }
.choice.theirs { border-color: var(--other); }
.choice.mine small { color: var(--accent); }
.choice.theirs small { color: var(--other); }
#stay { flex-shrink: 0; border-style: dashed; }
#stay.mine, #stay.theirs { border-style: solid; }

.title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.title h2 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

#board { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }

#grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.tile { position: relative; overflow: hidden; border-radius: 10px; background: var(--card); }

/* Drawn at double size and scaled down, then pushed past the edges to crop the controls. */
.tile iframe {
  position: absolute;
  top: calc(var(--crop-y) / -2);
  left: calc(var(--crop-x) / -2);
  width: calc(200% + 2 * var(--crop-x));
  height: calc(200% + 2 * var(--crop-y));
  border: 0;
  transform: scale(.5);
  transform-origin: 0 0;
  pointer-events: none;
}

/* Covers the whole player: every tap selects, none reaches the sound button. */
.tile button {
  position: absolute;
  inset: 0;
  width: 100%;
  background: transparent;
  border: 3px solid transparent;
  border-radius: 10px;
  opacity: 1;
}
.tile.mine button { border-color: var(--accent); }
.tile.theirs button { border-color: var(--other); }
.tile.mine.theirs button { border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--other); }

.badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  background: var(--heat);
  color: #fff;
  pointer-events: none;
}
.tile.theirs:not(.mine) .badge { background: var(--other); color: #2b1800; }

/* Result and buttons in the middle of the screen. */
#result {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(260px, 85%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  text-align: center;
  background: rgb(32 7 24 / .93);
  border: 1px solid var(--line);
  border-radius: 16px;
}
#resultText { font-weight: 700; font-size: 18px; }
#result.win { border-color: var(--accent); }
#result.win #resultText { color: var(--accent); }

#status { min-height: 28px; text-align: center; color: var(--muted); }
#status.live { color: var(--text); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Full screen layers. */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 480px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  background: radial-gradient(120% 55% at 50% -5%, #55102f, transparent 70%), var(--bg);
  text-align: center;
}
#cam { z-index: 3; }
#photo { z-index: 4; }
#cam .row button { flex: 1; padding: 0 8px; }

/* The empty layer above the frame swallows every tap. */
#stage { flex: 1; min-height: 0; position: relative; overflow: hidden; border-radius: 12px; background: var(--card); }
#stage iframe {
  position: absolute;
  top: calc(-1 * var(--crop-y));
  left: calc(-1 * var(--crop-x));
  width: calc(100% + 2 * var(--crop-x));
  height: calc(100% + 2 * var(--crop-y));
  border: 0;
  pointer-events: none;
}
#stage::after { content: ""; position: absolute; inset: 0; }

.frame { flex: 1; min-height: 0; position: relative; }
.frame video, .frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.mirror { transform: scaleX(-1); }

#toast {
  position: fixed;
  z-index: 5;
  left: 16px;
  right: 16px;
  top: max(44px, env(safe-area-inset-top));
  max-width: 448px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
  pointer-events: none;
}

/* Heat: gradient title, pill buttons, glowing picks. */
h1 { font-size: 44px; font-weight: 800; letter-spacing: -.02em; background: linear-gradient(90deg, #ff4d8d, #ff9a4d); -webkit-background-clip: text; background-clip: text; color: transparent; }
h2 { font-weight: 800; }
button { border-radius: 999px; }
.tile button { border-radius: 14px; }
.tile, #stage { border-radius: 14px; }
.tile.mine button { box-shadow: var(--glow), inset 0 0 22px rgb(255 46 118 / .7); }
.tile.theirs:not(.mine) button { box-shadow: inset 0 0 22px rgb(255 200 87 / .6); }
#result { border-radius: 24px; box-shadow: 0 12px 40px rgb(0 0 0 / .6); }
#result.win { box-shadow: 0 0 38px rgb(255 46 118 / .75); animation: pop .45s ease-out; }
#result.win #resultText { font-size: 24px; }
#status.live { color: #ff8fb8; font-size: 24px; text-shadow: var(--glow); animation: beat 1s ease-in-out infinite; }
.dot.on::before { box-shadow: var(--glow); }

.tile img, #stage img { position: absolute; inset: 0; width: 100%; height: 100%; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.tile img { object-fit: cover; }
#stage img { object-fit: contain; }

@keyframes pop { from { transform: translate(-50%, -50%) scale(.7); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes beat { 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }


/* Plain black over everything, with one dim switch. */
#black { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
#black button { background: none; border-color: #333; color: #777; padding: 0 28px; }
