:root {
  --paper: #F5F8FB;      /* milk white, cool */
  --surface: #FFFFFF;
  --gum: #F3C9CF;        /* the arch */
  --gum-deep: #E39CA7;
  --ink: #23324A;        /* navy text */
  --ink-soft: #5D6B82;
  --line: #DCE3EC;
  --enamel: #FFFFFF;
  --loose: #F2B33D;
  --loose-bg: #FDE9BC;
  --go: #2F8A75;         /* primary action */
  --go-ink: #FFFFFF;
  --danger: #B5434E;
  --radius-l: 22px;
  --radius-s: 12px;
  --f-display: "Mali", "Anuphan", system-ui, sans-serif;
  --f-body: "Anuphan", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141A26; --surface: #1C2433; --gum: #5A3540; --gum-deep: #8A4F5C;
    --ink: #EEF2F8; --ink-soft: #A7B2C4; --line: #2C3648; --enamel: #F4F6FA;
    --loose-bg: #6B5320; --go: #49B59A; --go-ink: #0E1A16; --danger: #E07A84;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.6 var(--f-body);
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 480px; margin: 0 auto; min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}
h1, h2 { font-family: var(--f-display); font-weight: 600; line-height: 1.3; margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--go); outline-offset: 2px; border-radius: 6px; }

/* ---- buttons ---- */
.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; font-weight: 600; cursor: pointer;
  min-height: 48px;
}
.btn.primary { background: var(--go); color: var(--go-ink); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid currentColor; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; }
.btn:active { transform: scale(.98); }
.link { background: none; border: 0; color: var(--go); font-weight: 500; padding: 12px; cursor: pointer; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface);
  display: grid; place-items: center; cursor: pointer; box-shadow: 0 0 0 1px var(--line);
}
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 0 14px; min-height: 44px; cursor: pointer; white-space: nowrap; font-size: 15px;
}

/* ---- auth ---- */
.auth { padding-top: 6vh; text-align: center; }
.auth-mark svg { width: 150px; height: auto; }
.auth-mark .crown { fill: var(--enamel); stroke: var(--ink); stroke-width: 1.4; stroke-linejoin: round; }
.auth-mark .mini-loose { fill: var(--loose-bg); stroke: var(--loose); }
.auth h1 { font-size: 34px; margin-top: 8px; }
.lede { color: var(--ink-soft); margin: 8px auto 24px; max-width: 32ch; text-wrap: balance; }
.auth .card { text-align: left; }
.card { background: var(--surface); border-radius: var(--radius-l); padding: 20px; box-shadow: 0 0 0 1px var(--line); }

/* ---- forms ---- */
.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 500; font-size: 15px; }
.form small { color: var(--ink-soft); font-weight: 400; font-size: 13px; }
input, textarea {
  font: inherit; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line); border-radius: var(--radius-s);
  padding: 11px 14px; width: 100%; min-height: 48px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus { outline: none; border-color: var(--go); }
.row { display: flex; gap: 8px; }
.switch { display: flex !important; align-items: center; gap: 12px; cursor: pointer; }
.switch input { width: 24px; height: 24px; min-height: 0; accent-color: var(--loose); }
.err { color: var(--danger); margin: 0; font-size: 14px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; }
.actions .btn.primary { flex: 1; }

/* ---- top bar ---- */
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.brand { font-size: 26px; flex: 1; }
.who { flex: 1; min-width: 0; }
.who h1 { font-size: 24px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--ink-soft); font-size: 14px; }

/* ---- kids list ---- */
.kids { display: grid; gap: 12px; margin-bottom: 20px; }
.kid {
  text-align: left; border: 0; background: var(--surface); border-radius: var(--radius-l);
  padding: 18px 20px; display: grid; gap: 2px; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line), 0 3px 0 0 var(--gum);
}
.kid-name { font-family: var(--f-display); font-size: 22px; font-weight: 600; }
.kid-age { color: var(--ink-soft); font-size: 14px; }
.kid-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 14px; color: var(--ink-soft); }
.kid-stats b { color: var(--ink); font-size: 17px; }
.empty { text-align: center; color: var(--ink-soft); padding: 32px 16px; }

/* ---- tabs ---- */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px;
  background: var(--surface); border-radius: 999px; box-shadow: 0 0 0 1px var(--line);
}
.tabs button {
  border: 0; background: none; border-radius: 999px; min-height: 40px; cursor: pointer;
  font-weight: 500; color: var(--ink-soft);
}
.tabs button[aria-selected="true"] { background: var(--gum); color: var(--ink); font-weight: 600; }

