/* ── RESET ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --g: #00e5a0;          /* accent green */
  --g2: rgba(0,229,160,.15);
  --bg: #08080f;
  --sf: rgba(12,12,22,.82);
  --sf2: rgba(255,255,255,.07);
  --br: rgba(255,255,255,.10);
  --tx: #f0f0f8;
  --tx2: rgba(240,240,248,.52);
  --r: 14px;
  --sb: env(safe-area-inset-bottom, 0px);
  --st: env(safe-area-inset-top,    0px);
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, 'Segoe UI', Tahoma, sans-serif;
  color: var(--tx);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}

/* ── SPLASH ─────────────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 999;
  background: radial-gradient(ellipse at 50% 60%, #0d1f30 0%, #08080f 70%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease;
}
#splash.out { opacity: 0; pointer-events: none; }

.splash-inner {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.splash-icon {
  width: 88px; height: 88px;
  background: rgba(0,229,160,.10);
  border: 1px solid rgba(0,229,160,.28);
  border-radius: 26px;
  display: flex; align-items: center; justify-content: center;
  animation: glow 2.4s ease-in-out infinite;
}
@keyframes glow {
  0%,100% { box-shadow: 0 0 18px rgba(0,229,160,.18); }
  50%      { box-shadow: 0 0 38px rgba(0,229,160,.45); }
}
.splash-inner h1 {
  font-size: 26px; font-weight: 700;
  background: linear-gradient(130deg,#fff,var(--g));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.splash-inner p { font-size: 13px; color: var(--tx2); }

.splash-bar-wrap { width: 220px; display: flex; flex-direction: column; gap: 7px; }
.splash-bar {
  height: 3px; background: rgba(255,255,255,.1); border-radius: 99px; overflow: hidden;
}
#splash-fill {
  height: 100%; width: 0%; background: var(--g); border-radius: 99px;
  transition: width .25s ease;
  box-shadow: 0 0 8px var(--g);
}
#splash-msg { font-size: 12px; color: var(--tx2); }

/* ── APP LAYOUT ─────────────────────────── */
#app { position: fixed; inset: 0; }

/* ── CAMERA LAYERS ──────────────────────── */
#video,
#canvas-skeleton,
#canvas-ar {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
/* NO mirror — natural camera output */
#video            { z-index: 0; }
#canvas-skeleton  { z-index: 1; pointer-events: none; }
#canvas-ar        { z-index: 2; pointer-events: none; }

/* ── TOP BAR ────────────────────────────── */
#topbar {
  position: absolute; top: var(--st); left: 0; right: 0; z-index: 10;
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,.55) 0%, transparent 100%);
}

.ibtn {
  width: 40px; height: 40px; flex-shrink: 0;
  background: var(--sf); border: 1px solid var(--br); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--tx); cursor: pointer;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: background .15s;
}
.ibtn:active { background: var(--sf2); transform: scale(.92); }

#status-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--sf); border: 1px solid var(--br); border-radius: 99px;
  padding: 6px 14px; font-size: 12px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #444;
  flex-shrink: 0; transition: background .3s;
}
#status-dot.init     { background: #888; }
#status-dot.search   { background: #f5a623; animation: blink 1s ease infinite; }
#status-dot.found    { background: var(--g); }
#status-dot.manual   { background: #7b8cde; }
#status-dot.error    { background: #ff4c4c; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── GUIDE FRAME ────────────────────────── */
#guide {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
  transition: opacity .4s;
}
#guide.hidden { opacity: 0; }
.guide-box {
  width: 64vw; height: 54vw; max-width: 320px; max-height: 280px;
  border: 2px dashed rgba(0,229,160,.35);
  border-radius: 20px;
}
.guide-lbl {
  margin-top: 14px; font-size: 13px;
  color: rgba(0,229,160,.75);
  background: rgba(0,0,0,.45);
  padding: 5px 16px; border-radius: 99px;
}

/* ── ADJUSTMENT SLIDERS ─────────────────── */
#adj-panel {
  position: absolute; z-index: 8;
  left: 10px; right: 10px;
  bottom: calc(var(--sb) + 272px);
  display: flex; flex-direction: column; gap: 7px;
}
.adj-row {
  display: flex; align-items: center; gap: 9px;
  background: var(--sf); border: 1px solid var(--br); border-radius: 12px;
  padding: 8px 12px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.adj-row span { font-size: 11px; color: var(--tx2); width: 52px; flex-shrink: 0; text-align: right; }
.adj-row input[type=range] {
  flex: 1; height: 3px;
  -webkit-appearance: none; appearance: none;
  background: var(--br); border-radius: 99px; outline: none;
}
.adj-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  background: var(--g); border-radius: 50%;
  box-shadow: 0 0 6px rgba(0,229,160,.5);
  cursor: pointer;
}
.adj-row b { font-size: 11px; color: var(--g); width: 34px; text-align: left; font-weight: 600; }

