:root {
  --bg: #0b1120;
  --bg-elevated: rgba(17, 25, 45, 0.88);
  --card-bg: rgba(18, 28, 50, 0.82);
  --surface-soft: rgba(30, 41, 59, 0.72);
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.42);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #0ea5e9;
  --accent-glow: rgba(99, 102, 241, 0.32);
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.14), transparent 38%),
    radial-gradient(circle at bottom left, rgba(14, 165, 233, 0.12), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(16px);
  background: rgba(11, 17, 32, 0.86);
  border-bottom: 1px solid var(--border);
}

.header-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-group h1 {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-group .subtitle {
  margin: 3px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.header-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.nav-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
}

.nav-pill:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.16);
}

.status-pill.loading {
  border-color: rgba(245, 158, 11, 0.45);
  color: #fde68a;
  background: rgba(245, 158, 11, 0.12);
}

.status-pill.ready {
  border-color: rgba(16, 185, 129, 0.45);
  color: #a7f3d0;
  background: rgba(16, 185, 129, 0.14);
}

.status-pill.error {
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
  background: rgba(239, 68, 68, 0.15);
}

/* Main Shell */
.main-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
}

/* Progress Banner */
.progress-banner {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  border: 1px solid rgba(99, 102, 241, 0.42);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}

.progress-detail {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.14s, filter 0.2s, background 0.2s, border-color 0.2s;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--accent-2), #0284c7);
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.28);
}

.btn-ghost {
  background: rgba(30, 41, 59, 0.72);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: rgba(51, 65, 85, 0.8);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-xs {
  padding: 5px 9px;
  font-size: 0.78rem;
}

.full-width {
  width: 100%;
}

.danger-text {
  color: #fca5a5;
}

.btn-link {
  background: none;
  border: none;
  color: #93c5fd;
  padding: 0;
  cursor: pointer;
  font-size: 0.82rem;
  text-decoration: underline;
}

.inline-btn {
  margin-left: 4px;
}

/* Drop Zone */
.upload-section {
  margin: 18px 0 28px;
}

.drop-zone {
  padding: 52px 24px;
  border-radius: var(--radius-lg);
  border: 2px dashed rgba(99, 102, 241, 0.48);
  background: linear-gradient(180deg, rgba(18, 28, 50, 0.85), rgba(13, 20, 38, 0.92));
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, rgba(30, 41, 72, 0.9), rgba(17, 25, 45, 0.96));
}

.drop-icon {
  font-size: 2.8rem;
  margin-bottom: 10px;
}

.drop-zone h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
}

.drop-desc {
  max-width: 680px;
  margin: 0 auto 22px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.drop-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 22px;
}

.feature-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.feature-badges span {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(30, 41, 59, 0.75);
  border: 1px solid var(--border);
  color: #cbd5e1;
}

/* Studio Workspace */
.batch-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  border: 1px solid var(--border);
}

.batch-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 220px;
  overflow: hidden;
}

.batch-label {
  font-size: 0.84rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.batch-label strong {
  color: var(--text);
}

.batch-list {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0;
}

.batch-item-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 5px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.72);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}

.batch-item-btn.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.24);
}

.batch-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.batch-remove-x {
  margin-left: 2px;
  opacity: 0.65;
  font-weight: 700;
}

.batch-remove-x:hover {
  opacity: 1;
  color: #fca5a5;
}

.batch-bar-actions {
  display: flex;
  gap: 8px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 430px);
  gap: 18px;
  align-items: start;
}

/* Stage Panel */
.stage-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.segmented-tabs {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.seg-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg-tab.active {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: #ffffff;
}

.stage-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: #cbd5e1;
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.stage-meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(30, 41, 59, 0.75);
  border: 1px solid var(--border);
  color: #e2e8f0;
}

.meta-pill.info {
  border-color: rgba(14, 165, 233, 0.4);
  color: #bae6fd;
}

.meta-pill.warn {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.14);
  color: #fde68a;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 450px;
  max-height: 640px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 18px;
}