/* ---- the chart ---- */
.chart-wrap { margin: 8px -8px 0; }
.chart { width: 100%; height: auto; display: block; }
.gum { fill: none; stroke: var(--gum); stroke-width: 46; stroke-linecap: round; stroke-linejoin: round; }
.gum.mini { stroke-width: 22; }
.jaw-label, .side-label { font: 500 12px var(--f-body); fill: var(--ink-soft); text-anchor: middle; }
.tooth { cursor: pointer; outline: none; }
.tooth .crown {
  fill: var(--enamel); stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round;
  transition: fill .2s;
}
.tooth.st-none .crown { fill: transparent; stroke: var(--gum-deep); stroke-dasharray: 3 3; stroke-width: 1.4; }
.tooth.st-loose .crown { fill: var(--loose-bg); stroke: var(--loose); stroke-width: 2; }
.tooth.st-lost .gap { fill: none; stroke: var(--gum-deep); stroke-dasharray: 1.5 3; stroke-width: 1.4; }
.tooth.st-lost .star { fill: var(--loose); }
.tooth.overdue .crown { stroke: var(--danger); }
.tooth .num { font: 600 10px var(--f-display); fill: var(--ink-soft); text-anchor: middle; pointer-events: none; }
.tooth:focus-visible .crown, .tooth:focus-visible .gap { stroke: var(--go); stroke-width: 3; stroke-dasharray: none; }
.tooth:active .body { transform: scale(1.12); }
.body { transition: transform .12s; }

/* the one bit of ambient motion: loose teeth wobble */
@keyframes wobble { 0%, 100% { transform: rotate(0) } 25% { transform: rotate(-7deg) } 75% { transform: rotate(7deg) } }
.tooth.st-loose .body { animation: wobble 1.8s ease-in-out infinite; transform-origin: 0 -8px; }
@media (prefers-reduced-motion: reduce) {
  .tooth.st-loose .body { animation: none; }
  #sheet, #sheet-backdrop { transition: none !important; }
}

.hint { text-align: center; color: var(--ink-soft); font-size: 14px; margin: 0 0 16px; }
.tally { display: flex; justify-content: center; gap: 28px; margin: 0 0 12px; }
.tally div { text-align: center; }
.tally dt { font-size: 13px; color: var(--ink-soft); }
.tally dd { margin: 0; font: 600 28px/1.2 var(--f-display); }
.tally small { font-size: 15px; color: var(--ink-soft); font-weight: 500; }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-size: 13px; color: var(--ink-soft); }
.legend li { display: flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 16px; border-radius: 4px 4px 6px 6px; display: inline-block; border: 1.5px solid var(--ink); background: var(--enamel); }
.lg.loose { background: var(--loose-bg); border-color: var(--loose); }
.lg.lost { border: 1.5px dotted var(--gum-deep); background: none; }
.lg.none { border: 1.5px dashed var(--gum-deep); background: none; }

/* ---- timeline ---- */
.timeline { list-style: none; padding: 0; margin: 20px 0 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.ev { position: relative; padding: 0 0 20px 30px; }
.ev::before {
  content: ""; position: absolute; left: 0; top: 6px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--enamel); border: 2px solid var(--ink);
}
.ev.lost::before { background: var(--loose); border-color: var(--loose); }
.ev time { font-size: 13px; color: var(--ink-soft); display: flex; gap: 10px; }
.ev p { margin: 2px 0 0; }
.ev em { font-style: normal; color: var(--ink-soft); font-size: 13px; }
.ev .note { color: var(--ink-soft); font-size: 14px; }

/* ---- bottom sheet ---- */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 26, 38, .35); opacity: 0; transition: opacity .2s; z-index: 10; }
#sheet-backdrop.open { opacity: 1; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; margin: 0 auto; max-width: 480px;
  background: var(--surface); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
#sheet.open { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
#sheet h2 { font-size: 22px; display: flex; align-items: baseline; gap: 8px; }
#sheet .code { font-size: 15px; color: var(--ink-soft); font-weight: 500; }
#sheet .sub { color: var(--ink-soft); font-size: 14px; margin: 4px 0 16px; }
.watch { background: var(--loose-bg); border-radius: var(--radius-s); padding: 10px 14px; font-size: 14px; margin: -4px 0 16px; }
.related {
  width: 100%; margin-top: 16px; text-align: left; border: 0; border-top: 1.5px dashed var(--line);
  background: none; padding: 14px 0 0; cursor: pointer; font-weight: 500;
}
.related span { display: block; font-weight: 400; font-size: 14px; color: var(--ink-soft); }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; z-index: 20;
  font-size: 15px; max-width: calc(100% - 32px);
}
