/* MirrorLook — dark, product-grade layout. Desktop: side panel. Phone: bottom sheet. */

:root {
  --bg: #0b0b0f;
  --surface: #14141b;
  --surface-2: #1c1c25;
  --surface-3: #252532;
  --border: #2b2b38;
  --text: #f3f1f6;
  --muted: #9b99a8;
  --accent: #ff5c8a;
  --accent-strong: #ff3d73;
  --accent-soft: rgba(255, 92, 138, 0.16);
  --gold: #ffb86b;
  --danger: #ff6b6b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --topbar-h: 56px;
  --panel-w: 380px;
  --sheet-peek: 64px;
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- App frame ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "stage panel";
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.2px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, var(--gold), var(--accent) 60%, #7a5cff);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.mode-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  margin-inline: auto;
}
.mode-tab {
  min-width: 84px; height: 34px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); font-weight: 600;
}
.mode-tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

.topbar-actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text); font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, .swatch:focus-visible, .preset:focus-visible, .mode-tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: transparent; color: #1a0a10; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-pill { border-radius: 999px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); background: rgba(20, 20, 27, 0.75); }
.btn-pill.btn-primary { background: var(--accent); }
.btn[aria-pressed="true"]:not(.btn-primary) { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Stage ---------- */

.stage-wrap { grid-area: stage; min-width: 0; min-height: 0; display: flex; padding: 16px; }
.stage {
  position: relative; flex: 1; min-height: 0;
  border-radius: 18px; overflow: hidden;
  background: #000; box-shadow: var(--shadow);
}
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform: scaleX(-1); opacity: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; touch-action: none; }
.app[data-mode="photo"] #view { cursor: ew-resize; }

.fps {
  position: absolute; top: 12px; right: 12px; z-index: 3;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, 0.55); color: var(--muted);
}

.status {
  position: absolute; inset: 0; z-index: 4;
  display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(20, 20, 27, 0.7), rgba(11, 11, 15, 0.92));
}
.status-card {
  width: min(420px, 100%); padding: 22px 22px 18px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); text-align: center;
}
.status-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.status-text { color: var(--muted); font-size: 14px; white-space: pre-line; }
.status-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
.status-actions:empty { display: none; }
.progress { height: 6px; margin-top: 16px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--accent)); transition: width 0.15s; }

.dropzone { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; padding: 20px; }
.dropzone-inner {
  width: min(460px, 100%); padding: 32px 24px; text-align: center;
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: rgba(20, 20, 27, 0.6);
}
.dropzone-inner svg { width: 40px; height: 40px; color: var(--accent); margin-bottom: 8px; }
.dropzone-inner h2 { margin: 0 0 6px; font-size: 20px; }
.dropzone-inner p { margin: 0 0 16px; color: var(--muted); }
.dropzone-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.dropzone-fine { font-size: 12px; margin: 14px 0 0 !important; }
.app.dragging .dropzone-inner { border-color: var(--accent); background: var(--accent-soft); }

.hint {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%); z-index: 3;
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: rgba(0, 0, 0, 0.6); border: 1px solid var(--border); backdrop-filter: blur(8px);
  max-width: calc(100% - 32px); text-align: center;
}

.stage-bar {
  position: absolute; left: 0; right: 0; bottom: 14px; z-index: 3;
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 0 12px;
  pointer-events: none;
}
.stage-bar .btn { pointer-events: auto; }

.split-bar {
  position: absolute; left: 50%; bottom: 68px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  border-radius: 999px; background: rgba(20, 20, 27, 0.75); border: 1px solid var(--border);
  backdrop-filter: blur(12px); font-size: 12px; color: var(--muted); font-weight: 600;
  width: min(360px, calc(100% - 32px));
}
.split-bar input { flex: 1; }

.live-only, .photo-only { display: none; }
.app[data-mode="live"] .live-only { display: inline-flex; }
.app[data-mode="photo"] .photo-only { display: inline-flex; }
.app[data-mode="photo"] .split-bar.photo-only { display: flex; }
.app[data-mode="photo"]:not(.has-photo) .photo-only { display: none; }

/* ---------- Panel ---------- */

