/* PrivaScale — mobile-first native app shell */
:root {
  --bg: #07070c;
  --surface: #12121c;
  --surface-2: #1b1b2a;
  --surface-3: #242438;
  --border: rgba(255, 255, 255, 0.08);
  --fg: #f4f4f8;
  --muted: #8e8ea3;
  --accent: #6c5cff;
  --accent-hover: #5a4ae6;
  --accent-soft: rgba(108, 92, 255, 0.16);
  --danger: #e55050;
  --danger-soft: rgba(229, 80, 80, 0.14);
  --success: #1dd1a1;
  --warn: #ffb86b;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 22px;
  --app-bar: 52px;
  --dock-pad: 12px;
  --ease-out: cubic-bezier(0.32, 0.72, 0, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
button {
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
}
a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── App shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg);
}

.app-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: calc(var(--app-bar) + var(--safe-top));
  padding: var(--safe-top) 12px 0 16px;
  background: rgba(7, 7, 12, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #7a6cff, #4f3fe0);
  flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.status-line {
  margin: 0.1rem 0 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.7rem;
  color: var(--muted);
}
.gpu-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  color: var(--muted);
}
.gpu-pill[data-state="ok"] { color: var(--success); background: rgba(29, 209, 161, 0.12); }
.gpu-pill[data-state="warn"] { color: var(--warn); background: rgba(255, 184, 107, 0.12); }
.gpu-pill[data-state="wait"] { color: var(--muted); }
.privacy-dot { color: var(--success); font-weight: 600; }
@media (max-width: 360px) {
  .privacy-dot { display: none; }
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.96); }

/* ── Screens: only one visible ── */
#screens {
  flex: 1;
  min-height: 0;
  position: relative;
}
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  min-height: 0;
}
#app[data-screen="home"] .screen-home,
#app[data-screen="workspace"] .screen-workspace {
  display: flex;
}

/* ── Buttons ── */
.btn {
  min-height: 48px;
  border-radius: 14px;
  padding: 0.7rem 1.1rem;
  font-weight: 650;
  font-size: 0.95rem;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--fg);
}
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #c93a3a; }
.dock-cta-big {
  min-height: 56px;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}
.dock-row .segmented { flex-shrink: 0; }
#process-btn { white-space: nowrap; }

select {
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.55rem 0.8rem;
  min-height: 48px;
}

.hint { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.78rem; text-align: center; }
.status-msg {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

/* ── Home ── */
.home-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1.25rem calc(1.5rem + var(--safe-bottom));
  text-align: center;
  min-height: 0;
}
.home-stage.dragover {
  background: var(--accent-soft);
}
.empty-mark {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  margin-bottom: 1rem;
}
.empty-title { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.03em; }
.empty-sub { margin: 0.35rem 0 1.25rem; color: var(--muted); font-size: 0.92rem; }

.home-cta { width: min(100%, 360px); min-height: 56px; font-size: 1.05rem; font-weight: 750; }

/* ── Workspace ── */
.screen-workspace { background: #050508; }
.viewer {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}
.compare {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.compare-stage {
  --split: 50%;
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background: #050508;
}
.compare-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
}
#output-canvas {
  clip-path: inset(0 0 0 var(--split));
}
.compare[data-mode="preview"] #output-canvas,
.compare[data-mode="preview"] .compare-handle,
.compare[data-mode="preview"] .compare-tag {
  display: none;
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split);
  width: 28px;
  transform: translateX(-50%);
  z-index: 3;
  cursor: ew-resize;
}
.compare-handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: #fff;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.45);
}
.compare-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  background-image:
    linear-gradient(#111, #111),
    linear-gradient(#111, #111);
  background-size: 2px 10px, 2px 10px;
  background-position: 13px 13px, 21px 13px;
  background-repeat: no-repeat;
}

.compare-tag {
  position: absolute;
  top: 10px;
  z-index: 2;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.22rem 0.45rem;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #fff;
  pointer-events: none;
}
.compare-tag-before { left: 10px; }
.compare-tag-after { right: 10px; }

/* Floating toolbar: mode switch + zoom controls */
.viewer-toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 8px;
  align-items: center;
}
.viewer-toolbar .icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(18, 18, 28, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.zoom-controls { display: none; gap: 8px; }
.compare[data-mode="preview"] .viewer-toolbar { display: none; }
.compare[data-mode="zoom"] .zoom-controls { display: flex; }
#icon-compare { display: none; }
.compare[data-mode="zoom"] #icon-compare { display: block; }
.compare[data-mode="zoom"] #icon-zoom { display: none; }

/* Zoom mode: only the output canvas, transformable */
.compare[data-mode="zoom"] #output-canvas { clip-path: none; cursor: grab; will-change: transform; }
.compare[data-mode="zoom"] #output-canvas.panning { cursor: grabbing; }
.compare[data-mode="zoom"] #original-canvas,
.compare[data-mode="zoom"] .compare-handle,
.compare[data-mode="zoom"] .compare-tag { display: none; }

.compare-caption {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.35rem 0.85rem;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--muted);
  min-height: 1.4em;
}
.compare-caption span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Progress overlay on viewer */
#progress {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  background: rgba(18, 18, 28, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  backdrop-filter: blur(16px);
}
#progress[hidden] { display: none !important; }
.progress-bar { height: 6px; background: #222230; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s ease; }
#status-text { margin: 0.55rem 0 0; font-weight: 650; font-size: 0.88rem; }
#progress-detail { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.78rem; }
#model-hint {
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface-2);
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
}
#model-hint[hidden] { display: none !important; }

