/*
 * Face Beautifier Auto — styles.
 *
 * Layout note: the canvas is sized in script, not by `aspect-ratio`. A flex
 * or grid item that grows has a definite size on both axes, which makes
 * `aspect-ratio` inert and renders the video stretched — and the stretch
 * looks like a renderer bug rather than a CSS one. The stage here only
 * centres; `fitCanvas()` in main.js does the fitting from a measured box.
 */

:root {
  --bg: #0e1116;
  --bg-elev: #161b23;
  --bg-elev-2: #1d2430;
  --line: #2a3240;
  --text: #e7ecf3;
  --text-dim: #9aa6b8;
  --accent: #6ee7b7;
  --accent-ink: #05130d;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --panel-w: 330px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f6;
    --bg-elev: #ffffff;
    --bg-elev-2: #f4f6fa;
    --line: #d6dce6;
    --text: #17202e;
    --text-dim: #5b687c;
    --accent: #0f9d76;
    --accent-ink: #ffffff;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 8px; top: 8px; z-index: 50;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 12px; border-radius: 8px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.topbar h1 span { color: var(--accent); }

.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.badge.ok { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.badge.err { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.icon-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
}
body.panel-hidden .layout { grid-template-columns: 1fr 0; }
body.panel-hidden .panel { display: none; }

.stage {
  min-width: 0;
  min-height: 0;
  /* A column that centres, with the caption in normal flow beneath the
     picture. `.stage-inner` never grows, so its size stays the one
     `fitCanvas` computed and nothing here has a ratio to resolve. */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 70%),
    var(--bg);
}

.stage-inner {
  position: relative;
  /* Sized in script; both axes are set explicitly so nothing here needs to
     resolve a ratio. */
  flex: 0 0 auto;
  line-height: 0;
  max-width: 100%;
}

canvas#output {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: #000;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.stage-hint {
  flex: 0 0 auto;
  max-width: 60ch;
  margin: 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
}

.split-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 26px;
  margin-left: -13px;
  cursor: ew-resize;
  touch-action: none;
}
.split-handle::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-radius: var(--radius);
  backdrop-filter: blur(3px);
  line-height: 1.5;
}
.overlay[hidden] { display: none; }
.overlay-card {
  max-width: 34ch;
  padding: 20px 22px;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.overlay-card p { margin: 0 0 12px; }
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- panel ---------- */
.panel {
  overflow-y: auto;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  padding: 4px 16px 24px;
  scrollbar-width: thin;
}
.group {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.group h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: inline;
}
details.group > summary {
  cursor: pointer;
  list-style: none;
  padding: 0 0 6px;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before { content: "▸ "; color: var(--text-dim); }
details.group[open] > summary::before { content: "▾ "; }

.presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.presets button {
  padding: 9px 8px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.presets button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.segmented { display: flex; gap: 4px; background: var(--bg-elev-2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.segmented button {
  flex: 1;
  padding: 7px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
}
.segmented button[aria-checked="true"] { background: var(--bg); color: var(--text); font-weight: 600; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 12px 0 4px;
  font-size: 13px;
}
.row span { color: var(--text-dim); }
.row output { color: var(--text); }
.row .auto-tag {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 0 0 4px;
}

select, .btn {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.btn { cursor: pointer; margin-top: 10px; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }

.check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin: 9px 0;
  font-size: 13px;
  cursor: pointer;
}
.check input { margin: 3px 0 0; accent-color: var(--accent); flex: 0 0 auto; }

.hint { margin: 8px 0 0; font-size: 12px; color: var(--text-dim); }
.hint em { color: var(--text); font-style: normal; font-weight: 600; }

.link {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-size: inherit;
  cursor: pointer; text-decoration: underline;
}

.panel-foot { padding-top: 14px; font-size: 11.5px; color: var(--text-dim); }
.panel-foot p { margin: 0 0 6px; }
.panel-foot a { color: var(--accent); }

/* ---------- narrow ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  body { overflow: auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .stage { padding: 12px; }
  .topbar { flex-wrap: wrap; gap: 8px 10px; }
  .topbar h1 { font-size: 15px; flex: 1 1 auto; }
  /* Keep the toggle on the title's line and let the badges wrap below it,
     rather than stranding the button on a row of its own. */
  .topbar .icon-btn { order: 1; }
  .badges { order: 2; width: 100%; margin-left: 0; }
  .badge { font-size: 11px; }
  body.panel-hidden .layout { grid-template-columns: 1fr; }
}
