:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #66737d;
  --line: #d9e1e6;
  --paper: #fbfcfd;
  --panel: #ffffff;
  --green: #16794c;
  --red: #b43c36;
  --blue: #245da8;
  --amber: #9b6a12;
  --tire: #26323a;
  --sky: #eaf5ff;
  --sun: #ffd166;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(234, 245, 255, 0.95), rgba(251, 252, 253, 0.98) 42%),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.road-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 12%, rgba(255, 209, 102, 0.35), transparent 16rem),
    linear-gradient(115deg, transparent 0 58%, rgba(38, 50, 58, 0.08) 58% 64%, transparent 64%),
    repeating-linear-gradient(115deg, transparent 0 46px, rgba(36, 93, 168, 0.07) 46px 52px);
}

.road-bg::after {
  content: "🚗  🚙  🏎️";
  position: absolute;
  right: 4vw;
  bottom: 2vh;
  font-size: clamp(3rem, 11vw, 8rem);
  opacity: 0.12;
  transform: rotate(-8deg);
  white-space: nowrap;
}

.theme-space {
  --blue: #4f46e5;
  --green: #0f9f8f;
  --paper: #f7f7ff;
}

.theme-space .road-bg {
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.9) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 18%, rgba(255, 255, 255, 0.85) 0 2px, transparent 3px),
    linear-gradient(180deg, rgba(36, 33, 88, 0.16), rgba(247, 247, 255, 0.96));
}

.theme-space .road-bg::after {
  content: "🚀  🪐  ✨";
}

.theme-ocean {
  --blue: #087f8c;
  --green: #0b8f61;
  --paper: #f0fbfc;
}

.theme-ocean .road-bg {
  background:
    radial-gradient(circle at 14% 14%, rgba(125, 211, 252, 0.35), transparent 16rem),
    repeating-linear-gradient(165deg, rgba(8, 127, 140, 0.08) 0 12px, transparent 12px 34px),
    linear-gradient(180deg, rgba(240, 251, 252, 0.98), rgba(255, 255, 255, 0.95));
}

.theme-ocean .road-bg::after {
  content: "🌊  🏄  ⛵";
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(36, 93, 168, 0.22);
}

.appbar nav {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

.appbar a {
  color: var(--blue);
  text-decoration: none;
}

.login-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 24px;
}

.app-menu {
  display: flex;
  gap: 8px;
  margin: 16px 0 4px;
  padding: 8px;
  overflow-x: auto;
  border: 1px solid rgba(36, 93, 168, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.menu-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  text-decoration: none;
}

.menu-link.active {
  background: var(--blue);
  color: #fff;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-strip {
  margin-top: 20px;
  min-height: 150px;
  display: flex;
  align-items: center;
  padding: 22px;
  border: 1px solid rgba(36, 93, 168, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(222, 242, 255, 0.86)),
    radial-gradient(circle at 82% 22%, rgba(255, 209, 102, 0.42), transparent 9rem);
  box-shadow: 0 18px 44px rgba(23, 32, 38, 0.08);
  overflow: hidden;
  position: relative;
}

.hero-strip::after {
  content: "🛣️";
  position: absolute;
  right: 24px;
  bottom: -22px;
  font-size: clamp(4rem, 12vw, 9rem);
  opacity: 0.18;
}

.parent-hero::after {
  content: "🏁";
}

.theme-space .hero-strip::after {
  content: "🌕";
}

.theme-ocean .hero-strip::after {
  content: "🌊";
}

.hero-strip h2 {
  margin-bottom: 6px;
  font-size: clamp(1.35rem, 3vw, 2.2rem);
}

.hero-strip p {
  margin: 0;
  color: var(--muted);
  max-width: 34rem;
}

.hero-emoji {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 10px 22px rgba(23, 32, 38, 0.1);
  font-size: 2rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 18px;
  font-size: 1.15rem;
}

.total {
  min-width: 170px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: right;
}

.total span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.total strong {
  display: block;
  font-size: 2rem;
}

.notice {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid #c9ddb9;
  border-radius: 8px;
  background: #f4faee;
  color: #355f1f;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.person-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  min-height: 172px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 30px rgba(23, 32, 38, 0.06);
}

.person-card.fancy {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(240, 248, 255, 0.9)),
    var(--panel);
}

.person-card p,
.empty {
  color: var(--muted);
}

.balance {
  color: var(--green);
  font-size: clamp(2.6rem, 7vw, 4.8rem);
  line-height: 0.9;
}

dl {
  display: flex;
  grid-column: 1 / -1;
  gap: 32px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 0.82rem;
}

