/* Split — balanced groups. Dark, glassy, self-contained. */

:root {
  --bg: #08080c;
  --ink: #ecebf3;
  --ink-dim: #a5a3b8;
  --ink-faint: #6e6c85;
  --panel: rgba(255, 255, 255, .038);
  --panel-2: rgba(255, 255, 255, .055);
  --line: rgba(255, 255, 255, .085);
  --line-soft: rgba(255, 255, 255, .05);
  --violet: #8b6eff;
  --cyan: #38bdf8;
  --mint: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
  --grad: linear-gradient(115deg, var(--violet), var(--cyan) 55%, var(--mint));
  --r: 18px;
  --shadow: 0 24px 60px -24px rgba(0, 0, 0, .85);
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- background ---------- */
.aurora { position: fixed; inset: -20vmax; z-index: 0; pointer-events: none; filter: blur(90px); opacity: .55; }
.aurora i {
  position: absolute; display: block; border-radius: 50%;
  width: 62vmax; height: 62vmax;
  mix-blend-mode: screen;
  animation: drift 34s ease-in-out infinite;
}
.aurora i:nth-child(1) { background: radial-gradient(circle at 50% 50%, #6d3cff, transparent 62%); top: -14%; left: -10%; }
.aurora i:nth-child(2) { background: radial-gradient(circle at 50% 50%, #0ea5e9, transparent 62%); top: 8%; right: -18%; left: auto; animation-duration: 44s; animation-direction: reverse; }
.aurora i:nth-child(3) { background: radial-gradient(circle at 50% 50%, #10b981, transparent 64%); bottom: -26%; left: 24%; top: auto; animation-duration: 52s; opacity: .7; }
@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  33%      { transform: translate3d(6vmax, -5vmax, 0) scale(1.12); }
  66%      { transform: translate3d(-5vmax, 4vmax, 0) scale(.94); }
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 0%, transparent 40%, rgba(4, 4, 8, .85) 100%);
}

/* ---------- layout ---------- */
.wrap {
  position: relative; z-index: 2;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 72px) clamp(16px, 4vw, 32px) 80px;
}

.head { text-align: center; margin-bottom: clamp(26px, 5vw, 44px); }
.mark { display: inline-flex; gap: 5px; align-items: flex-end; height: 30px; margin-bottom: 14px; }
.mark i { width: 9px; border-radius: 5px; display: block; animation: bob 3.4s ease-in-out infinite; }
.mark i:nth-child(1) { height: 20px; background: var(--violet); }
.mark i:nth-child(2) { height: 30px; background: var(--cyan); animation-delay: .35s; }
.mark i:nth-child(3) { height: 24px; background: var(--mint); animation-delay: .7s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

h1 {
  margin: 0;
  font-size: clamp(40px, 8vw, 68px);
  letter-spacing: -.045em;
  font-weight: 700;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.tag { margin: 10px auto 0; max-width: 46ch; color: var(--ink-dim); font-size: clamp(14px, 2.4vw, 16.5px); }

/* ---------- panels ---------- */
.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: clamp(16px, 3vw, 24px);
  margin-bottom: 18px;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: var(--shadow);
}
.panel-title {
  margin: 0 0 12px;
  font-size: 11.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-faint);
}

/* ---------- entry ---------- */
.entry { display: flex; gap: 10px; }
#entry {
  flex: 1; min-width: 0;
  font: inherit; font-size: clamp(16px, 2.6vw, 19px);
  color: var(--ink);
  background: rgba(0, 0, 0, .28);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 14px 16px;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
#entry::placeholder { color: var(--ink-faint); }
#entry:focus {
  outline: none;
  border-color: rgba(139, 110, 255, .65);
  box-shadow: 0 0 0 4px rgba(139, 110, 255, .14);
  background: rgba(0, 0, 0, .4);
}

.hint { margin: 10px 2px 0; font-size: 12.5px; color: var(--ink-faint); }
.hint .sep { opacity: .45; margin: 0 3px; }
.hint code {
  font-family: var(--mono); font-size: 11.5px;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--line-soft);
  padding: 1.5px 6px; border-radius: 6px; color: var(--ink-dim);
}
kbd {
  font-family: var(--mono); font-size: 11px;
  background: rgba(255, 255, 255, .09); border: 1px solid var(--line);
  border-bottom-width: 2px;
  padding: 2px 6px; border-radius: 6px; color: var(--ink-dim);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 550; font-size: 15px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .12s, background .18s, border-color .18s, opacity .18s;
}
.btn:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .16); }
.btn:active { transform: scale(.975); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-faint); padding: 8px 12px; font-size: 13px; }
.btn.ghost:hover { color: var(--ink); background: rgba(255, 255, 255, .07); }
.btn.primary {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--grad);
  border: none; color: #0a0a10; font-weight: 700; font-size: 16.5px;
  padding: 15px 26px;
  box-shadow: 0 10px 30px -10px rgba(139, 110, 255, .75);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary kbd { background: rgba(0, 0, 0, .18); border-color: rgba(0, 0, 0, .2); color: rgba(0, 0, 0, .6); }
.btn.primary:disabled { opacity: .4; cursor: not-allowed; filter: none; box-shadow: none; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 6px 6px 13px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.3);
}
.chip .lab { color: var(--ink-faint); font-size: 12.5px; max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .val { font-weight: 600; }
.chip button {
  all: unset;
  cursor: pointer; line-height: 1;
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink-faint); font-size: 15px;
  transition: background .15s, color .15s;
}
.chip button:hover { background: rgba(251, 113, 133, .2); color: var(--rose); }
.chip button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }
@keyframes pop { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: scale(1); } }

