/* ============================================================
   ApkMorph — Ultra-sleek Dark Glassmorphic PWA
   Zinc-950 base · Indigo/Violet glow · Mobile-first
   ============================================================ */

:root {
  --bg: #09090b;            /* zinc-950 */
  --bg-2: #0c0c0f;
  --panel: rgba(24, 24, 27, 0.55);
  --panel-solid: #161619;
  --border: rgba(99, 102, 241, 0.28);
  --border-soft: rgba(255, 255, 255, 0.07);
  --indigo: #6366f1;
  --violet: #a855f7;
  --accent-grad: linear-gradient(135deg, #6366f1, #a855f7);
  --text: #e4e4e7;
  --muted: #a1a1aa;
  --muted-2: #71717a;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --gold: #d4af37;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-glow: 0 0 0 1px var(--border), 0 8px 40px -12px rgba(99, 102, 241, 0.45);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 64px; /* room for fixed footer */
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Ambient animated aurora background */
.aurora {
  position: fixed;
  inset: -30% -10% auto -10%;
  height: 70vh;
  background:
    radial-gradient(40% 50% at 20% 20%, rgba(99, 102, 241, 0.22), transparent 60%),
    radial-gradient(35% 45% at 80% 10%, rgba(168, 85, 247, 0.20), transparent 60%),
    radial-gradient(30% 40% at 60% 60%, rgba(56, 189, 248, 0.10), transparent 60%);
  filter: blur(40px);
  z-index: 0;
  pointer-events: none;
  animation: auroraShift 18s ease-in-out infinite alternate;
}
@keyframes auroraShift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(0, 20px, 0) scale(1.08); }
}

/* ============ HEADER ============ */
.app-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid var(--border);
  box-shadow: 0 0 24px -6px rgba(99, 102, 241, 0.6);
}
.logo-text {
  margin: 0;
  font-size: clamp(22px, 4.5vw, 30px);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #c7d2fe, #a855f7 55%, #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 28px rgba(139, 92, 246, 0.45);
}
.subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.35);
  font-size: 12.5px;
  font-weight: 600;
  color: #bbf7d0;
  white-space: nowrap;
}
.status-light {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  70%  { box-shadow: 0 0 0 9px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ============ LAYOUT GRID ============ */
.app-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr) minmax(300px, 380px);
  gap: 20px;
  padding: 8px clamp(16px, 4vw, 40px) 40px;
  align-items: start;
}
.col-left { display: flex; flex-direction: column; gap: 20px; }
.col-center { position: sticky; top: 14px; }
.col-right { display: flex; flex-direction: column; gap: 20px; }

/* ============ PANELS ============ */
.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-glow);
  position: relative;
  overflow: hidden;
}
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(160deg, rgba(99,102,241,0.5), rgba(168,85,247,0.15) 40%, transparent 70%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.8;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head.clickable { cursor: pointer; user-select: none; }
.panel-title {
  margin: 0; font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
  display: flex; align-items: center; gap: 9px; color: #f4f4f5;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.8);
}

/* ============ TABS ============ */
.tabs {
  display: flex; gap: 6px; padding: 4px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  margin-bottom: 14px;
}
.tab-btn {
  flex: 1; padding: 9px 10px; border: 0; cursor: pointer;
  background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; border-radius: 9px;
  transition: all 0.25s ease;
}
.tab-btn.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 4px 16px -4px rgba(99, 102, 241, 0.7);
}
.tab-panel { display: none; animation: fadeUp 0.3s ease; }
.tab-panel.active { display: block; }