.checkerboard-surface {
  background-color: #162032;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.045) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.045) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.045) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.045) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#preview-canvas {
  max-width: 100%;
  max-height: 580px;
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  cursor: grab;
  touch-action: none;
}

#preview-canvas:active {
  cursor: grabbing;
}

.canvas-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 17, 32, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 0.9rem;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pan-zoom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding-top: 4px;
}

.slider-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}

.slider-inline input[type="range"] {
  width: 112px;
  accent-color: var(--accent);
}

.slider-num {
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: #cbd5e1;
}

.drag-tip {
  margin-left: auto;
  font-size: 0.77rem;
  color: var(--text-muted);
}

/* Right Control Panel */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.panel-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-card-head h3 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
}

.head-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.text-input,
.select-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.84rem;
}

.text-input:focus,
.select-input:focus {
  outline: none;
  border-color: var(--accent);
}

.spec-search-row {
  margin-bottom: 8px;
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.cat-chip {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.77rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.cat-chip.active {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--accent);
  color: #ffffff;
}

.spec-list {
  max-height: 215px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.spec-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s, background 0.15s;
}

.spec-item:hover {
  border-color: var(--border-strong);
}

.spec-item.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.2);
}

.spec-item-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.spec-item-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.spec-item-badge {
  font-size: 0.73rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border);
  color: #cbd5e1;
  white-space: nowrap;
}

.custom-spec-panel {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
}

.custom-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.field-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.77rem;
  color: var(--text-muted);
}

.spec-summary-box {
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(14, 165, 233, 0.08);
  border: 1px solid rgba(14, 165, 233, 0.28);
  font-size: 0.78rem;
  line-height: 1.5;
  color: #cbd5e1;
}

/* Swatches */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.swatch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 7px 4px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
  color: #cbd5e1;
  font-size: 0.74rem;
  cursor: pointer;
}

.swatch-btn.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.22);
  color: #ffffff;
}

.swatch-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.swatch-dot.transparent-dot {
  background-color: #cbd5e1;
  background-image:
    linear-gradient(45deg, #64748b 25%, transparent 25%),
    linear-gradient(-45deg, #64748b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #64748b 75%),
    linear-gradient(-45deg, transparent 75%, #64748b 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.bg-extra-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.color-picker-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #cbd5e1;
  cursor: pointer;
}

.color-picker-label input[type="color"] {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.micro-note {
  margin: 8px 0 0;
  font-size: 0.76rem;
  color: #fcd34d;
}

/* Sliders */
.slider-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #cbd5e1;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* Export Controls */
.export-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.custom-kb-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.export-meta-preview {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-bottom: 10px;
  line-height: 1.45;
}

.export-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  background: #0f172a;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
}

.camera-modal-card {
  max-width: 640px;
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  font-size: 0.88rem;
  line-height: 1.65;
  color: #cbd5e1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.camera-stage {
  position: relative;
  background: #020617;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-guide-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.oval-guide {
  width: 42%;
  height: 60%;
  border: 2px dashed rgba(56, 189, 248, 0.85);
  border-radius: 50% 50% 45% 45%;
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.32);
}

.camera-tip {
  position: absolute;
  bottom: 12px;
  margin: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  font-size: 0.78rem;
  color: #e2e8f0;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 74px;
  right: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.84rem;
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.65);
  background: rgba(6, 78, 59, 0.92);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.7);
  background: rgba(127, 29, 29, 0.92);
}

.toast.info {
  border-color: rgba(56, 189, 248, 0.6);
}

/* SEO Guide & Footer */
.seo-guide-section {
  margin-top: 28px;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.guide-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px 16px;
}

.guide-card h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
}

.guide-card p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.app-footer {
  max-width: 1440px;
  margin: 10px auto 26px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.app-footer a {
  color: #93c5fd;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 1024px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .guide-grid,
  .export-config-grid,
  .custom-kb-row {
    grid-template-columns: 1fr;
  }

  .swatch-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-wrap {
    min-height: 320px;
  }

  .drag-tip {
    margin-left: 0;
  }
}
