:root {
  --bg: #fff8ec;
  --card: #ffffff;
  --ink: #23303b;
  --muted: #6b7680;
  --line: #efe4d2;
  --teal: #2a9d8f;
  --teal-d: #1f7a6f;
  --sun: #ffc93c;
  --coral: #ff7a59;
  --plum: #7b5ea7;
  --sky: #4ea8de;
  --good: #2bb673;
  --bad: #e5484d;
  --good-bg: #e6f8ee;
  --bad-bg: #fdecec;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(35, 48, 59, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Lexend", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 800; }
h3 { font-size: 18px; font-weight: 700; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 15px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.topbar .title { font-weight: 800; font-size: 20px; flex: 1; }
.iconbtn {
  border: 0; background: var(--card); width: 44px; height: 44px; border-radius: 14px;
  font-size: 20px; box-shadow: var(--shadow); cursor: pointer; color: var(--ink);
}

.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); border: 2px solid var(--line);
}
.card + .card { margin-top: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 18px; padding: 14px 20px; font: inherit; font-weight: 700;
  font-size: 18px; cursor: pointer; background: var(--teal); color: #fff;
  box-shadow: 0 5px 0 var(--teal-d); transition: transform .06s;
  min-height: 54px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--teal-d); }
.btn.block { width: 100%; }
.btn.sun { background: var(--sun); color: var(--ink); box-shadow: 0 5px 0 #d9a61f; }
.btn.coral { background: var(--coral); box-shadow: 0 5px 0 #d65d3f; }
.btn.plum { background: var(--plum); box-shadow: 0 5px 0 #5d4583; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; border: 2px solid var(--line); }
.btn.small { padding: 8px 14px; min-height: 40px; font-size: 15px; border-radius: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.danger { background: var(--bad); box-shadow: 0 5px 0 #b3363a; }

label { display: block; font-weight: 700; margin: 14px 0 6px; font-size: 16px; }
input, textarea, select {
  width: 100%; font: inherit; font-size: 20px; padding: 14px 16px; border-radius: 16px;
  border: 2px solid var(--line); background: #fff; color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--teal); }
textarea { font-size: 16px; min-height: 160px; }
.err { color: var(--bad); font-weight: 600; margin-top: 10px; font-size: 16px; }

/* Home */
.hello { display: flex; align-items: center; gap: 14px; margin: 6px 0 18px; }
.hello .avatar {
  width: 64px; height: 64px; border-radius: 22px; background: var(--sun);
  display: grid; place-items: center; font-size: 34px; box-shadow: var(--shadow);
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: 20px; padding: 14px; border: 2px solid var(--line); box-shadow: var(--shadow); }
.stat .big { font-size: 30px; font-weight: 800; line-height: 1; }
.stat .lbl { color: var(--muted); font-size: 14px; margin-top: 6px; }
.week { display: flex; justify-content: space-between; gap: 6px; margin-top: 10px; }
.week .d { flex: 1; text-align: center; font-size: 13px; color: var(--muted); }
.week .dot { width: 34px; height: 34px; border-radius: 50%; margin: 4px auto 0; background: #f1e8d8; display: grid; place-items: center; font-size: 16px; }
.week .dot.on { background: var(--coral); color: #fff; }
.week .dot.today { outline: 3px solid var(--sun); }

.tile {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  border: 2px solid var(--line); background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); cursor: pointer; font: inherit; color: inherit;
  margin-bottom: 14px;
}
.tile:active { transform: translateY(2px); }
.tile .emoji { width: 62px; height: 62px; border-radius: 20px; display: grid; place-items: center; font-size: 32px; flex-shrink: 0; }
.tile .t { font-weight: 800; font-size: 19px; }
.tile .s { color: var(--muted); font-size: 15px; }
.tile .badge { margin-left: auto; font-size: 13px; font-weight: 700; padding: 6px 10px; border-radius: 999px; background: var(--good-bg); color: var(--good); white-space: nowrap; }
.bg-teal { background: #d9f2ee; } .bg-sun { background: #fff1c7; } .bg-coral { background: #ffe1d8; } .bg-plum { background: #ebe3f6; } .bg-sky { background: #ddeefa; }

/* Spelling */
.progressbar { height: 12px; background: #f1e8d8; border-radius: 999px; overflow: hidden; margin: 6px 0 16px; }
.progressbar > div { height: 100%; background: var(--teal); border-radius: 999px; transition: width .3s; }
.speak {
  width: 120px; height: 120px; border-radius: 50%; border: 0; background: var(--sun); font-size: 54px;
  box-shadow: 0 7px 0 #d9a61f; cursor: pointer; display: block; margin: 8px auto 12px;
}
.speak:active { transform: translateY(4px); box-shadow: 0 3px 0 #d9a61f; }
.sentence { font-size: 20px; text-align: center; margin: 8px 0 16px; }
.blank { display: inline-block; min-width: 90px; border-bottom: 3px solid var(--ink); }
.spellinput { text-align: center; font-size: 30px; font-weight: 700; letter-spacing: 1px; }
.bigword { font-size: 44px; font-weight: 800; text-align: center; letter-spacing: 1px; margin: 14px 0; word-break: break-word; }
.covered { background: repeating-linear-gradient(45deg, #f1e8d8, #f1e8d8 12px, #f7f0e3 12px, #f7f0e3 24px); color: transparent; border-radius: 16px; user-select: none; }
.feedback { border-radius: 18px; padding: 14px; margin: 14px 0; font-weight: 600; text-align: center; }
.feedback.good { background: var(--good-bg); color: #13784a; }
.feedback.bad { background: var(--bad-bg); color: #9e2a2e; }
.letters { font-size: 34px; font-weight: 800; letter-spacing: 2px; }
.letters .x { background: var(--sun); color: var(--ink); border-radius: 6px; padding: 0 2px; }
.tipbox { background: #fff6dc; border: 2px dashed #f0cf6e; border-radius: 18px; padding: 12px 14px; font-size: 16px; }

/* Choices */
.choice {
  display: block; width: 100%; text-align: left; border: 2px solid var(--line); background: #fff;
  border-radius: 18px; padding: 14px 16px; font: inherit; font-size: 18px; margin-bottom: 10px; cursor: pointer; color: inherit;
}
.choice.right { background: var(--good-bg); border-color: var(--good); }
.choice.wrong { background: var(--bad-bg); border-color: var(--bad); }
.choice:disabled { cursor: default; }

/* Photos */
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 14px; overflow: hidden; background: #f1e8d8; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 4px; right: 4px; border: 0; width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; cursor: pointer; }
.filebtn input { display: none; }

/* Number families */
.family-svg { width: 100%; max-width: 320px; display: block; margin: 0 auto; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.fact { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 12px; text-align: center; font-weight: 800; font-size: 22px; opacity: .15; transition: opacity .3s, transform .3s; transform: scale(.95); }
.fact.show { opacity: 1; transform: none; }
.eq { font-size: 34px; font-weight: 800; text-align: center; margin: 16px 0; }
.eq .box { display: inline-block; min-width: 70px; border: 3px dashed var(--teal); border-radius: 14px; padding: 0 10px; color: var(--teal); }
.levels { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.lvl { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 8px 12px; font: inherit; font-size: 15px; cursor: pointer; color: inherit; }
.lvl.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.lvl:disabled { opacity: .45; cursor: default; }

/* Results */
.celebrate { font-size: 72px; text-align: center; margin: 10px 0; animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.score { font-size: 48px; font-weight: 800; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { background: #f6efe2; border-radius: 999px; padding: 6px 12px; font-size: 15px; font-weight: 600; }
.chip.bad { background: var(--bad-bg); color: #9e2a2e; }
.chip.good { background: var(--good-bg); color: #13784a; }

/* PIN pad & names */
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.namebtn { border: 2px solid var(--line); background: #fff; border-radius: 20px; padding: 18px 10px; font: inherit; font-weight: 800; font-size: 20px; cursor: pointer; color: inherit; box-shadow: var(--shadow); }
.namebtn .e { font-size: 34px; display: block; }
.pindots { display: flex; justify-content: center; gap: 14px; margin: 16px 0; }
.pindots span { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--teal); }
.pindots span.on { background: var(--teal); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 320px; margin: 0 auto; }
.pinpad button { height: 68px; border-radius: 20px; border: 2px solid var(--line); background: #fff; font: inherit; font-size: 28px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); color: inherit; }
.pinpad button:active { transform: translateY(2px); }

/* Parent */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
.cal { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; margin-top: 8px; }
.cal div { aspect-ratio: 1; border-radius: 6px; background: #f1e8d8; }
.cal div.on { background: var(--coral); }
.boxbar { display: flex; height: 16px; border-radius: 999px; overflow: hidden; margin: 8px 0; background: #f1e8d8; }
.boxbar span { height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
details summary { cursor: pointer; font-weight: 700; padding: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 600; transition: transform .25s; z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
.loader { width: 54px; height: 54px; border: 6px solid #f1e8d8; border-top-color: var(--teal); border-radius: 50%; animation: spin 1s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
