:root {
  --bg: #f2f2f7;
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-bg-solid: #ffffff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --brand: #2f9e5c;
  --brand-dark: #227a46;
  --owing: #ff5a3d;
  --owing-bg: rgba(255, 90, 61, 0.12);
  --clear-bg: rgba(52, 199, 89, 0.14);
  --parent-bg: rgba(94, 92, 230, 0.12);
  --border: rgba(60, 60, 67, 0.13);
  --danger: #e0402b;
  --radius: 22px;
  --radius-sm: 14px;
  --touch: 54px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  --blur: blur(20px);
}

* { box-sizing: border-box; }

html { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  color: var(--ink);
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.brand-mark { font-size: 1.3rem; }

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.nav a, .nav .link-btn {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 2px;
  opacity: 0.75;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.nav a:hover, .nav .link-btn:hover { opacity: 1; }

.nav .me {
  display: inline-flex;
  align-items: center;
  opacity: 1;
  font-weight: 700;
}

.nav-icons a, .nav-icons .link-btn {
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.nav-icons a:hover, .nav-icons .link-btn:hover { background: var(--clear-bg); }

.me-avatar {
  font-size: 1.25rem;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--clear-bg);
  border-radius: 50%;
}

.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.card {
  background: var(--card-bg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card.narrow {
  max-width: 420px;
  margin: 40px auto;
}

.card.center {
  text-align: center;
}

h1 { margin-top: 0; letter-spacing: -0.02em; font-weight: 800; }
h2 { margin-top: 0; font-size: 1.1rem; letter-spacing: -0.01em; font-weight: 700; }
h3 { margin-bottom: 8px; font-weight: 700; }
.muted { color: var(--muted); }

.balance-card {
  text-align: center;
  padding: 32px 20px;
  background: var(--clear-bg);
}
.balance-card.is-owing { background: var(--owing-bg); }
.balance-amount {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.balance-amount.small { font-size: 1.5rem; display: inline-block; margin-right: 8px; }
.balance-status { margin-top: 8px; font-weight: 600; color: var(--ink); }

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.92rem;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select {
  font-size: 1rem;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: var(--touch);
  background: rgba(118, 118, 128, 0.08);
  color: var(--ink);
  font-family: inherit;
}
input:focus, select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 14px;
  padding: 14px 20px;
  min-height: var(--touch);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: rgba(118, 118, 128, 0.12);
  color: #1c1c1e;
  transition: transform 0.1s ease, opacity 0.15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(47, 158, 92, 0.35); }
.btn.primary:active { background: var(--brand-dark); }
.btn.ghost { background: transparent; border: 1.5px solid var(--border); color: var(--ink); }
.btn.small { padding: 10px 16px; min-height: 42px; font-size: 0.88rem; }
.btn.wide { width: 100%; }

.inline-form {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin: 6px 6px 6px 0;
  flex-wrap: wrap;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.profile-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 10px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  border: 1px solid var(--border);
  transition: transform 0.12s ease;
}
.profile-btn:active { transform: scale(0.96); }
.profile-btn.is-child { background: var(--clear-bg); }
.profile-btn.is-parent { background: var(--parent-bg); }
.profile-btn .avatar {
  font-size: 2.5rem;
  line-height: 1;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.profile-btn .avatar.avatar-photo { background: var(--clear-bg); }

.pin-display {
  width: 100%;
  text-align: center;
  letter-spacing: 12px;
  font-size: 1.5rem;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px 0;
}
.key {
  min-height: 60px;
  font-size: 1.4rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(118, 118, 128, 0.08);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.1s ease;
  font-family: inherit;
}
.key:active { transform: scale(0.94); background: var(--clear-bg); }
.key-clear, .key-back { font-size: 1rem; }

.flash {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-weight: 600;
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.flash-success { background: var(--clear-bg); color: var(--brand-dark); }
.flash-error { background: var(--owing-bg); color: var(--danger); }

.chore-list, .catalog-list, .ledger-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.chore-item, .catalog-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.chore-item:last-child, .catalog-item:last-child { border-bottom: none; }
.chore-title { font-weight: 700; }
.chore-meta { color: var(--muted); font-size: 0.88rem; margin-bottom: 8px; }
.chore-item.status-approved { border-left: 3px solid var(--brand); padding-left: 12px; }
.chore-item.status-finished { border-left: 3px solid #d9a441; padding-left: 12px; }
.chore-item.status-paid { opacity: 0.65; }
.chore-item.status-rejected { opacity: 0.5; text-decoration: line-through; }

.price-form input[type="number"] { width: 90px; min-height: 44px; }

.kid-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.kid-summary {
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}
.kid-summary.is-clear { background: var(--clear-bg); }
.kid-summary.is-owing { background: var(--owing-bg); }
.kid-name { font-weight: 700; }
.kid-balance { font-size: 1.4rem; font-weight: 800; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kid-obligation { font-size: 0.85rem; color: var(--muted); }

.settings-block {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.settings-block:last-child { border-bottom: none; }

.collapsible summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary h2 { margin: 0; }
.collapsible summary::after {
  content: '▸';
  color: var(--muted);
  font-size: 0.9rem;
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-left: 10px;
}
.collapsible[open] summary::after { transform: rotate(90deg); }
.collapsible .stack { margin-top: 16px; }

.catalog-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.catalog-item.is-retired { opacity: 0.55; }
.catalog-edit-form, .catalog-icon-form { display: contents; }
.catalog-edit-form input[type="text"] { flex: 1 1 140px; min-width: 100px; }
.catalog-edit-form input[type="number"] { width: 70px; flex-shrink: 0; }
.btn-icon {
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(118, 118, 128, 0.1);
  font-size: 1.05rem;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-icon:active { transform: scale(0.94); }
.btn-icon-danger:active { background: var(--owing-bg); }

.ledger-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.ledger-item:last-child { border-bottom: none; }
.ledger-date { color: var(--muted); min-width: 50px; }
.ledger-memo { flex: 1; }
.ledger-item.is-credit .ledger-amount { color: var(--brand-dark); font-weight: 700; font-variant-numeric: tabular-nums; }
.ledger-item.is-debit .ledger-amount { color: var(--danger); font-weight: 700; font-variant-numeric: tabular-nums; }
.ledger-delete-form { margin: 0; }
.ledger-delete-btn {
  border: none;
  background: rgba(118, 118, 128, 0.12);
  color: var(--muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.75rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}
.ledger-delete-btn:active { background: var(--owing-bg); color: var(--danger); }

.remove-link {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
}

.steps {
  padding-left: 20px;
  margin: 10px 0 16px;
}
.steps li {
  margin-bottom: 8px;
  color: var(--ink);
}

.chore-photo-thumb {
  display: block;
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin: 8px 0;
  border: 1px solid var(--border);
}

.finish-form {
  margin-top: 8px;
}
.finish-form input[type="file"] {
  min-height: auto;
  padding: 8px;
  font-size: 0.85rem;
}

/* Avatar & background picker (profile page) */
.avatar-photo { object-fit: cover; }

.avatar-preview {
  display: flex;
  justify-content: center;
  margin: 12px 0;
}
.avatar-preview-img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: var(--clear-bg);
  border: 2px solid var(--border);
}

.spaced-top { margin-top: 16px; }

.avatar-grid, .preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.avatar-option {
  font-size: 1.8rem;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  background: rgba(118, 118, 128, 0.08);
  cursor: pointer;
  transition: transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-option:active { transform: scale(0.92); }
.avatar-option.is-selected { border-color: var(--brand); background: var(--clear-bg); }

.preset-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.preset-form { display: contents; }
.preset-option {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 3px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  padding: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  transition: transform 0.1s ease;
}
.preset-option:active { transform: scale(0.95); }
.preset-option.is-selected { border-color: var(--ink); }
.upload-form { margin-top: 18px; }

/* Preset gradients — used both on body backgrounds and picker swatches */
.bg-preset-sunset { background: linear-gradient(160deg, #ff9a56, #ff6a88 60%, #ff99ac); }
.bg-preset-ocean { background: linear-gradient(160deg, #2193b0, #6dd5ed); }
.bg-preset-forest { background: linear-gradient(160deg, #134e5e, #71b280); }
.bg-preset-lavender { background: linear-gradient(160deg, #8e78c9, #fbc2eb); }
.bg-preset-peach { background: linear-gradient(160deg, #f6a97a, #fcb69f); }
.bg-preset-mint { background: linear-gradient(160deg, #10a37f, #38f9d7); }
.bg-preset-midnight { background: linear-gradient(160deg, #0f2027, #203a43 60%, #2c5364); }
.bg-preset-candy { background: linear-gradient(160deg, #f66a8f, #fecfef); }

body[class*="bg-preset-"] {
  background-attachment: fixed;
  background-size: cover;
}
body.has-user[style*="background-image"] {
  background-position: center;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card-bg: rgba(28, 28, 30, 0.72);
    --card-bg-solid: #1c1c1e;
    --ink: #f2f2f7;
    --muted: #98989f;
    --border: rgba(255, 255, 255, 0.14);
    --clear-bg: rgba(48, 209, 88, 0.18);
    --parent-bg: rgba(94, 92, 230, 0.22);
    --owing-bg: rgba(255, 69, 58, 0.2);
  }
  .topbar { background: rgba(28, 28, 30, 0.6); }
  input[type="text"], input[type="password"], input[type="number"], input[type="file"], select, .key {
    background: rgba(118, 118, 128, 0.24);
    color: var(--ink);
    border-color: var(--border);
  }
  .btn { background: rgba(118, 118, 128, 0.24); color: var(--ink); }
  .btn.ghost { color: var(--ink); }
  .me-avatar { background: rgba(118, 118, 128, 0.24); }
  .avatar-preview-img { background: rgba(118, 118, 128, 0.24); }
  .profile-btn .avatar.avatar-photo { background: rgba(118, 118, 128, 0.24); }
}

@media (max-width: 480px) {
  .balance-amount { font-size: 2.4rem; }
  .content { padding: 16px 12px 50px; }
}
