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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --accent: #ec4899;
  --gold: #f59e0b;
  --gold-light: #fbbf24;
  --green: #10b981;
  --red: #ef4444;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

button { font-family: inherit; }

/* ── Top bar ── */
.top-bar {
  background: #0b1222;
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.back-link:hover { color: var(--text); }

.top-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.95rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:hover { background: var(--surface); border-color: var(--primary-light); }
.btn--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-color: transparent;
  color: white;
}
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99,102,241,0.35); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--red); border-color: rgba(239,68,68,0.4); }
.btn--danger:hover { background: rgba(239,68,68,0.1); }

/* ── Hero header ── */
.hero {
  background: linear-gradient(135deg, #1e293b 0%, #0b1222 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.75rem 1.5rem 1.25rem;
  text-align: center;
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--primary-light);
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  margin-bottom: 0.65rem;
}

.hero__title {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  background: linear-gradient(135deg, #f8fafc 0%, var(--primary-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.15;
  margin-bottom: 0.4rem;
}

.hero__desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.55;
}

/* ── Main layout ── */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 0;
  min-height: calc(100vh - 110px);
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 240px 1fr 240px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-left, .sidebar-right { order: 2; }
  .canvas-area { order: 1; }
}

.sidebar-left, .sidebar-right {
  background: #0b1222;
  border-right: 1px solid var(--border);
  padding: 1rem 0.85rem;
  overflow-y: auto;
  max-height: calc(100vh - 110px);
}
.sidebar-right { border-right: none; border-left: 1px solid var(--border); }

.sidebar-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ── Parts catalog ── */
.cat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

.cat-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.55rem;
  border-radius: 0.4rem;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.cat-tab:hover { color: var(--text); border-color: var(--primary-light); }
.cat-tab.active {
  background: var(--primary);
  border-color: transparent;
  color: white;
}

.parts-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.part-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  padding: 0.55rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.part-card:hover {
  border-color: var(--primary-light);
  background: #243149;
  transform: translateX(2px);
}
.part-card.added {
  border-color: var(--green);
  background: rgba(16,185,129,0.08);
}
.part-card.added::after {
  content: '✓';
  margin-left: auto;
  color: var(--green);
  font-weight: 700;
}

.part-emoji {
  font-size: 1.3rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.part-info {
  flex: 1;
  min-width: 0;
}

.part-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.part-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Canvas area ── */
.canvas-area {
  background:
    radial-gradient(ellipse at center, #1a2540 0%, #0b1222 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 1rem 2rem;
  position: relative;
  overflow: hidden;
}

.canvas-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  position: relative;
  z-index: 2;
  flex-wrap: wrap;
  justify-content: center;
}

.view-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
}
.view-toggle button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.15s;
}
.view-toggle button.active {
  background: var(--primary);
  color: white;
}

/* ── Phone rendering ── */
.phone-wrap {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.phone-shadow {
  width: 280px;
  height: 18px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.5) 0%, transparent 70%);
  border-radius: 50%;
  margin-top: -8px;
}

.phone {
  position: relative;
  width: 280px;
  height: 580px;
  background: var(--phone-color, #1c1c1e);
  border-radius: 42px;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.05),
    inset 0 0 0 8px rgba(0,0,0,0.4),
    0 20px 50px rgba(0,0,0,0.6),
    0 0 0 1px rgba(255,255,255,0.08);
  transition: background 0.4s ease, transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.phone.flipped {
  transform: rotateY(180deg);
}

.phone-face {
  position: absolute;
  inset: 8px;
  border-radius: 36px;
  background: var(--phone-color, #1c1c1e);
  overflow: hidden;
}

.phone-face--front {
  background:
    linear-gradient(180deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0) 8%, rgba(0,0,0,0) 92%, rgba(0,0,0,0.15) 100%),
    var(--phone-color, #1c1c1e);
}

.phone-face--back {
  display: none;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(0,0,0,0.25) 0%, transparent 60%),
    var(--phone-color, #1c1c1e);
}

.phone.showing-back .phone-face--front { display: none; }
.phone.showing-back .phone-face--back { display: block; }

.phone-screen {
  position: absolute;
  inset: 12px 8px 8px 8px;
  border-radius: 32px;
  background: linear-gradient(135deg, #0a0e1a 0%, #1a1f2e 100%);
  overflow: hidden;
}

.phone-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 70% 30%, rgba(99,102,241,0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 30% 70%, rgba(236,72,153,0.18) 0%, transparent 50%);
  opacity: 0.6;
}

.phone-screen::after {
  content: '';
  position: absolute;
  top: 15%;
  left: -20%;
  width: 60%;
  height: 70%;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.08) 50%, transparent 70%);
  transform: rotate(15deg);
  pointer-events: none;
}

/* Time + status bar mockup */
.screen-statusbar {
  position: absolute;
  top: 8px;
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.85);
  font-weight: 600;
  z-index: 1;
}
.screen-time { letter-spacing: 0.02em; }
.screen-icons { display: flex; gap: 0.2rem; align-items: center; }

.screen-widget {
  position: absolute;
  bottom: 18px;
  left: 18px;
  right: 18px;
  text-align: center;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.5);
  font-weight: 500;
  z-index: 1;
}

/* Parts layer */
.parts-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.placed-part {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  transform: translate(-50%, -50%);
  transition: filter 0.15s, transform 0.05s;
  z-index: 5;
  font-size: 1.6rem;
  line-height: 1;
}

.placed-part:hover {
  filter: drop-shadow(0 0 8px rgba(99,102,241,0.6));
  z-index: 10;
}

.placed-part.dragging {
  cursor: grabbing;
  z-index: 20;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
}

