:root{
  --bg:#0A0A0B;
  --bg-soft:#111113;
  --surface:#18181B;
  --surface-2:#212124;
  --border:#2C2C30;
  --border-soft:#232326;
  --text:#F1F1EF;
  --text-dim:#8C8C90;
  --text-faint:#5C5C61;
  --glow: rgba(255,255,255,.06);
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset;
  color-scheme: dark;
}
:root[data-theme="light"]{
  --bg:#F3F2EF;
  --bg-soft:#ECEBE7;
  --surface:#FFFFFF;
  --surface-2:#F5F4F1;
  --border:#DEDCD5;
  --border-soft:#E7E5E0;
  --text:#17171A;
  --text-dim:#6C6C72;
  --text-faint:#9A9A9E;
  --glow: rgba(0,0,0,.04);
  --shadow: 0 1px 0 rgba(0,0,0,.02) inset;
  color-scheme: light;
}
@media (prefers-color-scheme: light){
  :root:not([data-theme]){
    --bg:#F3F2EF; --bg-soft:#ECEBE7; --surface:#FFFFFF; --surface-2:#F5F4F1;
    --border:#DEDCD5; --border-soft:#E7E5E0; --text:#17171A; --text-dim:#6C6C72; --text-faint:#9A9A9E;
    --glow: rgba(0,0,0,.04); --shadow: 0 1px 0 rgba(0,0,0,.02) inset;
    color-scheme: light;
  }
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
body{
  background:var(--bg);
  color:var(--text);
  font-family:'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing:antialiased;
  min-height:100vh;
}
.mono{ font-family:'JetBrains Mono', ui-monospace, SFMono-Regular, monospace; }
.dim{ color:var(--text-dim); }
.small{ font-size:11px; }
.truncate{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.hidden{ display:none !important; }
.sr-only{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }
::selection{ background:var(--text); color:var(--bg); }

.shell{ max-width:1360px; margin:0 auto; padding:20px 18px 96px; }
@media(min-width:768px){ .shell{ padding:32px 32px 48px; } }

/* ---------- Header ---------- */
.topbar{ display:flex; align-items:center; margin-bottom:18px; }
.brand{ display:flex; align-items:center; gap:11px; color:var(--text); }
.brand-name{ font-family:'Space Grotesk', sans-serif; font-size:17px; font-weight:700; letter-spacing:-0.01em; margin:0; line-height:1.1; }
.brand-tag{ font-size:11px; color:var(--text-dim); margin:3px 0 0; font-family:'JetBrains Mono', monospace; }
@media(min-width:768px){ .topbar{ margin-bottom:26px; } .brand-name{ font-size:19px; } }

/* ---------- Tabbar ---------- */
.tabbar{
  display:flex; gap:4px; background:var(--surface); border:1px solid var(--border);
  border-radius:14px; padding:4px; margin-bottom:22px; box-shadow:var(--shadow);
}
.tab-btn{
  flex:1; display:flex; align-items:center; justify-content:center; gap:7px;
  background:transparent; border:none; border-radius:10px; padding:10px 8px;
  color:var(--text-dim); font-size:13px; font-weight:500; font-family:inherit;
  cursor:pointer; transition:background-color .15s ease, color .15s ease;
}
.tab-btn:hover{ color:var(--text); }
.tab-btn.is-active{ background:var(--surface-2); color:var(--text); box-shadow:var(--shadow); }
.tab-icon{ flex-shrink:0; }

@media(max-width:640px){
  .shell{ padding-bottom:104px; }
  .tabbar{
    position:fixed; left:12px; right:12px; bottom:12px; z-index:40;
    margin-bottom:0; padding:6px; border-radius:18px;
    backdrop-filter:blur(14px); background:color-mix(in srgb, var(--surface) 88%, transparent);
  }
  .tab-btn{ flex-direction:column; gap:4px; padding:8px 4px 7px; font-size:10.5px; }
}

/* ---------- Panels ---------- */
.panel{ display:none; }
.panel.is-active{ display:block; }

/* ---------- Cards ---------- */
.card{
  background:var(--surface); border:1px solid var(--border); border-radius:14px;
  padding:18px; box-shadow:var(--shadow);
}
.card + .card{ margin-top:18px; }
.card-title{ font-family:'Space Grotesk', sans-serif; font-size:14px; font-weight:600; margin:0 0 4px; }
.card-title-row{ display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.card-title-row .card-title{ margin:0; }
.card-sub{ font-size:12.5px; color:var(--text-dim); line-height:1.55; margin:0 0 14px; }

/* ---------- Layouts ---------- */
.grid-layout{ display:grid; grid-template-columns:1fr; gap:18px; }
@media(min-width:1024px){ .grid-layout{ grid-template-columns:380px 1fr; align-items:start; } }
.grid-settings{ display:grid; grid-template-columns:1fr; gap:18px; }
@media(min-width:768px){ .grid-settings{ grid-template-columns:1fr 1fr; } }
.span-2{ grid-column:1 / -1; }

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  border-radius:10px; font-size:13px; font-weight:600; font-family:inherit;
  padding:10px 16px; cursor:pointer; border:1px solid transparent; transition:opacity .15s ease, filter .15s ease;
}
.btn-block{ width:100%; }
.btn-small{ padding:7px 11px; font-size:11.5px; font-weight:500; }
.btn-primary{ background:var(--text); color:var(--bg); margin-top:14px; }
.btn-primary:hover{ filter:brightness(.92); }
.btn-primary:disabled{ opacity:.32; cursor:not-allowed; filter:none; }
.btn-ghost{ background:transparent; border-color:var(--border); color:var(--text); }
.btn-ghost:hover{ border-color:var(--text-faint); background:var(--surface-2); }

/* ---------- Upload ---------- */
.drop-zone{
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px;
  border:1.5px dashed var(--border); border-radius:12px; padding:30px 16px; text-align:center;
  cursor:pointer; color:var(--text-dim); transition:border-color .15s ease, background-color .15s ease;
}
.drop-zone:hover, .drop-zone.drag{ border-color:var(--text-faint); background:var(--surface-2); color:var(--text); }
.drop-zone span:first-of-type{ font-size:13px; font-weight:500; color:var(--text); }
.source-info{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  background:var(--surface-2); border:1px solid var(--border-soft); border-radius:10px;
  padding:9px 12px; margin-top:12px; font-size:11.5px;
}
.res-note{ margin:8px 0 0; }
.res-note strong{ color:var(--text); font-weight:500; }

/* ---------- Progress ---------- */
.progress-wrap{ margin-top:14px; }
.progress-track{ height:5px; border-radius:99px; background:var(--border); overflow:hidden; }
.progress-fill{ height:100%; width:0%; background:var(--text); transition:width .2s ease; }
.progress-wrap p{ margin:7px 0 0; }

/* ---------- Faces grid ---------- */
.faces-grid{ display:grid; grid-template-columns:repeat(3, 1fr); gap:10px; }
.face-thumb{
  background:var(--surface-2); border:1px solid var(--border-soft); border-radius:10px;
  padding:8px; display:flex; flex-direction:column; align-items:center; gap:6px;
}
.face-thumb img{ width:100%; aspect-ratio:1; object-fit:cover; border-radius:6px; }
.face-thumb .flabel{ font-size:10px; color:var(--text-dim); }
.face-thumb .btn{ width:100%; }
.hint-block{ margin:16px 0 0; line-height:1.6; }
.hint-block strong{ color:var(--text); font-weight:500; }

/* ---------- 3D Preview ---------- */
.preview-card{ position:relative; padding:0; overflow:hidden; height:min(70vh, 620px); }
.canvas-wrap{ position:absolute; inset:0; }
#dome-canvas{ touch-action:none; cursor:grab; display:block; }
#dome-canvas.grabbing{ cursor:grabbing; }
.empty-state{ position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; color:var(--text-faint); pointer-events:none; }
.empty-state.hidden{ display:none; }
.starfield{ position:absolute; inset:0; overflow:hidden; }
.star{ position:absolute; border-radius:50%; background:var(--text-dim); }
.preview-hint{
  position:absolute; bottom:16px; left:50%; transform:translateX(-50%);
  background:var(--surface-2); border:1px solid var(--border-soft); border-radius:99px;
  padding:7px 14px; font-size:11px; font-family:'JetBrains Mono', monospace; color:var(--text-dim);
  display:flex; align-items:center; gap:7px;
}
.preview-badge{
  position:absolute; top:14px; left:14px; font-size:10.5px; padding:4px 10px; border-radius:99px;
  background:var(--surface-2); border:1px solid var(--border-soft);
}

/* ---------- History ---------- */
.history-list{ display:flex; flex-direction:column; gap:8px; }
.history-row{
  display:flex; align-items:center; gap:12px; padding:9px; border-radius:10px;
  background:var(--surface-2); border:1px solid var(--border-soft);
}
.history-row img{ width:44px; height:44px; border-radius:8px; object-fit:cover; flex-shrink:0; }
.history-meta{ flex:1; min-width:0; }
.history-meta .h-date{ font-size:12.5px; font-weight:500; }
.history-meta .h-sub{ font-size:11px; color:var(--text-dim); margin-top:1px; }
.history-del{
  background:transparent; border:1px solid var(--border); color:var(--text-dim);
  width:28px; height:28px; border-radius:8px; display:flex; align-items:center; justify-content:center;
  cursor:pointer; flex-shrink:0;
}
.history-del:hover{ color:var(--text); border-color:var(--text-faint); }
.empty-block{ display:flex; flex-direction:column; align-items:center; gap:8px; padding:34px 10px; color:var(--text-faint); text-align:center; }

/* ---------- Settings inputs ---------- */
.seg-group{ display:flex; gap:6px; }
.seg-btn{
  flex:1; background:var(--surface-2); border:1px solid var(--border-soft); color:var(--text-dim);
  border-radius:9px; padding:9px 6px; font-size:12.5px; font-weight:500; font-family:inherit; cursor:pointer;
  transition:border-color .15s ease, color .15s ease, background-color .15s ease;
}
.seg-btn:hover{ color:var(--text); }
.seg-btn.is-active{ background:var(--text); color:var(--bg); border-color:var(--text); }
.text-input{
  width:100%; background:var(--surface-2); border:1px solid var(--border-soft); color:var(--text);
  border-radius:9px; padding:10px 12px; font-size:13px; font-family:inherit;
}
.text-input:focus{ outline:2px solid var(--text-faint); outline-offset:1px; }

/* ---------- Focus ---------- */
button:focus-visible, a:focus-visible, input:focus-visible, label:focus-within{
  outline:2px solid var(--text-faint); outline-offset:2px;
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration:.001ms !important; transition-duration:.001ms !important; }
}
