:root {
  --bg: #1a2433;
  --panel: #202d3e;
  --card: #273444;
  --border: #354a62;
  --text: #c9d4d9;
  --muted: #6b77b2;
  --accent: #80c6c6;
  --accent-hover: #5eadad;
  --sidebar-w: 268px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  font-size: 13px;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.logo {
  padding: 18px 16px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.logo-icon {
  color: var(--accent);
  font-size: 18px;
}

.panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-section h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.section-header h3 { margin-bottom: 0; }

.field {
  margin-bottom: 10px;
}

.field:last-child { margin-bottom: 0; }

.field > label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  margin-bottom: 6px;
  font-size: 12px;
}

.val-label {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

/* Range inputs */
input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

/* Color inputs */
input[type=color] {
  width: 30px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  padding: 1px;
  background: var(--card);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Mono', monospace;
  color: var(--muted);
}

/* Select */
select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

select:focus { border-color: var(--accent); }

/* Buttons */
.btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover { background: #2d3f54; border-color: var(--border); }
.btn:active { background: #1e2d3e; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}

.btn-sm:hover { color: var(--text); border-color: #3d5470; }

.full-width { width: 100%; }

.hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
  margin-top: 6px;
}

/* Color swatches */
.color-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
}

.swatch:hover {
  transform: scale(1.18);
  border-color: white;
}

.swatch.active {
  border-color: white;
  box-shadow: 0 0 0 2px var(--accent);
}

/* Device type toggle */
.device-type-row {
  display: flex;
  gap: 6px;
}

.type-btn {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.type-btn:hover:not(.active) {
  background: #2d3f54;
  border-color: var(--border);
  color: var(--text);
}

.type-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Canvas Area ── */
.canvas-container {
  flex: 1;
  position: relative;
  background: linear-gradient(135deg, #1a2433, #16332a);
  overflow: hidden;
}

.canvas-container.drag-over::after {
  content: 'Drop to apply screenshot';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  background: rgba(128, 198, 198, 0.15);
  border: 2px dashed var(--accent);
  color: white;
  z-index: 20;
  pointer-events: none;
}

#three-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}

.loading-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
  opacity: 1;
  transition: opacity 0.4s;
}

.loading-hint.hidden { opacity: 0; }

.loading-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.loading-inner p {
  color: rgba(255,255,255,0.4);
  font-size: 14px;
}

/* ── Tab Bar ── */
#tab-bar {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 4px;
  height: 40px;
  align-items: flex-end;
  flex-shrink: 0;
  z-index: 10;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0 14px 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
  font-family: inherit;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── App Store View ── */
.appstore-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.as-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.as-device-switch {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.as-dev-btn {
  background: var(--card);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
}

.as-dev-btn:last-child { border-right: none; }
.as-dev-btn:hover:not(.active) { background: #2d3f54; color: var(--text); }
.as-dev-btn.active { background: var(--accent); color: #fff; }

.as-templates {
  display: flex;
  gap: 6px;
}

.as-tpl {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--muted);
  padding: 5px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: border-color 0.12s, color 0.12s;
  font-family: inherit;
}

.as-tpl:hover { color: var(--text); border-color: #3d5470; }
.as-tpl.active { border-color: var(--accent); color: var(--text); }

.as-colors {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 8px;
}

.as-color-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}

.as-color-label input[type=color] {
  width: 26px;
  height: 22px;
}

.as-font-sizes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.as-font-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.as-font-label input[type=range] {
  width: 72px;
  accent-color: var(--accent);
  cursor: pointer;
}

.as-font-label span {
  width: 34px;
  color: var(--text);
  font-size: 11px;
}

.as-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left panel — screen cards */
.as-screens-panel {
  width: 280px;
  min-width: 280px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.as-screens-panel::-webkit-scrollbar { width: 4px; }
.as-screens-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Right panel — preview canvas */
.as-preview-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111a24;
  overflow: hidden;
  padding: 20px;
}

#as-preview-canvas {
  max-height: 100%;
  width: auto;
  border-radius: 8px;
  box-shadow: 0 4px 48px rgba(0,0,0,0.7);
  transition: box-shadow 0.15s;
}

/* Screen cards */
.as-screen-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.12s;
}

.as-screen-card.selected { border-color: var(--accent); }

.as-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.as-card-num {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.as-remove-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.1s, background 0.1s;
}

.as-remove-btn:hover { color: #ef4444; background: rgba(239,68,68,0.1); }

.as-card-thumb {
  width: 100%;
  height: 90px;
  background: var(--bg);
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.as-thumb-placeholder {
  font-size: 11px;
  color: var(--muted);
}

.as-card-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.as-upload-btn {
  font-size: 11px;
  padding: 5px 10px;
}

.as-headline,
.as-subtitle {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.12s;
}

.as-headline:focus,
.as-subtitle:focus { border-color: var(--accent); }

.as-preview-btn {
  font-size: 11px;
  padding: 5px 10px;
}

.as-card-actions-top {
  display: flex;
  align-items: center;
  gap: 4px;
}

.as-layout-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(128, 198, 198, 0.15);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.as-randomize-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.1s, background 0.1s;
}

.as-randomize-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

#as-preview-canvas.drag-over {
  box-shadow: 0 0 0 3px var(--accent), 0 4px 48px rgba(0, 0, 0, 0.7);
  cursor: copy;
}
