:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --brand: #3b82f6;
  --brand-2: #2563eb;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2340 0, transparent 60%), var(--bg);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 26, 33, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand-icon { color: var(--brand); flex: none; }
.brand span { vertical-align: middle; }
.brand-sub { color: var(--muted); font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 22px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 22px 48px;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.stage {
  position: relative;
  height: min(46vh, 440px);
  width: auto;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin-inline: auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #e9edf0;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.shirt-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  user-select: none;
  pointer-events: none;
}
.render-layer {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
  display: none;
}
.stage .canvas-container {
  position: absolute !important;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
.stage canvas { width: 100% !important; height: 100% !important; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 0; }

.panel { display: flex; flex-direction: column; gap: 16px; }
.group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.group h3 { margin: 0 0 12px; font-size: 15px; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 62px; height: 62px;
  border-radius: 12px;
  border: 2px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  background: #000;
  transition: border-color .15s, transform .1s;
}
.swatch img { width: 100%; height: 100%; object-fit: cover; }
.swatch:hover { transform: translateY(-2px); }
.swatch.active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(59,130,246,.35); }

.colors { display: flex; gap: 9px; flex-wrap: wrap; }
.color {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  cursor: pointer; padding: 0;
  transition: transform .1s, border-color .15s;
  position: relative;
}
.color:hover { transform: translateY(-2px); }
.color.active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(59,130,246,.4); }
.color[data-white] { border-color: #3a3f4a; }
.radio-group { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.radio { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.radio input { width: 17px; height: 17px; accent-color: var(--brand); flex: none; }

.slider-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.slider-row label { font-size: 13px; color: var(--muted); min-width: 86px; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--brand); height: 4px; }
input[type="range"]:disabled { opacity: .4; }
input[type="color"]:disabled { opacity: .4; }

.custom-color { justify-content: space-between; margin: 12px 0 0; }
.custom-color input[type="color"] {
  width: 46px; height: 30px; padding: 0; border: 1px solid var(--line);
  border-radius: 8px; background: none; cursor: pointer;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: #2a303b; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand-2); }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }
.btn-danger { color: #fff; background: var(--danger); border-color: #b91c1c; }
#deleteBtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.wide { width: 100%; padding: 13px; font-size: 15px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.file-btn { display: inline-block; text-align: center; width: 100%; }

.toggle {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; color: var(--text);
  margin: 4px 0 12px;
  cursor: pointer;
}
.toggle input { width: 17px; height: 17px; accent-color: var(--brand); }
.tiny { color: var(--muted); font-size: 12px; margin: 6px 0 0; line-height: 1.5; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 12, 16, 0.82);
  backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 50; text-align: center; padding: 20px;
}
.overlay[hidden] { display: none; }
.spinner {
  width: 46px; height: 46px;
  border: 4px solid rgba(255,255,255,.2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #2a303b; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 16px; font-size: 14px; z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