/* ── SHOE PANEL ─────────────────────────── */
#shoe-panel {
  position: absolute; z-index: 9;
  left: 0; right: 0;
  bottom: 0;
  background: var(--sf);
  border-top: 1px solid var(--br);
  border-radius: 20px 20px 0 0;
  padding: 0 16px calc(16px + var(--sb));
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
}
.drag-bar {
  width: 34px; height: 4px; background: var(--br);
  border-radius: 2px; margin: 10px auto 12px;
}
.panel-head { font-size: 11px; color: var(--tx2); text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 12px; }

#shoe-row {
  display: flex; gap: 10px;
  overflow-x: auto; padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#shoe-row::-webkit-scrollbar { display: none; }

.shoe-card {
  flex-shrink: 0; width: 82px;
  background: var(--sf2); border: 1.5px solid var(--br);
  border-radius: 14px; padding: 9px 7px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; position: relative;
  transition: border-color .2s, background .2s, transform .15s;
}
.shoe-card.active { border-color: var(--g); background: var(--g2); }
.shoe-card:active { transform: scale(.94); }

.shoe-thumb { width: 58px; height: 42px; object-fit: contain; }
.shoe-thumb-ph {
  width: 58px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  opacity: .35;
}
.shoe-nm {
  font-size: 9px; color: var(--tx2); text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%;
}
.shoe-dot {
  position: absolute; top: 5px; right: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--g); display: none;
}
.shoe-card.active .shoe-dot { display: block; }

/* Add card */
.shoe-add {
  flex-shrink: 0; width: 82px; min-height: 72px;
  background: var(--sf2); border: 1.5px dashed var(--br);
  border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  cursor: pointer;
  transition: border-color .2s, transform .15s;
}
.shoe-add:active { transform: scale(.94); border-color: var(--g); }
.shoe-add span { font-size: 9px; color: var(--tx2); }

/* ── MODEL LOADING OVERLAY ──────────────── */
#model-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
#model-overlay[hidden] { display: none; }

.spinner {
  width: 46px; height: 46px;
  border: 3px solid rgba(0,229,160,.2);
  border-top-color: var(--g);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#model-overlay span { font-size: 14px; color: var(--tx2); }

/* ── SETTINGS SHEET ─────────────────────── */
#cfg-sheet {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end;
}
#cfg-sheet[hidden] { display: none; }

#cfg-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
}
#cfg-drawer {
  position: relative; z-index: 1; width: 100%;
  background: #0f0f1c; border-top: 1px solid var(--br);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--sb));
  max-height: 78vh; overflow-y: auto;
  animation: slideUp .28s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.cfg-hd {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.cfg-hd h2 { font-size: 18px; font-weight: 700; }
.cfg-sec { margin-bottom: 22px; }
.cfg-sec-title {
  font-size: 11px; color: var(--tx2);
  text-transform: uppercase; letter-spacing: 1.2px;
  margin-bottom: 10px;
}
.cfg-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--sf2); border-radius: 10px;
  padding: 11px 13px; font-size: 14px;
  cursor: pointer; margin-bottom: 6px;
}
.cfg-row input { accent-color: var(--g); }
.cfg-note { font-size: 12px; color: var(--tx2); margin-bottom: 10px; line-height: 1.6; }
.cfg-note code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.dl-link { color: var(--g); text-decoration: underline; display: inline-block; margin-top: 4px; }

.upload-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px;
  background: var(--g2); border: 1px solid rgba(0,229,160,.28);
  border-radius: 11px; color: var(--g); font-size: 14px;
  cursor: pointer; transition: background .15s;
}
.upload-btn:active { background: rgba(0,229,160,.26); }
#upload-msg { display: block; margin-top: 8px; font-size: 12px; color: var(--g); text-align: center; }

/* ── TOAST ──────────────────────────────── */
#toast {
  position: fixed; z-index: 300;
  bottom: calc(var(--sb) + 280px);
  left: 50%; transform: translateX(-50%);
  background: var(--sf); border: 1px solid var(--br);
  border-radius: 99px; padding: 9px 20px;
  font-size: 13px; white-space: nowrap;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
#toast.show { opacity: 1; }