/* ============ INPUTS ============ */
.field-label {
  display: block; font-size: 12px; color: var(--muted);
  margin: 10px 0 6px; font-weight: 500;
}
.text-input, .num-input {
  width: 100%; padding: 11px 13px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px; font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.text-input::placeholder { color: var(--muted-2); }
.text-input:focus, .num-input:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.hint { font-size: 11.5px; color: var(--muted-2); margin: 8px 0 0; line-height: 1.5; }
.inline-num { display: flex; align-items: center; gap: 6px; }
.num-input { width: 80px; text-align: center; }
.unit { font-size: 12px; color: var(--muted); }

/* ============ DROPZONE ============ */
.dropzone {
  border: 1.5px dashed rgba(99, 102, 241, 0.4);
  border-radius: var(--radius-sm);
  padding: 26px 16px;
  text-align: center;
  background: rgba(99, 102, 241, 0.04);
  transition: all 0.25s ease;
  cursor: pointer;
}
.dropzone.dragover {
  border-color: var(--violet);
  background: rgba(168, 85, 247, 0.12);
  transform: scale(1.01);
}
.dz-icon { font-size: 26px; color: var(--indigo); }
.dz-main { margin: 10px 0 2px; font-size: 14px; font-weight: 600; }
.dz-sub { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
.file-info {
  margin-top: 12px; padding: 10px 12px;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: var(--radius-sm);
  font-size: 12.5px; color: #bbf7d0;
}

/* ============ BUTTONS ============ */
.btn-primary, .btn-secondary, .btn-ghost {
  font-family: var(--font); font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); font-size: 13.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  transition: transform 0.15s ease, box-shadow 0.25s ease, background 0.25s ease, opacity 0.2s;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  padding: 12px 18px;
  box-shadow: 0 8px 28px -8px rgba(99, 102, 241, 0.8);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 34px -8px rgba(139, 92, 246, 0.9); }
.btn-secondary {
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
  color: var(--text);
  padding: 12px 16px;
}
.btn-secondary:hover { background: rgba(99,102,241,0.12); }
.btn-ghost {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-soft);
  color: var(--muted);
  padding: 8px 13px;
  font-size: 12.5px;
}
.btn-ghost:hover { color: #fff; border-color: var(--border); }
.btn-primary.block, .btn-ghost.block { width: 100%; margin-top: 14px; }
.sm { padding: 7px 12px; font-size: 12px; }
button:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; }

.btn-spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  display: none;
  animation: spin 0.7s linear infinite;
}
button.loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ SWITCHES ============ */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; }
.row-between + .row-between { border-top: 1px solid var(--border-soft); }
.row-title { font-size: 13.5px; font-weight: 600; }
.row-sub { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--border-soft);
  border-radius: 999px; transition: 0.3s;
}
.slider::before {
  content: ""; position: absolute; height: 18px; width: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.3s;
}
.switch input:checked + .slider {
  background: var(--accent-grad);
  border-color: transparent;
  box-shadow: 0 0 14px -2px rgba(139,92,246,0.8);
}
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ============ SUB GROUPS ============ */
.sub-group {
  margin-top: 6px; padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}
.group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--violet); font-weight: 700; margin-bottom: 6px;
}
.color-input {
  width: 44px; height: 30px; padding: 0; border: 1px solid var(--border-soft);
  border-radius: 8px; background: transparent; cursor: pointer;
}
.file-btn { position: relative; overflow: hidden; }

/* icon preview */
.icon-preview-wrap { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.icon-preview {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--accent-grad);
  background-size: cover; background-position: center;
  border: 1px solid var(--border);
  box-shadow: 0 0 18px -4px rgba(139,92,246,0.7);
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 20px;
}
.icon-preview-note { font-size: 11.5px; color: var(--muted-2); }

/* ============ DEVICE CANVAS ============ */
.canvas-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 12px;
}
.canvas-title { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.inspect-toggle { cursor: pointer; }
.inspect-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border-soft); color: var(--muted);
  transition: 0.25s;
}
.inspect-toggle input { display: none; }
.inspect-toggle input:checked + .inspect-pill {
  background: rgba(168,85,247,0.18); border-color: var(--violet); color: #fff;
  box-shadow: 0 0 16px -4px rgba(168,85,247,0.8);
}

.phone-stage { display: flex; justify-content: center; }

.phone {
  position: relative;
  width: min(320px, 86vw);
  aspect-ratio: 9 / 19;
  background: linear-gradient(160deg, #1c1c22, #0a0a0c);
  border-radius: 42px;
  padding: 12px;
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.06),
    0 0 0 8px #050506,
    0 30px 70px -20px rgba(99,102,241,0.45);
  border: 1px solid rgba(255,255,255,0.08);
}
.notch {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 42%; height: 22px; background: #050506; border-radius: 0 0 16px 16px; z-index: 4;
}
.statusbar {
  position: absolute; top: 16px; left: 22px; right: 22px; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; color: #fff; font-weight: 600; pointer-events: none;
}
.sb-right { display: flex; align-items: center; gap: 6px; }
.sb-signal { letter-spacing: -2px; font-size: 9px; }

.screen {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 32px; overflow: hidden;
  background: #000;
}
#deviceIframe { width: 100%; height: 100%; border: 0; background: #0b1020; display: block; }

.inspect-overlay {
  position: absolute; inset: 0; z-index: 6;
  pointer-events: none;
  background:
    repeating-linear-gradient(45deg, rgba(168,85,247,0.06) 0 12px, transparent 12px 24px);
  opacity: 0; transition: opacity 0.25s;
}
.inspect-overlay.on {
  pointer-events: auto; opacity: 1; cursor: crosshair;
  box-shadow: inset 0 0 0 2px rgba(168,85,247,0.6);
}
.inspect-box {
  position: absolute; z-index: 7; pointer-events: none;
  border: 2px solid #a855f7; border-radius: 4px;
  box-shadow: 0 0 0 4000px rgba(9,9,11,0.35);
  transition: all 0.12s ease;
}
.inspect-box::after {
  content: "selected"; position: absolute; top: -20px; left: -2px;
  font-size: 10px; background: #a855f7; color: #fff; padding: 1px 6px; border-radius: 4px;
}
.inspect-tip {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  z-index: 8; font-size: 11.5px; color: #fff;
  background: rgba(9,9,11,0.85); padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--violet); white-space: nowrap;
}

