/* Theme variables: light is the default, dark follows the system
   (prefers-color-scheme), and html.dark / html.light override the
   system when the user toggles the theme button. The html rules
   must come after the media query and must stay in sync with it —
   otherwise a manual toggle would not beat the system choice.
   Photos, face boxes, and the play stage are not themed: a photo
   must look like the photo, and the stage is already dark. */
:root {
  --bg: #f4f2ec;
  --text: #222;
  --muted: #555;
  --surface: #fff;
  --border: #ddd;
  --button-border: #bbb;
  --button-bg: #fff;
  --button-hover: #f0eee8;
  --primary-bg: #222;
  --primary-text: #fff;
  --primary-hover: #444;
  --dropzone-hover-bg: #f9f7f0;
  --row-border: #eee;
  --error: #a00;
  --focus: #222;
  --shadow: rgba(0,0,0,0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --text: #e8e6e1;
    --muted: #a8a5a0;
    --surface: #1e212b;
    --border: #333646;
    --button-border: #44475a;
    --button-bg: #242736;
    --button-hover: #2e3247;
    --primary-bg: #e8e6e1;
    --primary-text: #14161c;
    --primary-hover: #ffffff;
    --dropzone-hover-bg: #242736;
    --row-border: #333646;
    --error: #ff8a7a;
    --focus: #ffd23f;
    --shadow: rgba(0,0,0,0.4);
  }
}
html.dark {
  --bg: #14161c;
  --text: #e8e6e1;
  --muted: #a8a5a0;
  --surface: #1e212b;
  --border: #333646;
  --button-border: #44475a;
  --button-bg: #242736;
  --button-hover: #2e3247;
  --primary-bg: #e8e6e1;
  --primary-text: #14161c;
  --primary-hover: #ffffff;
  --dropzone-hover-bg: #242736;
  --row-border: #333646;
  --error: #ff8a7a;
  --focus: #ffd23f;
  --shadow: rgba(0,0,0,0.4);
}
html.light {
  --bg: #f4f2ec;
  --text: #222;
  --muted: #555;
  --surface: #fff;
  --border: #ddd;
  --button-border: #bbb;
  --button-bg: #fff;
  --button-hover: #f0eee8;
  --primary-bg: #222;
  --primary-text: #fff;
  --primary-hover: #444;
  --dropzone-hover-bg: #f9f7f0;
  --row-border: #eee;
  --error: #a00;
  --focus: #222;
  --shadow: rgba(0,0,0,0.06);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
main { max-width: 720px; margin: 0 auto; padding: 24px 16px 48px; }
.site-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.site-header > div { flex: 1 1 320px; }
.theme-toggle { flex-shrink: 0; margin-top: 4px; }
h1 { margin: 0 0 8px; font-size: 2rem; }
h2 { margin: 0 0 12px; font-size: 1.25rem; }
.tagline { font-size: 1.1rem; margin: 0 0 8px; }
.privacy, .small { font-size: 0.9rem; color: var(--muted); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  margin-top: 20px;
  box-shadow: 0 2px 10px var(--shadow);
}
button {
  font: inherit;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
}
button:hover { background: var(--button-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
/* No focus style existed before: keyboard users could not tell which
   control was focused. :focus-visible keeps mouse users clean. */
button:focus-visible, .dropzone:focus-visible, .play-face:focus-visible, .play-canvas:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
button.primary { background: var(--primary-bg); color: var(--primary-text); border-color: var(--primary-bg); }
button.primary:hover { background: var(--primary-hover); }
button[aria-pressed="true"] { background: var(--primary-bg); color: var(--primary-text); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.primary-row { border-top: 1px solid var(--row-border); padding-top: 14px; }
.error { color: var(--error); }
.hint { color: var(--muted); }
select {
  font: inherit;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text);
}
.anchor-control { display: inline-flex; gap: 6px; align-items: center; }

/* Upload */
.dropzone {
  border: 2px dashed var(--button-border);
  border-radius: 16px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
}
.dropzone.drag-over { border-color: var(--focus); background: var(--dropzone-hover-bg); }

/* Pick stage: the photo sets the size, boxes sit on top in %. */
.photo-stage {
  position: relative;
  width: min(100%, 560px);
  margin: 0 auto;
  touch-action: none;
  user-select: none;
}
.photo-stage img { display: block; width: 100%; height: auto; border-radius: 12px; }
.boxes { position: absolute; inset: 0; }
.face-box {
  position: absolute;
  border: 3px solid #ffd23f;
  border-radius: 8px;
  background: transparent;
  padding: 0;
  cursor: move;
}
.face-box.is-selected { border-color: #ff4d2e; box-shadow: 0 0 0 2px rgba(255,77,46,0.35); }
.face-box .face-label {
  position: absolute; top: -24px; left: 0;
  background: #ff4d2e; color: #fff;
  font-size: 12px; padding: 2px 6px; border-radius: 999px;
  white-space: nowrap;
}
.face-box .resize-handle {
  /* 28px, up from 22px: closer to a touch target without covering
     much of a small face box. Still below the 44px ideal — a larger
     invisible hit area is future work if small faces prove fiddly. */
  position: absolute; right: -10px; bottom: -10px;
  width: 28px; height: 28px;
  background: #ff4d2e; border: 2px solid #fff; border-radius: 50%;
  cursor: nwse-resize;
}

/* Play stage: same stretch + spring as jpl-dev's avatar egg. */
.play-card { text-align: center; }
.play-stage {
  background: radial-gradient(circle at 50% 40%, #3a3f4a, #14161c 75%);
  border-radius: 16px;
  padding: 32px 16px;
  overflow: hidden;
}
.play-face {
  display: block;
  width: min(320px, 80vw);
  height: auto;
  margin: 0 auto;
  border-radius: 16px;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.play-face:active { cursor: grabbing; }
.play-face.is-springing { transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
/* Warp mode: canvas replaces the img, same stage size. Handles are
   visual guides only (pointer-events:none in .play-handles), so a
   drag always hits the canvas and the nearest landmark is the grab. */
.play-warp-wrap { position: relative; width: min(320px, 80vw); margin: 0 auto; }
.play-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 16px;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.play-canvas:active { cursor: grabbing; }
.play-handles { position: absolute; inset: 0; pointer-events: none; }
.play-handle {
  position: absolute;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  background: #ff4d2e;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.2);
  transition: opacity 0.2s;
}
/* Anchor visibility, driven by data-anchor-mode on the wrap
   (set from the Anchors menu, persisted in localStorage):
   - always: dots at full opacity, as before.
   - hover (default): dots hidden until the wrap is hovered or
     focused, then faint (0.45) — enough to find a grab point
     without covering the face. While dragging, the same faint
     level applies, so the grabbed dot stays trackable.
   - hidden: no dots at all; grabbing still works by dragging
     anywhere, since the grab is the nearest landmark.
   Touch devices have no hover, so hover mode shows faint dots
   always there — otherwise touch users would never see a dot. */
.play-warp-wrap[data-anchor-mode="always"] .play-handle { opacity: 1; }
.play-warp-wrap[data-anchor-mode="hover"] .play-handle { opacity: 0; }
.play-warp-wrap[data-anchor-mode="hover"]:hover .play-handle,
.play-warp-wrap[data-anchor-mode="hover"]:focus-within .play-handle,
.play-warp-wrap[data-anchor-mode="hover"].is-dragging .play-handle { opacity: 0.45; }
.play-warp-wrap[data-anchor-mode="hidden"] .play-handle { display: none; }
@media (hover: none) {
  .play-warp-wrap[data-anchor-mode="hover"] .play-handle { opacity: 0.45; }
}
.play-readout { font-variant-numeric: tabular-nums; }
.sound-toggle { display: inline-flex; gap: 6px; align-items: center; }

@media (prefers-reduced-motion: reduce) {
  .play-face.is-springing { transition: none; }
}