/* ── Dock ── */
.dock {
  flex: 0 0 auto;
  padding: var(--dock-pad) 14px calc(var(--dock-pad) + var(--safe-bottom));
  background: rgba(12, 12, 20, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
}
.dock-panel { display: none; flex-direction: column; gap: 0.55rem; }
#app[data-dock="ready"] #dock-ready,
#app[data-dock="busy"] #dock-busy,
#app[data-dock="done"] #dock-done { display: flex; }

.dock-row { display: flex; align-items: center; gap: 0.55rem; }
.dock-cta { flex: 1; min-width: 0; }
#format-select { flex: 0 0 auto; max-width: 102px; }

.segmented {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  flex: 0 0 auto;
}
.segmented button {
  min-height: 42px;
  min-width: 52px;
  padding: 0 0.85rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  border-radius: 10px;
  cursor: pointer;
}
.segmented button.is-active {
  background: var(--surface-3);
  color: var(--fg);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
}
.segmented-block { width: 100%; }
.segmented-block button { flex: 1; }

#download-zip-btn[hidden] { display: none !important; }
.option-row[disabled] { opacity: 0.4; cursor: not-allowed; }
#model-cpu-note { margin: 0 0 0.5rem; }

/* ── Settings sheet ── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 40;
  opacity: 1;
  transition: opacity 0.22s var(--ease-out);
}
.sheet-overlay.hidden { display: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: min(92dvh, 740px);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  transition: transform 0.28s var(--ease-out);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
}
.sheet.hidden {
  transform: translateY(110%);
  pointer-events: none;
  visibility: hidden;
}
.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 99px;
  background: #3a3a50;
  margin: 0.55rem auto 0;
  flex-shrink: 0;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.7rem 0.55rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.sheet-header h2 { margin: 0; font-size: 1.05rem; }
.sheet-body {
  padding: 1rem 1.1rem 1.2rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field { display: flex; flex-direction: column; gap: 0.45rem; }
.field-note { margin: 0; color: var(--muted); font-size: 0.78rem; line-height: 1.45; }
.field-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.option-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  text-align: left;
}
.option-row:last-child { border-bottom: 0; }
.option-row.is-selected { background: var(--accent-soft); }
.option-title { font-weight: 650; font-size: 0.92rem; }
.option-hint { color: var(--muted); font-size: 0.78rem; }

.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  min-height: 48px;
  padding: 0.35rem 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.toggle-row small {
  display: block;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.75rem;
}
.toggle {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.toggle-ui {
  width: 48px;
  height: 30px;
  border-radius: 999px;
  background: var(--surface-3);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.toggle-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s var(--ease-out);
}
.toggle:checked + .toggle-ui { background: var(--accent); }
.toggle:checked + .toggle-ui::after { transform: translateX(18px); }
.toggle:focus-visible + .toggle-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

.advanced-body { display: flex; flex-direction: column; gap: 0.5rem; }

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 0.85rem;
  font-weight: 550;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}
.toast.hidden { display: none; }

/* ── Helpers ── */
.mobile-only { display: none; }
@media (max-width: 700px) {
  .mobile-only { display: inline; }
  .desktop-only { display: none; }
}

kbd {
  background: #222;
  border: 1px solid #333;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
}

/* ── Tablet / desktop ── */
@media (min-width: 768px) {
  #app {
    max-width: 480px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.45);
  }
  #app[data-screen="workspace"] { max-width: 640px; }
  body { background: #040407; }

  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(420px, 92vw);
    max-height: min(80vh, 640px);
    border-radius: 20px;
    transform: translate(-50%, -50%);
    padding-bottom: 0.4rem;
  }
  .sheet.hidden {
    transform: translate(-50%, calc(-50% + 16px)) scale(0.97);
    opacity: 0;
  }
  .sheet-handle { display: none; }
}

@media (min-width: 1100px) {
  #app[data-screen="workspace"] {
    max-width: 720px;
  }
}

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

@media (display-mode: standalone) {
  .app-bar { border-bottom-color: rgba(255, 255, 255, 0.06); }
}
