:root {
  --bg: #f6f4fd;
  --card: #ffffff;
  --text: #1b1730;
  --muted: #655f7a;
  --line: #ddd8ee;
  --accent: #6d28d9;
  --accent-text: #ffffff;
  --best-bg: #e3f6ef;
  --best-line: #12a37f;
  --worse: #b42318;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13111c;
    --card: #1e1b2e;
    --text: #edeaf7;
    --muted: #a39dbb;
    --line: #342f4d;
    --accent: #a78bfa;
    --accent-text: #1a1033;
    --best-bg: #12332b;
    --best-line: #2bb38f;
    --worse: #ff8a7a;
    --warn-bg: #3a2f10;
    --warn-text: #ffd983;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top, main { max-width: 640px; margin: 0 auto; padding: 0 14px; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 6px;
}
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
.settings { display: flex; gap: 10px; }
.settings label { font-size: 0.75rem; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }

input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.summary {
  margin: 10px 0; padding: 12px 14px; border-radius: 12px;
  background: var(--best-bg); border: 1px solid var(--best-line);
  position: sticky; top: calc(6px + env(safe-area-inset-top)); z-index: 2;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.12);
}
.summary:empty { display: none; }
.summary strong { font-size: 1.1rem; }
.summary ul { margin: 6px 0 0; padding-left: 1.1em; color: var(--muted); font-size: 0.92rem; }
.summary.win, .summary.tie {
  text-align: center; color: #fff; border: 0; padding: 16px 16px 14px; border-radius: 16px;
  background: linear-gradient(135deg, #0b5d57 0%, #0f9f7c 55%, #22c08c 100%);
  box-shadow: 0 8px 24px rgb(15 118 110 / 0.35);
}
.summary.tie { background: linear-gradient(135deg, #475569, #64748b); box-shadow: none; }
.win-label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.9; }
.win-name { font-size: 1.9rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; margin-top: 2px; overflow-wrap: anywhere; }
.win-price { font-size: 1.05rem; font-weight: 600; opacity: 0.95; }
.win-save {
  display: inline-block; margin: 8px 3px 0; padding: 4px 12px; border-radius: 999px;
  background: rgb(255 255 255 / 0.18); font-size: 0.88rem;
}
.win-save b { color: #fde68a; }

.summary.pop { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes pop {
  0% { transform: scale(0.85); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}
.confetti { position: fixed; z-index: 10; pointer-events: none; }
.confetti i {
  position: absolute; width: 8px; height: 12px; border-radius: 2px; opacity: 0;
  animation: fly 1.2s cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}
@keyframes fly {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; }
}
.deal { transition: opacity 0.25s, box-shadow 0.25s, border-color 0.25s; }
.deal.best { box-shadow: 0 0 0 2px var(--best-line), 0 6px 18px rgb(18 163 127 / 0.2); }
.deal.lose { opacity: 0.78; }
.deal.lose:focus-within { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .summary.pop { animation: none; }
  .deal { transition: none; }
}

.summary.waiting { background: var(--card); border: 1px dashed var(--line); color: var(--muted); box-shadow: none; position: static; }
.summary.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn-text); }

.deal {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin: 10px 0;
}
.deal.best { border-color: var(--best-line); box-shadow: 0 0 0 1px var(--best-line); }

.deal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.name { font-weight: 600; border-color: transparent; background: transparent; padding-left: 4px; flex: 1; }
.name:hover { border-color: var(--line); }
.badge {
  white-space: nowrap; font-size: 0.78rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--best-line); color: #fff;
}
.badge.worse { background: transparent; color: var(--worse); border: 1px solid currentColor; }
.rm {
  border: 0; background: transparent; color: var(--muted);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer; flex: none;
}

.rm:hover { background: var(--bg); color: var(--text); }

.fields {
  display: grid; gap: 8px; align-items: end;
  grid-template-columns: 1.2fr 0.8fr auto 1fr;
}
.times { padding-bottom: 12px; color: var(--muted); }
.fields input { min-height: 46px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
input:disabled { opacity: 0.5; }
input.need { border-color: #d97706; box-shadow: 0 0 0 2px rgb(217 119 6 / 0.3); }
::placeholder { color: var(--muted); opacity: 0.45; }

.chips { display: flex; gap: 5px; margin-top: 8px; }
.chips select { flex: 0 0 78px !important; padding-left: 10px !important; }
.chips button, .chips select {
  flex: 1 1 auto; width: auto; min-width: 0; min-height: 42px; padding: 6px 5px; font-size: 0.88rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--text); white-space: nowrap;
  touch-action: manipulation;
}
.chips .on { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.offers button { font-size: 0.88rem; }

.offer-extra { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); }
.offer-extra[hidden] { display: none; }
.offer-extra input { min-height: 44px; }
.offer-extra > input { width: 4.5em; flex: none; text-align: center; }
.offer-extra .money { flex: 1; }
.fields label > span { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.money { position: relative; }
.money .cur { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); }
.money input { padding-left: 26px; }


.result { margin-top: 10px; min-height: 1.4em; font-size: 0.92rem; color: var(--muted); }
.result .unitprice { font-size: 1.15rem; font-weight: 700; color: var(--text); margin-right: 8px; }
.result .extra { color: var(--worse); }
.result .err { color: var(--warn-text); background: var(--warn-bg); padding: 2px 8px; border-radius: 6px; }

.actions { display: flex; gap: 10px; margin: 14px 0 6px; }
button { cursor: pointer; }
.actions button {
  padding: 11px 16px; border-radius: 10px; min-height: 48px; touch-action: manipulation;
  border: 1px solid var(--line); background: var(--card);
}
.actions .primary { flex: 1; background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 10px 0 30px; }

/* ---------- Brand colour ---------- */
:root { --brand: linear-gradient(120deg, #4f46e5 0%, #7c3aed 50%, #db2777 100%); }
body { padding-top: 0; min-height: 100vh; }
.top {
  display: block; max-width: none; padding: env(safe-area-inset-top) 0 0;
  background: var(--brand); color: #fff; box-shadow: 0 4px 18px rgb(79 70 229 / 0.3);
}
.top-in {
  max-width: 640px; margin: 0 auto; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand svg { width: 36px; height: 36px; filter: drop-shadow(0 2px 4px rgb(0 0 0 / 0.25)); }
.settings label { color: rgb(255 255 255 / 0.85); }
.settings select { background: rgb(255 255 255 / 0.16); border-color: rgb(255 255 255 / 0.35); color: #fff; padding: 6px 8px; }
.settings select option { color: #1b1730; background: #fff; }
main { padding-top: 6px; }

/* Each deal gets its own colour: numbered dot, top stripe and selected chips. */
#deals { counter-reset: deal; }
.deal { counter-increment: deal; --dc: #6366f1; border-top: 4px solid var(--dc); }
.deal:nth-child(5n+2) { --dc: #db2777; }
.deal:nth-child(5n+3) { --dc: #d97706; }
.deal:nth-child(5n+4) { --dc: #0891b2; }
.deal:nth-child(5n) { --dc: #7c3aed; }
.deal-head::before {
  content: counter(deal); flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--dc); color: #fff; font-weight: 700; font-size: 0.9rem;
}
.chips .on { background: var(--dc); color: #fff; }
.deal input:focus, .deal select:focus { outline-color: var(--dc); }
.deal.best { border-top-color: var(--best-line); }
.actions .primary { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgb(124 58 237 / 0.35); }

/* ---------- Launch splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  display: grid; place-content: center; justify-items: center; gap: 16px;
  background: var(--bg);
  animation: splash-out 0.4s ease 0.9s forwards;
}
#splash svg {
  width: 116px; height: 116px; border-radius: 27px;
  box-shadow: 0 14px 40px rgb(124 58 237 / 0.45);
  animation: splash-logo 0.65s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
#splash span {
  font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em;
  background: var(--brand); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: splash-text 0.45s ease 0.2s both;
}
@keyframes splash-logo { from { transform: scale(0.4) rotate(-20deg); opacity: 0; } }
@keyframes splash-text { from { transform: translateY(10px); opacity: 0; } }
@keyframes splash-out { to { opacity: 0; visibility: hidden; transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) {
  #splash { animation-duration: 0.2s; animation-delay: 0.5s; }
  #splash svg, #splash span { animation: none; }
}

/* ---------- Name + tagline ---------- */
h1 { display: flex; flex-direction: column; line-height: 1.05; font-size: 1.45rem; font-weight: 800; letter-spacing: 0.02em; }
h1 small { font-size: 0.68rem; font-weight: 500; letter-spacing: 0.03em; opacity: 0.85; }
#splash { gap: 6px; }
#splash svg { margin-bottom: 12px; }
#splash span { font-size: 2.2rem; letter-spacing: 0.04em; line-height: 1; }
#splash small { color: var(--muted); font-size: 0.95rem; animation: splash-text 0.45s ease 0.3s both; }
@media (prefers-reduced-motion: reduce) { #splash small { animation: none; } }

/* ---------- Saved deals ---------- */
.save {
  border: 0; background: transparent; color: var(--muted); flex: none;
  width: 36px; height: 36px; border-radius: 8px; font-size: 1.35rem; line-height: 1; cursor: pointer;
  touch-action: manipulation;
}
.save.on { color: #f59e0b; }
#saved h2 { font-size: 1rem; margin: 20px 0 8px; }
#saved ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#saved li {
  display: flex; align-items: center; gap: 8px; padding: 10px 6px 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid #f59e0b; border-radius: 12px;
}
.saved-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.saved-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-text span { font-size: 0.85rem; color: var(--muted); }
#saved .use {
  flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 600; touch-action: manipulation;
}
#saved .use:disabled { background: transparent; color: var(--muted); border: 1px solid var(--line); cursor: default; }
#saved .rm { display: block; }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 999px; background: #1b1730; color: #fff; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.deal .rm { font-size: 1.15rem; }
