:root {
  --bg: #fbf7f0;
  --card: #ffffff;
  --ink: #2b1d1f;
  --muted: #8a7a73;
  --line: #eadfd2;
  --accent: #7a1f3d;       /* burgundy */
  --accent-soft: #f4e3e8;
  --gold: #c98a06;         /* BONUS */
  --gold-soft: #fff4d6;
  --radius: 16px;
  --tap: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  max-width: 100%;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- top (sticky) ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 14px 8px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 16px var(--bg);
  max-width: 640px; margin: 0 auto;
}
.bar { display: flex; gap: 10px; }
.seg {
  flex: 1; display: flex; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px; gap: 4px;
}
.seg-btn {
  flex: 1; min-height: var(--tap); border: 0; border-radius: 12px; background: transparent;
  font-weight: 700; font-size: 16px; line-height: 1.1;
}
.seg-btn.on { background: var(--accent); color: #fff; }
.seg-btn.on small { color: #f3d9e1; }
.clear {
  min-width: 76px; min-height: calc(var(--tap) + 10px); border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card); font-weight: 700; line-height: 1.1;
}
.clear:active, .seg-btn:active { transform: scale(.97); }

.result { text-align: center; padding: 8px 0 2px; }
.big {
  font-size: clamp(64px, 22vw, 84px); line-height: 1; font-weight: 800; letter-spacing: -2px; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.big.empty { color: var(--line); }
.big.bonus { color: var(--gold); font-size: clamp(48px, 18vw, 72px); letter-spacing: 0; }
.unit { font-size: 14px; color: var(--muted); font-weight: 600; min-height: 17px; }
.reason {
  margin-top: 4px; font-size: 16px; font-weight: 600; color: var(--ink);
  white-space: normal; overflow-wrap: anywhere; word-break: break-word;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; overflow: hidden; padding: 6px 0 2px; }
.chips:empty { display: none; }
.chip {
  flex: none; display: flex; align-items: center; gap: 6px; min-height: 36px;
  padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; white-space: nowrap;
}
.chip b { font-weight: 700; }
.chip .x { color: var(--muted); font-size: 16px; }
.chip .z { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 4px; }
.chip.combo { border-color: var(--accent); }

/* ---------- main ---------- */
main { max-width: 640px; margin: 0 auto; padding: 14px 14px 60px; padding-top: calc(var(--top-h, 200px) + 16px); }

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat {
  position: relative; min-height: 84px; border: 2px solid var(--line); background: var(--card);
  border-radius: var(--radius); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-weight: 700; font-size: 15px; padding: 6px 4px;
}
.cat .e { font-size: 30px; line-height: 1; }
.cat.on { border-color: var(--accent); background: var(--accent-soft); }
.cat .n {
  position: absolute; top: 6px; right: 8px; min-width: 22px; height: 22px; border-radius: 11px;
  background: var(--accent); color: #fff; font-size: 13px; line-height: 22px; padding: 0 6px;
}

.list { margin-top: 16px; }
.group-title {
  margin: 18px 4px 8px; font-size: 13px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.group-title:first-child { margin-top: 4px; }
.note { margin: -4px 4px 8px; font-size: 13px; color: var(--muted); }
.svcs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.svc {
  min-height: 64px; border: 2px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 8px 12px; text-align: left; display: flex; flex-direction: column; justify-content: center;
  gap: 2px; position: relative; line-height: 1.15;
}
.svc .nm { font-weight: 650; font-size: 15px; padding-right: 22px; }
.svc .pr { font-weight: 800; color: var(--accent); font-size: 16px; }
.svc .pr .split { font-weight: 500; color: var(--muted); font-size: 12px; }
.svc .ck {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line);
}
.svc.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.svc.on .pr, .svc.on .pr .split { color: #f6dbe3; }
.svc.on .ck { background: #fff; border-color: #fff; }
.svc.on .ck::after {
  content: "✓"; color: var(--accent); font-weight: 900; font-size: 15px;
  display: block; text-align: center; line-height: 18px;
}
.svc:active, .cat:active { transform: scale(.98); }

/* ---------- custom ---------- */
.custom { margin-top: 22px; }
.custom-toggle {
  width: 100%; min-height: var(--tap); border: 2px dashed var(--line); background: transparent;
  border-radius: var(--radius); font-weight: 700; display: flex; align-items: center;
  justify-content: center; gap: 8px;
}
.custom-toggle small { display: inline; }
.custom-form { margin-top: 10px; display: grid; gap: 10px; }
input[type="text"] {
  width: 100%; min-height: var(--tap); border: 2px solid var(--line); border-radius: 14px;
  background: var(--card); padding: 0 14px; font-size: 18px;
}
input:focus { outline: none; border-color: var(--accent); }
.price-row { display: flex; gap: 10px; align-items: center; }
.price-row .dollar { font-size: 22px; font-weight: 800; color: var(--muted); }
.price-row input { flex: 1; }
.add {
  min-height: var(--tap); min-width: 88px; border: 0; border-radius: 14px; background: var(--accent);
  color: #fff; font-weight: 800; padding: 0 16px;
}

/* ---------- bonus helper ---------- */
.bonus { margin-top: 30px; text-align: center; }
.bonus-toggle {
  min-height: 48px; padding: 0 22px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--muted); font-weight: 600;
}
.bonus-panel {
  margin-top: 12px; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.next {
  background: var(--gold-soft); color: #7a5300; border-radius: 12px; padding: 12px 14px;
  font-weight: 800; font-size: 18px;
}
.next small { color: #9b7a2c; display: inline; }
.techs { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; }
.tech {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 12px;
  padding: 4px 4px 4px 12px; min-height: var(--tap);
}
.tech.next-up { border-color: var(--gold); background: #fffbef; }
.tech .pos { color: var(--muted); font-size: 13px; width: 18px; }
.tech .tn { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tech .cnt { min-width: 28px; text-align: center; font-weight: 800; font-size: 18px; color: var(--gold); }
.ib {
  width: 48px; height: 48px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 18px; font-weight: 700;
}
.tech-form { display: flex; gap: 10px; }
.quiet {
  margin-top: 12px; min-height: 48px; width: 100%; border: 0; background: transparent;
  color: var(--muted); font-weight: 600;
}
.hint { margin: 4px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

@media (min-width: 560px) {
  .svcs { grid-template-columns: 1fr 1fr 1fr; }
  .big { font-size: 96px; }
}