/* ---------- tally ---------- */
.tally { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 22px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.grow { flex: 1; }
.stat { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12.5px; color: var(--ink-faint); }
.stat b { font-size: 17px; color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 26px; }
.controls > * { min-width: 0; }
.ctl { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; min-width: 0; }
.ctl .panel-title { margin: 0; }

.stepper { display: inline-flex; align-items: center; background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.step {
  all: unset; cursor: pointer;
  width: 40px; height: 46px; display: grid; place-items: center;
  font-size: 19px; color: var(--ink-dim); transition: background .15s, color .15s;
}
.step:hover { background: rgba(255, 255, 255, .08); color: var(--ink); }
.step:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }
#k {
  width: 58px; height: 46px; text-align: center;
  font: inherit; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink); background: transparent; border: none;
  border-left: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft);
  -moz-appearance: textfield;
}
#k::-webkit-outer-spin-button, #k::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#k:focus { outline: none; background: rgba(139, 110, 255, .12); }

/* must wrap — otherwise its min-content width sets a floor for the whole page */
.presets { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.presets button {
  all: unset; cursor: pointer;
  min-width: 32px; height: 32px; padding: 0 8px;
  display: grid; place-items: center; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-faint);
  border: 1px solid transparent;
  transition: all .15s;
}
.presets button:hover { color: var(--ink); background: rgba(255, 255, 255, .07); }
.presets button[aria-pressed="true"] { color: var(--ink); background: rgba(139, 110, 255, .2); border-color: rgba(139, 110, 255, .45); }
.presets button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 11px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.track { width: 42px; height: 24px; border-radius: 999px; background: rgba(255, 255, 255, .11); border: 1px solid var(--line); position: relative; transition: background .2s; flex: none; }
.knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink-dim); transition: transform .22s cubic-bezier(.2, .9, .3, 1.2), background .2s; }
.switch input:checked + .track { background: rgba(139, 110, 255, .55); border-color: rgba(139, 110, 255, .7); }
.switch input:checked + .track .knob { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--cyan); outline-offset: 2px; }
.switch-text { font-size: 14px; color: var(--ink-dim); display: flex; flex-direction: column; }
.switch-text em { font-style: normal; font-size: 12px; color: var(--ink-faint); }

.warn {
  margin: -4px 2px 18px; padding: 11px 15px;
  border-radius: 12px; font-size: 13.5px;
  background: rgba(251, 191, 36, .1); border: 1px solid rgba(251, 191, 36, .3); color: #fcd77c;
}

/* ---------- results ---------- */
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; margin: 26px 4px 16px; }
.summary h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.summary .verdict { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-dim); }
.summary .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 12px currentColor; color: var(--mint); }
.summary .dot.warm { background: var(--amber); color: var(--amber); }
.summary .actions { margin-left: auto; display: flex; gap: 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }

.group {
  position: relative; overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: var(--shadow);
  opacity: 0;
  animation: rise .42s cubic-bezier(.16, 1, .3, 1) forwards;
  animation-delay: var(--d, 0ms);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

.group::before {
  content: ""; position: absolute; top: 0; left: 0; height: 3px;
  width: var(--fill, 100%);
  background: var(--accent, var(--violet));
  box-shadow: 0 0 18px -2px var(--accent, var(--violet));
  transition: width .5s cubic-bezier(.16, 1, .3, 1);
}

.group h3 { margin: 0; font-size: 11.5px; font-weight: 650; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-faint); }
.group .sum { display: flex; align-items: baseline; gap: 9px; margin: 6px 0 2px; }
.group .sum b { font-size: 31px; font-weight: 700; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.group .off { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink-faint); }
.group .off.pos { color: var(--amber); }
.group .off.neg { color: var(--cyan); }
.group .off.exact { color: var(--mint); }
.group .n { font-size: 12px; color: var(--ink-faint); }

.items { list-style: none; margin: 14px 0 0; padding: 13px 0 0; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 7px; }
.items li { display: flex; align-items: baseline; gap: 10px; font-size: 14px; font-variant-numeric: tabular-nums; }
.items .lab { color: var(--ink-dim); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .v { font-weight: 600; margin-left: auto; }
.items .empty { color: var(--ink-faint); font-style: italic; font-size: 13px; }

.blank { text-align: center; color: var(--ink-faint); font-size: 14px; padding: 40px 20px; border: 1px dashed var(--line); border-radius: var(--r); }

.foot { margin-top: 46px; text-align: center; font-size: 12px; color: var(--ink-faint); }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 20;
  transform: translate(-50%, 20px);
  background: rgba(20, 20, 28, .92); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
  box-shadow: var(--shadow);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.sr-copy { position: fixed; top: -1000px; left: -1000px; opacity: 0; }

/* Tablets and narrow windows: the controls row gets cramped well before it
   actually overflows, so give Split its own full-width line early. */
@media (max-width: 820px) {
  .controls { flex-direction: column; align-items: stretch; }
  .ctl { justify-content: space-between; }
  .btn.primary { width: 100%; }
}

@media (max-width: 560px) {
  .on-desk { display: none; }
  .summary .actions { margin-left: 0; width: 100%; justify-content: flex-start; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 380px) {
  .panel { padding: 15px; }
  .entry { flex-direction: column; }
  #add { width: 100%; }
  .stepper { flex: 1; }
  #k { flex: 1; width: auto; }
  .switch-text em { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .group { opacity: 1; }
}
