:root {
  --bg-1: #fff4f8;
  --bg-2: #ffdfeb;
  --card: #ffffffcc;
  --ink: #5b2a43;
  --ink-soft: #9a6a80;
  --pink: #ff6fa5;
  --pink-deep: #e84d8a;
  --pink-pale: #ffe3ee;
  --lilac: #efe3ff;
  --lilac-ink: #7a55a8;
  --error-bg: #fff0f0;
  --error-ink: #b3262e;
  --ok-ink: #2f8f5b;
  --radius: 22px;
  --shadow: 0 10px 30px #ff6fa533;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg-1), var(--bg-2)) fixed;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}

main { max-width: 460px; margin: 0 auto; }

h1 {
  margin: 4px 0 18px;
  text-align: center;
  font-size: 1.35rem;
  letter-spacing: .02em;
  color: var(--pink-deep);
}

[hidden] { display: none !important; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
  margin-bottom: 18px;
  backdrop-filter: blur(6px);
}

/* ---------- the big score ---------- */

.score { position: relative; text-align: center; overflow: hidden; padding: 28px 12px 22px; }

.score .label { margin: 0; font-size: .95rem; color: var(--ink-soft); }

.score #total {
  display: block;
  margin: 6px 0 2px;
  font-size: clamp(76px, 30vw, 150px);
  line-height: 1.05;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--pink-deep);
  text-shadow: 0 4px 0 #ffc2d9;
}

#total.pop { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }

@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.18) rotate(-2deg); }
  100% { transform: scale(1); }
}

.conn { margin: 0; font-size: .8rem; color: var(--ink-soft); min-height: 1.2em; }
.conn.offline { color: var(--error-ink); }

#burst { position: absolute; inset: 0; pointer-events: none; }

.float {
  position: absolute;
  bottom: 28%;
  font-size: 1.5rem;
  opacity: 0;
  animation: floatUp var(--d, 1.2s) ease-out forwards;
}

@keyframes floatUp {
  0% { transform: translate(0, 0) scale(.6); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(var(--x, 0), -170px) scale(1.15); opacity: 0; }
}

/* ---------- history ---------- */

h2 { margin: 0 0 10px; font-size: 1.05rem; color: var(--ink); }

#history { list-style: none; margin: 0; padding: 0; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px dashed #ffc2d9;
}
.entry:first-child { border-top: 0; }

.chip {
  flex: none;
  min-width: 58px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.entry.up .chip { background: var(--pink-pale); color: var(--pink-deep); }
.entry.down .chip { background: var(--lilac); color: var(--lilac-ink); }

.entry .body { min-width: 0; }
.entry .reason { margin: 0; overflow-wrap: anywhere; }
.entry .when { margin: 2px 0 0; font-size: .8rem; color: var(--ink-soft); }
.empty { color: var(--ink-soft); text-align: center; padding: 8px 0; }

/* ---------- admin ---------- */

label { display: block; font-size: .85rem; color: var(--ink-soft); margin: 0 0 6px 2px; }

input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  font: inherit;
  font-size: 16px; /* stops iOS from zooming in */
  color: var(--ink);
  padding: 14px 16px;
  border: 2px solid #ffc2d9;
  border-radius: 16px;
  background: #fff;
  outline: none;
}
input:focus { border-color: var(--pink); }

button {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 18px;
  cursor: pointer;
  color: #fff;
  background: var(--pink);
  padding: 16px 12px;
  min-height: 56px;
  box-shadow: 0 5px 0 var(--pink-deep);
  transition: transform .08s, box-shadow .08s;
}
button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--pink-deep); }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

button.minus { background: #b79bdc; box-shadow: 0 5px 0 #8f72b8; }
button.minus:active { box-shadow: 0 1px 0 #8f72b8; }
button.ghost { background: #fff; color: var(--pink-deep); box-shadow: 0 5px 0 #ffc2d9; }
button.ghost:active { box-shadow: 0 1px 0 #ffc2d9; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.quick button { font-size: 1.35rem; padding: 18px 4px; }

.field { margin-bottom: 14px; }

.custom { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.custom .field { margin: 0; }

.undo-row { margin-top: 4px; }
.undo-row button { width: 100%; }

#status { min-height: 1.6em; margin: 12px 2px 0; text-align: center; font-weight: 700; }
#status.saved { color: var(--ok-ink); }

.error {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--error-bg);
  color: var(--error-ink);
  border: 2px solid #f3b4b8;
  font-weight: 700;
}
.error p { margin: 0 0 10px; }
.error button { width: 100%; background: var(--error-ink); box-shadow: 0 5px 0 #7c1a20; }
.error button:active { box-shadow: 0 1px 0 #7c1a20; }

.msg { margin: 10px 2px 0; font-size: .9rem; color: var(--error-ink); font-weight: 700; min-height: 1.3em; }
.hint { margin: 10px 2px 0; font-size: .85rem; color: var(--ink-soft); }

.mini-total { text-align: center; margin: 0 0 14px; color: var(--ink-soft); }
.mini-total strong { display: inline-block; color: var(--pink-deep); font-size: 1.8rem; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  #total.pop, .float { animation: none; }
  button { transition: none; }
}