.placed-part.selected {
  outline: 2px dashed var(--primary-light);
  outline-offset: 4px;
  border-radius: 6px;
}

.placed-part__remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  background: var(--red);
  color: white;
  border: 2px solid var(--bg);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}
.placed-part.selected .placed-part__remove { display: flex; }

/* Camera lenses rendered as circles */
.part-cameras {
  display: grid;
  gap: 2px;
  padding: 3px;
  background: rgba(0,0,0,0.5);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
}
.cam-lens {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #2a3144 0%, #050609 70%);
  border: 2px solid #1a1f2e;
  position: relative;
}
.cam-lens::after {
  content: '';
  position: absolute;
  top: 25%;
  left: 25%;
  width: 35%;
  height: 35%;
  border-radius: 50%;
  background: rgba(99,102,241,0.3);
  box-shadow: 0 0 4px rgba(99,102,241,0.5);
}

/* Camera layouts */
.layout--single .cam-lens { width: 28px; height: 28px; }
.layout--dual { grid-template-columns: 1fr 1fr; }
.layout--triple-diag { grid-template-columns: 1fr; transform: rotate(0); }
.layout--triple-tri { grid-template-columns: 1fr 1fr; }
.layout--triple-tri .cam-lens:nth-child(3) { grid-column: 1 / 3; justify-self: center; }
.layout--quad { grid-template-columns: 1fr 1fr; }
.layout--penta { grid-template-columns: 1fr 1fr; }
.layout--penta .cam-lens:nth-child(5) { grid-column: 1 / 3; justify-self: center; }

/* Camera bump visual */
.part-cam-bump {
  background: rgba(0,0,0,0.4);
  border-radius: 14px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* Apple logo */
.part-apple-logo {
  font-size: 2.2rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* Speaker grilles */
.part-speaker-grill {
  display: flex;
  gap: 2px;
}
.speaker-hole {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
}

/* Solar panel */
.part-solar-panel {
  background: linear-gradient(135deg, #1e3a8a, #0c1e4a);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 1px;
  padding: 2px;
  font-size: 0;
}
.solar-cell {
  background: rgba(99,102,241,0.25);
  border: 1px solid rgba(0,0,0,0.4);
}

/* Finish backdrops */
.finish-bg {
  position: absolute;
  inset: 0;
  border-radius: 36px;
  pointer-events: none;
  z-index: 1;
}
.finish-titanium { background: linear-gradient(135deg, #8a8178 0%, #5a534a 100%); }
.finish-aluminum { background: linear-gradient(135deg, #c0c0c0 0%, #8a8a8a 100%); }
.finish-steel    { background: linear-gradient(135deg, #d8d8d8 0%, #888 100%); }
.finish-leather  { background: linear-gradient(135deg, #6b4423 0%, #3a2410 100%); }
.finish-wood     { background: linear-gradient(135deg, #8b5a2b 0%, #4a2f15 100%); }
.finish-glass    { background: linear-gradient(135deg, rgba(200,210,220,0.4), rgba(100,110,120,0.3)); }
.finish-carbon   { background:
  repeating-linear-gradient(45deg, #1a1a1a 0 2px, #2a2a2a 2px 4px);
}

/* ── Color picker ── */
.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--border);
  transition: all 0.15s;
  position: relative;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary-light);
}

/* ── Right sidebar ── */
.field-group {
  margin-bottom: 1rem;
}

.field-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.text-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
.text-input:focus { outline: none; border-color: var(--primary-light); }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
}
.stat-card__label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.stat-card__value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--gold-light);
  font-variant-numeric: tabular-nums;
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.5rem;
}
.action-stack .btn { width: 100%; justify-content: center; }

.hint-box {
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 0.5rem;
  padding: 0.65rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 1rem;
}

/* ── Submit modal ── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  padding: 1rem;
}
.modal.active { display: flex; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--primary-light);
  border-radius: 1.25rem;
  padding: 2rem 1.75rem 1.75rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 0.6rem;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.modal-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.design-preview {
  background: linear-gradient(135deg, #1a2540 0%, #0b1222 100%);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 1.25rem 1rem;
  margin-bottom: 1rem;
}

.design-preview .phone {
  width: 180px;
  height: 370px;
  margin: 0 auto;
  border-radius: 28px;
}
.design-preview .phone-face { border-radius: 24px; inset: 6px; }
.design-preview .phone-screen { border-radius: 22px; inset: 8px 6px 6px 6px; }

.design-specs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 1rem;
  font-size: 0.75rem;
}
.design-specs > div {
  background: var(--surface-2);
  border-radius: 0.4rem;
  padding: 0.45rem 0.55rem;
  text-align: left;
}
.design-specs strong { display: block; color: var(--gold-light); font-size: 0.85rem; font-weight: 700; }
.design-specs span { color: var(--text-muted); font-size: 0.68rem; }

.design-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 0 1rem;
  justify-content: center;
  max-height: 70px;
  overflow-y: auto;
}
.design-tag {
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.25);
  color: var(--primary-light);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.1rem;
  border-radius: 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Scrollbar ── */
.sidebar-left::-webkit-scrollbar,
.sidebar-right::-webkit-scrollbar { width: 6px; }
.sidebar-left::-webkit-scrollbar-thumb,
.sidebar-right::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Footer credit ── */
.footer-note {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: #0b1222;
}

/* ── Drop hint ── */
.canvas-empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  pointer-events: none;
  z-index: 1;
  max-width: 240px;
  line-height: 1.55;
  opacity: 0.7;
}
.canvas-empty-hint strong { color: var(--primary-light); display: block; font-size: 0.95rem; margin-bottom: 0.25rem; }

/* Floating animation for new parts */
@keyframes partPop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  60% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.placed-part.new { animation: partPop 0.35s ease-out; }
