:root {
  --bg: #0a0a0f;
  --panel: #14141d;
  --panel-2: #1c1c28;
  --ink: #e8e8f0;
  --muted: #8a8aa0;
  --line: #2a2a3a;
  --accent: #ff2e88;
  --accent-2: #00e5ff;
  --glow: 0 0 24px rgba(255, 46, 136, 0.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(0, 229, 255, 0.08), transparent),
    radial-gradient(1000px 500px at 0% 110%, rgba(255, 46, 136, 0.1), transparent),
    var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* App shell: a centered column — framed image on top, controls panel below.
   Even gutters on every side scale with the viewport, capped so nothing bleeds
   to the edges on desktop. */
body.editor {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 2.4vh, 22px);
  padding: clamp(14px, 3vw, 28px);
  padding-bottom: max(clamp(14px, 3vw, 28px), env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}

.glass {
  background: rgba(16, 16, 24, 0.66);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

/* The image frame. The Pixi canvas sizes itself to this element (resizeTo:
   canvas.parentNode), drawing the checkered backdrop and letterboxing the photo
   evenly inside it. Capped at 900px so it never spans the whole desktop width. */
.stage-frame {
  position: relative;
  width: 100%;
  max-width: 900px;
  flex: 1 1 auto;
  min-height: 0;            /* allow the frame to shrink so controls stay visible */
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.5);
}
#stage {
  position: absolute; inset: 0;
  display: block; width: 100%; height: 100%;
  cursor: pointer;          /* hints the tap-to-reshuffle affordance */
  touch-action: none;
}

/* Detection overlay: a transparent canvas above the Pixi stage that draws
   subject bounding boxes. Never intercepts taps (the photo stays reshuffleable). */
.detect-overlay {
  position: absolute; inset: 0;
  display: block; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* Empty state: a centered call-to-action over the checker backdrop, shown until
   the first image loads (toggled via [hidden] from main.js). Clicking it opens
   the same file picker as the Upload button. */
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  background: transparent; border: 0; color: var(--muted);
  font: inherit; cursor: pointer; transition: color .15s;
}
.empty-state:hover { color: var(--ink); }
.empty-state svg { width: 56px; height: 56px; opacity: .85; }
.empty-state span { font-size: 15px; letter-spacing: .3px; }

/* Controls panel: one card under the image, same width cap as the frame. */
.controls {
  width: 100%;
  max-width: 900px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 16px;
}
.ctrl-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }

/* Social ratio picker — a compact segmented control above the action row. */
.ratio-row { display: flex; justify-content: center; gap: 6px; width: 100%; margin-bottom: 10px; }
.ratio {
  font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 14px; transition: .15s;
}
.ratio:hover { border-color: var(--accent-2); color: #fff; }
.ratio.on { border-color: var(--accent-2); color: #fff; background: rgba(0, 229, 255, 0.12); box-shadow: 0 0 12px rgba(0, 229, 255, 0.25); }

/* Restrained secondary buttons (Upload, Record) — quiet outlines that defer to
   the primary CTA. */
.ctrl {
  flex: 0 1 auto; font: inherit; cursor: pointer; white-space: nowrap;
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 18px; font-size: 14px; transition: .15s;
}
.ctrl:hover:not(:disabled) { border-color: var(--accent-2); color: #fff; }
.ctrl:disabled { opacity: .4; cursor: default; }
.ctrl.active { border-color: var(--accent-2); color: #fff; box-shadow: 0 0 16px rgba(0, 229, 255, 0.35); }

/* Primary CTA: the pink accent stays reserved for Download Image. */
.ctrl.primary {
  background: linear-gradient(180deg, var(--accent), #c41f6a);
  border-color: transparent; color: #fff; font-weight: 700;
  padding: 11px 26px; box-shadow: var(--glow);
}
.ctrl.primary:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
.ctrl.recording { color: #fff; border-color: var(--accent); background: linear-gradient(180deg, #e01e5a, #8c0f38); animation: recpulse 1s ease-in-out infinite; }
@keyframes recpulse { 50% { box-shadow: var(--glow); } }

.ctrl-hint { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: .4px; text-align: center; }

/* Per-subject control popover — a small card anchored to a subject in the photo
   (positioned by main.js). Floats over the stage frame above the overlay. */
.subject-pop {
  position: absolute; z-index: 3; width: max-content; max-width: 220px;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border-radius: 12px;
  background: rgba(16, 16, 24, 0.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
}
.subject-pop-head { display: flex; align-items: center; gap: 6px; }
.subject-pop-name {
  flex: 1 1 auto; min-width: 0; font: inherit; font-size: 13px; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px;
}
.subject-pop-name:focus { outline: none; border-color: var(--accent-2); }
.subject-pop-x {
  flex: 0 0 auto; font: inherit; font-size: 13px; line-height: 1; cursor: pointer;
  color: var(--muted); background: transparent; border: 0; padding: 4px 6px; border-radius: 7px;
}
.subject-pop-x:hover { color: #fff; }
.subject-pop-acts { display: flex; gap: 6px; }
.subject-pop-btn {
  flex: 1 1 0; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
  color: var(--muted); background: transparent;
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; transition: .15s;
}
.subject-pop-btn:hover { border-color: var(--accent-2); color: #fff; }
.subject-pop-btn.on { border-color: var(--accent-2); color: #fff; background: rgba(0, 229, 255, 0.14); box-shadow: 0 0 12px rgba(0, 229, 255, 0.22); }
.subject-pop-foot {
  font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
  color: var(--muted); background: transparent;
  border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; transition: .15s;
}
.subject-pop-foot:hover { border-color: var(--accent-2); color: #fff; }

/* Toasts: top-center so they never collide with the bottom controls panel. */
.toast-host { position: fixed; top: calc(16px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 50; }
.toast {
  background: #2a0d1a; border: 1px solid var(--accent); color: #ffd5e6;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--glow);
  opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.in { opacity: 1; }

/* Phones: stack the controls full-width, lead with the primary CTA. The stacked
   column is tall, so let the page scroll and pin the image a solid share of the
   viewport — otherwise the frame (whose only children are absolute) collapses to
   the leftover space and the photo shrinks to a small letterboxed square. */
@media (max-width: 520px) {
  body.editor { overflow-y: auto; }
  .stage-frame { min-height: 56dvh; }
  .ctrl-row { flex-direction: column; align-items: stretch; }
  .ctrl { width: 100%; text-align: center; }
  .ctrl.primary { order: -1; }
  .ratio-row { flex-wrap: wrap; }
  .ratio { flex: 1 1 auto; }
}