.splash {
  position: absolute; inset: 0; z-index: 9;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: var(--bg);
  animation: splashIn 0.4s ease;
}
@keyframes splashIn { from { opacity: 0; } to { opacity: 1; } }
.splash-logo { width: 96px; height: 96px; border-radius: 22px; object-fit: cover; box-shadow: 0 0 40px -8px rgba(139,92,246,0.8); }
.splash-name { font-size: 16px; font-weight: 700; color: var(--text); }

/* Inspect readout */
.inspect-readout {
  margin-top: 14px; width: min(320px, 86vw);
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
}
.ir-head { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; font-weight: 700; color: #f4f4f5; }
.ir-close { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
.ir-code {
  margin: 10px 0; font-family: var(--mono); font-size: 11px; color: #c4b5fd;
  background: #000; border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 10px; max-height: 130px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.ir-actions { display: flex; gap: 8px; }

/* ============ CONSOLE ============ */
.console-panel { display: flex; flex-direction: column; }
.chevron { color: var(--muted); transition: transform 0.3s; font-size: 14px; }
.console-body { transition: max-height 0.35s ease, opacity 0.25s; overflow: hidden; }
.console-body.collapsed { max-height: 0 !important; opacity: 0; }
.console-output {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.7;
  background: #050506; border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 12px;
  height: 280px; overflow-y: auto;
}
.log-line { display: flex; gap: 8px; animation: fadeUp 0.25s ease; }
.log-time { color: var(--muted-2); flex: none; }
.log-msg { color: var(--text); }
.log-info .log-msg { color: #c4b5fd; }
.log-success .log-msg { color: #86efac; }
.log-warn .log-msg { color: #fcd34d; }
.log-error .log-msg { color: #fca5a5; }
.log-line::before { content: "›"; color: var(--indigo); flex: none; }

/* progress */
.progress-wrap { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.progress-track { flex: 1; height: 8px; background: rgba(255,255,255,0.07); border-radius: 999px; overflow: hidden; }
.progress-bar {
  height: 100%; width: 0%;
  background: var(--accent-grad);
  background-size: 200% 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.progress-label { font-size: 12px; color: var(--muted); font-family: var(--mono); min-width: 38px; text-align: right; }

.action-toolbar { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ============ FOOTER ============ */
.app-footer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  text-align: center;
  padding: 14px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--gold);
  background: linear-gradient(to top, rgba(9,9,11,0.96), rgba(9,9,11,0.0));
  text-shadow: 0 0 14px rgba(212,175,55,0.25);
  letter-spacing: 0.02em;
  border-top: 1px solid rgba(212,175,55,0.12);
  backdrop-filter: blur(6px);
}

/* ============ TOASTS ============ */
.toast-stack {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  z-index: 50; display: flex; flex-direction: column; gap: 10px; align-items: center;
  width: max-content; max-width: 92vw;
}
.toast {
  padding: 11px 18px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: var(--panel-solid); border: 1px solid var(--border);
  box-shadow: var(--shadow-glow); color: var(--text);
  animation: toastIn 0.3s ease; display: flex; align-items: center; gap: 9px;
}
.toast.success { border-color: rgba(34,197,94,0.5); }
.toast.error { border-color: rgba(239,68,68,0.5); }
.toast.info { border-color: rgba(99,102,241,0.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.toast.out { opacity: 0; transform: translateY(12px); transition: 0.3s; }

/* ============ ANIMATIONS ============ */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.reveal { opacity: 0; animation: fadeUp 0.6s ease forwards; }
.reveal:nth-child(1) { animation-delay: 0.05s; }
.reveal:nth-child(2) { animation-delay: 0.12s; }
.reveal:nth-child(3) { animation-delay: 0.19s; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1080px) {
  .app-grid { grid-template-columns: 1fr; }
  .col-center { position: static; order: 2; }
  .col-left { order: 1; }
  .col-right { order: 3; }
}
@media (max-width: 520px) {
  .app-header { padding: 14px 16px; }
  .status-badge .status-label { display: none; }
  .status-badge { padding: 8px; }
  .action-toolbar { flex-direction: column; }
  .panel { padding: 15px; }
}

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