dd {
  margin: 3px 0 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.workbench {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.workbench.three {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.panel {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 30px rgba(23, 32, 38, 0.05);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.entry-form,
.history {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
}

.entry-form.narrow {
  max-width: 420px;
}

.entry-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 48px;
  padding: 0 11px;
  border: 1px solid #b8c4cc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

button[type="submit"] {
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.table-wrap {
  overflow-x: auto;
}

.history-list {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 690px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-width: 70px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: capitalize;
}

.pill.credit {
  background: var(--green);
}

.pill.free_credit,
.pill.goal_credit,
.pill.correction {
  background: var(--blue);
}

.pill.redeem,
.pill.deduct,
.pill.savings,
.pill.investing {
  background: var(--amber);
}

.icon-button {
  width: 30px;
  height: 30px;
  border: 1px solid #e2b7b4;
  border-radius: 6px;
  background: #fff5f4;
  color: var(--red);
  font-size: 1.2rem;
  line-height: 1;
}

.delete-button {
  width: 100%;
  border: 1px solid #e2b7b4;
  background: #fff5f4;
  color: var(--red);
}

.money-card {
  display: block;
}

.progress {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf1;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.history-card form {
  display: grid;
  gap: 8px;
}

.theme-form {
  display: grid;
  gap: 14px;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.theme-choice {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.theme-choice input {
  width: 20px;
  height: 20px;
}

.theme-choice span {
  font-size: 1.6rem;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.ledger-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

.pager.bottom {
  margin: 12px 0 0;
}

.pager-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  text-decoration: none;
}

.pager-link.disabled {
  pointer-events: none;
  opacity: 0.45;
  color: var(--muted);
}

.history-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  min-width: 0;
  overflow: hidden;
}

.history-card.mini {
  display: grid;
  gap: 10px;
  align-content: start;
}

.history-card.mini div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-width: 0;
  flex-wrap: wrap;
}

.history-card.mini span,
.history-card small {
  color: var(--muted);
}

.history-card.mini p {
  margin: 0;
  overflow-wrap: anywhere;
}

.history-card.mini strong,
.history-card.mini span,
.history-card small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.kid-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.kid-detail {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
}

.kid-detail header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.kid-detail h3,
.kid-detail h4 {
  margin: 0;
}

.kid-detail h4 {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.compact-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.compact-list .history-card {
  padding: 10px;
}

.history-card.audit {
  border-color: #bfd2ee;
  background: #f7fbff;
}

.ledger-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 8px;
  align-items: stretch;
}

.inline-edit {
  display: grid;
  grid-template-columns: minmax(96px, 0.7fr) minmax(160px, 1fr) 96px;
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.inline-edit label {
  font-size: 0.78rem;
}

.inline-edit input {
  height: 40px;
}

.inline-edit button {
  min-height: 40px;
}

.cancel-form {
  display: grid;
  align-items: end;
}

.canceled {
  display: inline-flex;
  width: fit-content;
  padding: 6px 8px;
  border-radius: 999px;
  background: #eef3f7;
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 24px, 720px);
  }

  .topbar,
  .workbench,
  .workbench.three,
  .login-grid {
    display: block;
  }

  .total,
  .entry-form,
  .history,
  .panel {
    margin-top: 18px;
  }

  .balance-grid {
    grid-template-columns: 1fr;
  }

  .theme-grid {
    grid-template-columns: 1fr;
  }

  .kid-detail-grid {
    grid-template-columns: 1fr;
  }

  .appbar nav {
    margin-top: 12px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: 100%;
    padding: 14px 12px 24px;
  }

  .topbar {
    align-items: stretch;
    padding-bottom: 16px;
  }

  h1 {
    font-size: 2rem;
  }

  .total {
    min-width: 0;
    text-align: left;
  }

  .balance-grid {
    gap: 12px;
    margin: 16px 0;
  }

  .person-card {
    min-height: 142px;
    padding: 18px;
  }

  .balance {
    font-size: 3.2rem;
  }

  dl {
    gap: 24px;
  }

  .entry-form,
  .history,
  .panel {
    padding: 16px;
  }

  .table-wrap {
    display: none;
  }

  .history-list {
    display: grid;
    gap: 10px;
  }

  .history-card {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .history-card > div:first-child,
  .history-card-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .history-card span {
    color: var(--muted);
    font-size: 0.84rem;
  }

  .history-card-main b {
    font-size: 1.35rem;
  }

  .history-card p {
    margin: 0;
    color: var(--ink);
    overflow-wrap: anywhere;
  }

  .inline-edit {
    grid-template-columns: 1fr;
  }

  .ledger-actions {
    grid-template-columns: 1fr;
  }
}