.panel {
  grid-area: panel; min-height: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--surface);
}
.panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 24px; overscroll-behavior: contain; }
.panel-section { padding: 14px 0 6px; border-bottom: 1px solid var(--border); }
.panel-section:last-of-type { border-bottom: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.sheet-handle { display: none; }

.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.preset {
  min-height: var(--tap); padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; text-align: left;
}
.preset:hover { background: var(--surface-3); }
.preset[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.preset-dots { display: flex; gap: 2px; flex-shrink: 0; }
.preset-dots i { width: 8px; height: 8px; border-radius: 50%; display: block; border: 1px solid rgba(0,0,0,0.3); }

.layers { display: flex; flex-direction: column; gap: 8px; }
.layer { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; }
.layer-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 8px; min-height: 50px; }
.layer-title {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: none; border: 0; padding: 6px 0; text-align: left; min-height: var(--tap);
}
.layer-name { font-weight: 600; }
.layer-hint { color: var(--muted); font-size: 12px; }
.layer-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--surface-3); box-shadow: 0 0 0 1px var(--border); }
.layer.is-off .layer-name { color: var(--muted); }
.layer.is-off .layer-dot { opacity: 0.35; }
.layer-body { display: none; padding: 4px 12px 14px; border-top: 1px solid var(--border); }
.layer.is-open .layer-body { display: block; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border);
  transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: transparent; }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 6px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;
  background: var(--c); box-shadow: 0 0 0 1px var(--border); padding: 0; position: relative;
}
.swatch:hover { transform: scale(1.06); }
.swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.swatch-custom { display: grid; place-items: center; background: conic-gradient(#ff5c8a, #ffb86b, #7ee787, #58a6ff, #bc8cff, #ff5c8a); }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.swatch-custom svg { width: 14px; height: 14px; color: #111; stroke-width: 2.4; pointer-events: none; }

.slider-row { display: grid; grid-template-columns: 70px 1fr 36px; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.slider-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--surface-3); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }

.seg { display: inline-flex; margin-top: 10px; padding: 3px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); }
.seg button { min-width: 72px; height: 32px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-height: 32px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.save-form { display: flex; gap: 8px; margin-bottom: 10px; }
.save-form input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
}
.saved { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.saved li { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.saved .saved-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved .btn-danger { color: var(--danger); }
.empty { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

.panel-foot { padding: 16px 0 0; color: var(--muted); font-size: 12px; }
.panel-foot p { margin: 0 0 4px; }
.fine { opacity: 0.8; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px;
  background: var(--surface-3); border: 1px solid var(--border); box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}
.toast.is-error { border-color: var(--danger); }

.drop-veil {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(11, 11, 15, 0.8); border: 3px dashed var(--accent); font-size: 22px; font-weight: 700;
  pointer-events: none;
}

.mobile-only { display: none; }

/* ---------- Phone layout: bottom sheet ---------- */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
    grid-template-areas: "top" "stage";
  }
  .mobile-only { display: inline-flex; }
  .topbar { gap: 8px; padding: 0 10px; }
  .brand-name { display: none; }
  .btn-ghost span { display: none; }
  .stage-wrap { padding: 0; }
  .stage { border-radius: 0; box-shadow: none; }
  .stage-bar { bottom: calc(var(--sheet-peek) + 12px + env(safe-area-inset-bottom)); }
  .split-bar { bottom: calc(var(--sheet-peek) + 66px + env(safe-area-inset-bottom)); }
  .btn-pill span { display: none; }
  .btn-pill { width: var(--tap); padding: 0; }
  .btn-pill#btn-compare { width: auto; padding: 0 16px; }
  .btn-pill#btn-compare span { display: inline; }

  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: min(72dvh, 640px);
    border-left: 0; border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0; box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(calc(100% - var(--sheet-peek) - env(safe-area-inset-bottom)));
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app.panel-open .panel { transform: translateY(0); }
  .sheet-handle {
    display: flex; align-items: center; justify-content: center;
    height: var(--sheet-peek); width: 100%; border: 0; background: transparent; position: relative;
    touch-action: none;
  }
  .sheet-handle span { width: 44px; height: 5px; border-radius: 999px; background: var(--border); }
  .sheet-handle::after {
    content: "Looks & layers"; position: absolute; bottom: 10px; font-size: 13px; font-weight: 600; color: var(--muted);
  }
  .app.panel-open .sheet-handle::after { content: "Preview"; }
  .panel-scroll { padding: 0 14px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
