:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #22c55e;
  --red: #f87171;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  /* Kill double-tap-to-zoom and the 300ms tap delay. */
  touch-action: manipulation;
}
html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  /* No bounce/pinch chaining past the page edges. */
  overscroll-behavior: none;
  /* Disallow pinch/text-size scaling on iOS Safari. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-y;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
  /* Prevent accidental text selection on rapid taps. */
  -webkit-user-select: none;
  user-select: none;
}
header {
  text-align: center;
  padding: 24px 0 8px;
}
header h1 { font-size: 1.5rem; margin: 0; }
header p { color: var(--muted); margin: 4px 0 0; font-size: 0.85rem; }

.kid {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin: 14px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.kid-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.kid-name { font-size: 1.15rem; font-weight: 600; }
.kid-weekly { color: var(--muted); font-size: 0.78rem; }
.balance {
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.balance.neg { color: var(--red); }

/* Read-only view: balance centered, no controls row. */
.kid.readonly .balance { display: block; text-align: center; margin-top: 4px; }

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.controls .balance { flex: 1; text-align: center; }
button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  color: var(--text);
}
.step {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--card-2);
  transition: transform 0.05s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step:active { transform: scale(0.92); }
.step.minus { background: #4c2230; color: var(--red); }
.step.plus { background: #14402a; color: var(--green); }
.step:disabled { opacity: 0.4; }

.pay {
  display: block;
  width: fit-content;
  margin: 22px auto 0;
  padding: 8px;
  background: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.pay:active { opacity: 0.6; }
.step-label { text-align: center; color: var(--muted); font-size: 0.75rem; margin-top: 8px; }

/* Footer nav link (e.g. "Parent edit" / "Back to public view"). */
.navlink {
  display: block;
  text-align: center;
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.navlink + .navlink { margin-top: 10px; }

/* Modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.overlay.show { display: flex; }
.modal {
  background: var(--card);
  border-radius: 18px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
}
.modal h2 { margin: 0 0 8px; font-size: 1.2rem; }
.modal p { color: var(--muted); margin: 0 0 14px; font-size: 0.9rem; }
.modal ul { margin: 0 0 18px; padding-left: 18px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; padding: 14px; border-radius: 12px; font-weight: 600; }
.btn-cancel { background: var(--card-2); }
.btn-confirm { background: var(--green); color: #04200f; }

/* Login gate */
.login {
  max-width: 320px;
  margin: 40px auto 0;
  text-align: center;
}
.login input {
  width: 100%;
  padding: 14px;
  margin: 10px 0;
  border-radius: 12px;
  border: 1px solid var(--card-2);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
.login button {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: var(--accent);
  color: #04293a;
  font-size: 1rem;
  font-weight: 700;
}
.login .err { color: var(--red); font-size: 0.85rem; min-height: 1.1em; margin: 4px 0 0; }
.logout {
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 0.8rem;
}
.hidden { display: none !important; }

/* PIN re-lock screen */
.lock {
  max-width: 320px;
  margin: 40px auto 0;
  text-align: center;
}
.lock p { color: var(--muted); margin: 0 0 4px; }
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 18px 0;
}
.pin-dots span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--card-2);
  background: transparent;
  transition: background 0.1s, border-color 0.1s;
}
.pin-dots span.filled {
  background: var(--accent);
  border-color: var(--accent);
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-width: 260px;
  margin: 16px auto 0;
}
.keypad button {
  width: 76px;
  height: 76px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--card-2);
  font-size: 1.5rem;
  font-weight: 600;
  transition: transform 0.05s, background 0.15s;
}
.keypad button:active { transform: scale(0.92); }
.keypad button.ghost {
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.lock.shake { animation: shake 0.3s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
