:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e5ea;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}

.app-header {
  text-align: center;
  padding: 20px 16px 12px;
}
.app-header h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }

.steps-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 4px 12px 16px;
  flex-wrap: wrap;
}
.step-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #e9ecf1;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
.step-dot span { font-weight: 500; }
.step-dot.active { background: var(--primary); color: #fff; }
.step-dot.done { background: #16a34a; color: #fff; }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 12px;
}

.panel.hidden { display: none; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 16px;
}
.card h2 { margin-top: 0; font-size: 17px; }

.tabbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-content.hidden { display: none; }

.camera-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 3/4;
}
#video { width: 100%; height: 100%; object-fit: cover; }
.face-guide {
  position: absolute;
  inset: 12% 22%;
  border: 2px dashed rgba(255,255,255,0.7);
  border-radius: 50% / 40%;
  pointer-events: none;
}

.hint { color: var(--muted); font-size: 12.5px; text-align: center; margin: 10px 0 0; }

.btn-row { display: flex; justify-content: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #eef1f6; color: var(--text); }
.btn.text { background: transparent; color: var(--primary); text-decoration: underline; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.upload-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 20px;
}
.upload-box.dragover { border-color: var(--primary); color: var(--primary); background: #eff4ff; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
  color: var(--text);
}
.field-label:first-child { margin-top: 0; }

.preview-canvas {
  width: 100%;
  max-width: 320px;
  display: block;
  margin: 0 auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 16px 16px;
}
.preview-canvas.small { max-width: 200px; }
.preview-canvas.layout { max-width: 100%; }

.select {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: #fff;
}

.custom-size {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.custom-size.hidden { display: none; }
.custom-size input {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.color-swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
}
.swatch.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }

.radio-row { display: flex; gap: 16px; font-size: 13px; flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: 5px; }

input[type="range"] { width: 100%; }

.crop-wrap {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  aspect-ratio: 1/1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  touch-action: none;
  background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 16px 16px;
}
#cropCanvas { width: 100%; height: 100%; display: block; cursor: grab; }

.layout-preview-wrap { margin-top: 16px; text-align: center; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,22,28,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 50;
  color: #fff;
  padding: 20px;
  text-align: center;
}
.overlay.hidden { display: none; }
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 24px;
  padding: 0 20px;
}
