:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-soft: #f0f0ec;
  --text: #171717;
  --muted: #71717a;
  --line: #e4e4e7;
  --primary: #18181b;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 14px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; }
button { cursor: pointer; }

#app {
  width: 100vw;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  background: rgba(247, 247, 244, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.nav-btn {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}
.nav-btn.active { background: var(--primary); color: #fff; }

.page-wrap { flex: 1; position: relative; overflow: hidden; }
.page { position: absolute; inset: 0; display: none; overflow-y: auto; padding-bottom: calc(20px + var(--safe-bottom)); }
.page.active { display: block; }
.builder { padding: 18px 14px 30px; }

.header { margin: 4px 0 18px; }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.header h1 { margin: 0 0 8px; font-size: 30px; line-height: 1.08; letter-spacing: 0; }
.header p { margin: 0; max-width: 30em; color: var(--muted); font-size: 14px; line-height: 1.55; }

.panel, .config-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.panel-title { display: block; margin-bottom: 10px; font-size: 14px; font-weight: 750; }
.budget-row { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 4px 0 12px; }
.currency { color: var(--muted); font-size: 26px; }
#budget-input {
  width: min(70vw, 220px);
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  font-size: 44px;
  font-weight: 800;
}
.quick-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(48px, 1fr)); gap: 6px; }
.chip, .option, .seg-btn, .ghost-btn, .primary-btn, .icon-btn, .part-btn, .close-btn {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.chip { min-height: 34px; color: var(--muted); font-weight: 700; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.usage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.option {
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 10px;
  text-align: left;
}
.option strong { font-size: 15px; }
.option span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.option.active { background: #f4f4f5; border-color: #a1a1aa; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg-btn { min-height: 40px; color: var(--muted); font-weight: 700; }
.seg-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.primary-btn {
  width: 100%;
  min-height: 50px;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  margin: 6px 0 14px;
}
.primary-btn:disabled { opacity: .55; }
.ghost-btn { min-height: 40px; padding: 0 12px; color: var(--text); font-weight: 700; }
.ghost-btn.wide { width: 100%; margin-top: 8px; }
.hidden { display: none !important; }

.results-title { margin: 18px 0 10px; font-size: 18px; }
.config-card { padding: 13px; }
.config-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.config-name { font-weight: 850; }
.tag { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.price { white-space: nowrap; font-size: 18px; font-weight: 850; }
.parts { display: grid; gap: 5px; margin: 10px 0; }
.part-row { display: grid; grid-template-columns: 42px 1fr; gap: 8px; color: #3f3f46; font-size: 13px; line-height: 1.42; }
.part-row span { color: var(--muted); }
.compat-ok { color: var(--ok); font-size: 13px; font-weight: 750; }
.warn { color: var(--warn); font-size: 13px; line-height: 1.45; }
.score-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.score { padding: 8px 6px; border-radius: var(--radius); background: var(--surface-soft); text-align: center; }
.score span { display: block; color: var(--muted); font-size: 11px; }
.score strong { display: block; margin-top: 2px; font-size: 16px; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.scene-page { height: 100%; overflow: hidden; padding: 0; }
.scene-shell { position: relative; height: 100%; background: #f2f2ee; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.scene-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.scene-title {
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}
.scene-title strong { display: block; font-size: 14px; }
.scene-title span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.scene-actions { display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
.icon-btn { width: 40px; height: 40px; background: rgba(255,255,255,.86); font-weight: 850; }
.parts-tray {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(255,255,255,.9);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.parts-list { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.parts-list::-webkit-scrollbar { display: none; }
.part-btn { flex: 0 0 auto; min-width: 68px; height: 48px; padding: 7px; font-size: 12px; font-weight: 700; }
.part-btn.installed { background: #dcfce7; border-color: #86efac; }

.showcase-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 46px 14px calc(14px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(247,247,244,.96));
}
.showcase-info { text-align: center; margin-bottom: 12px; }
.showcase-info strong { display: block; font-size: 17px; }
.showcase-info span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.showcase-controls { display: flex; justify-content: center; gap: 8px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(24,24,27,.32);
}
.modal-body {
  width: 100%;
  max-width: 480px;
  max-height: 82dvh;
  overflow-y: auto;
  padding: 18px 14px calc(18px + var(--safe-bottom));
  border: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  background: var(--surface);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.close-btn { width: 38px; height: 38px; font-size: 20px; }
.detail-grid { display: grid; gap: 8px; }
.detail-item { padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fafafa; font-size: 13px; line-height: 1.45; }
.detail-item strong { display: block; margin-bottom: 3px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 82px;
  z-index: 80;
  max-width: 88vw;
  padding: 10px 14px;
  border-radius: 999px;
  background: #18181b;
  color: #fff;
  font-size: 13px;
  transform: translateX(-50%);
}
