* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f4f5f7;
  color: #1c1e21;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: #fff;
  border-bottom: 1px solid #e0e2e6;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }
.build-title {
  flex: 1;
  min-width: 12rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid #cfd3d9;
  border-radius: 8px;
  font-size: 1rem;
}
.action-btn {
  min-height: 44px; padding: 0 1rem; border-radius: 8px; border: 1px solid #1c64f2;
  background: #1c64f2; color: #fff; font: inherit; cursor: pointer;
}
.action-secondary { background: #fff; color: #1c64f2; }
.share-fallback { flex-basis: 100%; padding: 0.5rem; border: 1px solid #cfd3d9; border-radius: 8px; }

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1500px;
  margin: 0 auto;
}

.canvas { min-width: 0; }
.canvas svg { width: 100%; height: auto; display: block; }

.parts-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fff;
  border: 1px solid #e0e2e6;
  border-radius: 10px;
  overflow: hidden;
  align-self: start;
}
.part-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.part-row:hover { background: #f0f2f5; }
.part-row.selected { background: #e7f0ff; }
.part-name { font-weight: 600; white-space: nowrap; }
.part-desc { color: #6b7280; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.buy-link { display: inline-block; margin-top: 0.6rem; min-height: 44px; line-height: 44px; color: #1c64f2; text-decoration: none; font-weight: 600; }
.buy-link:hover { text-decoration: underline; }

.editor {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(360px, 90vw);
  background: #fff;
  border-left: 1px solid #e0e2e6;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
  padding: 1rem;
  overflow-y: auto;
  z-index: 20;
}
.editor-head { display: flex; justify-content: space-between; align-items: center; }
.editor-head h2 { margin: 0; font-size: 1.05rem; }
.close-btn {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.notice {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1e21;
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 30;
}

.field { display: block; margin-top: 0.9rem; font-size: 0.85rem; font-weight: 600; color: #4b5563; }
.field input[type='text'], .field input[type='url'] {
  display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.7rem;
  border: 1px solid #cfd3d9; border-radius: 8px; font: inherit; font-weight: 400;
}
.swatch-row, .chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid #cfd3d9; cursor: pointer; padding: 0;
}
.swatch-custom { border-style: dashed; }
.chip {
  min-height: 44px; padding: 0 0.9rem; border-radius: 999px;
  border: 1px solid #cfd3d9; background: #fff; font: inherit; cursor: pointer;
}
.chip.active { background: #1c64f2; border-color: #1c64f2; color: #fff; }
.clear-btn { margin-top: 1rem; width: 100%; }
.total-row {
  display: flex; justify-content: space-between; padding: 0.7rem 0.9rem;
  border-top: 2px solid #e0e2e6; font-size: 1rem;
}
.part-price { color: #374151; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bb-selected { filter: drop-shadow(0 0 4px #1c64f2); }
.canvas svg [class] { cursor: pointer; }
.canvas svg [data-hit-for] { cursor: pointer; }

/* Phone: single column, editor becomes a bottom sheet */
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; padding: 0.5rem; }
  .canvas { order: -1; }
  .editor {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    max-height: 72vh;
    border-left: 0;
    border-top: 1px solid #e0e2e6;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
  }
}
