@font-face {
  font-family: "Baloo 2";
  src: url("../fonts/Baloo2.ttf") format("truetype");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --ink: #5a3e5c;
  --bg: #fff4f0;
  --card: #fff;
  --pink: #ffb3cb;
  --peach: #ffd2b0;
  --lemon: #ffe58a;
  --mint: #b4ecd4;
  --sky: #b3dcff;
  --lav: #dccfff;
  --danger: #ff8a8a;
  --muted: #8a6d8c;
  --shadow: 0 5px 0 var(--ink);
  font-family: "Baloo 2", "Segoe UI", "Comic Sans MS", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-size: 17px;
  line-height: 1.45;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 159, 189, .28) 2px, transparent 2.5px) 0 0 / 28px 28px,
    linear-gradient(180deg, #ffeaf2 0%, var(--bg) 45%, #eaf6ff 100%);
  background-attachment: fixed;
}

h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.7rem; line-height: 1.15; }
h3 { font-size: 1.2rem; line-height: 1.2; margin-bottom: .4rem; }
a { color: inherit; }
small { font-size: .8em; opacity: .8; }
.muted { color: var(--muted); font-size: .95rem; }
.grow { flex: 1; }

/* ---------- decorations ---------- */
#bg { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.deco { position: absolute; width: 90px; opacity: .55; animation: float 7s ease-in-out infinite; }
.deco svg { width: 100%; display: block; }
.d0 { top: 14%; left: 3%; width: 120px; }
.d1 { top: 26%; right: 4%; animation-delay: -2s; }
.d2 { bottom: 12%; left: 6%; width: 60px; animation-delay: -4s; }
.d3 { bottom: 20%; right: 3%; width: 140px; animation-delay: -1s; }
.d4 { top: 62%; left: 1%; width: 50px; animation-delay: -3s; }
.d5 { top: 8%; right: 12%; width: 54px; animation-delay: -5s; }
@keyframes float { 50% { transform: translateY(-16px) rotate(6deg); } }

#app { position: relative; z-index: 1; max-width: 1120px; margin: 0 auto; padding: 16px 16px 40px; }

/* ---------- building blocks ---------- */
.card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.btn {
  font: inherit; font-weight: 700; color: var(--ink);
  background: var(--lemon);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 18px;
  min-height: 44px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s, box-shadow .12s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--pink); }
.btn.ghost { background: #fff; }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 36px; padding: 2px 14px; font-size: .95rem; }
.btn.wide { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: .6; cursor: wait; }
:focus-visible { outline: 4px solid #6c9cff; outline-offset: 2px; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.pill {
  display: inline-block; font-weight: 600; font-size: .92rem;
  background: var(--lemon); border: 2px solid var(--ink); border-radius: 999px; padding: 0 12px;
}
.pill.pink { background: var(--pink); }
.pill.sky { background: var(--sky); }
.pill.mint { background: var(--mint); }
.pill.gold { background: #ffd43b; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip {
  font: inherit; font-weight: 600; color: var(--ink); background: #fff;
  border: 3px solid var(--ink); border-radius: 999px; padding: 2px 16px; min-height: 40px; cursor: pointer;
}
.chip.on { background: var(--pink); }

.grid { display: grid; gap: 18px; margin: 18px 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stack { display: grid; gap: 18px; margin: 18px 0; }

.tile {
  background: var(--c, var(--lemon));
  border: 3px solid var(--ink); border-radius: 22px; box-shadow: var(--shadow);
  padding: 10px 14px; text-align: center; text-decoration: none; display: grid;
  transition: transform .12s;
}
a.tile:hover { transform: translateY(-3px) rotate(-1.5deg); }
.tile b { font-size: 2.2rem; line-height: 1.1; }

.sec-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-end; margin: 22px 0 12px; }
.sec-head p { color: var(--muted); margin-top: 2px; }
.sec-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.back { display: inline-block; margin-top: 18px; font-weight: 700; }

.empty { text-align: center; padding: 30px 20px; display: grid; gap: 12px; justify-items: center; margin-top: 18px; }
.empty-emoji { font-size: 3.4rem; animation: float 4s ease-in-out infinite; }

.note { background: #fff8e1; border-radius: 14px; padding: 8px 12px; margin: 8px 0; white-space: pre-wrap; }

.info { margin: 0; display: grid; gap: 8px; }
.info div { display: grid; grid-template-columns: 9.5em 1fr; gap: 8px; }
.info dt { font-weight: 700; }
.info dd { margin: 0; overflow-wrap: anywhere; }
.info.compact { gap: 2px; font-size: .95rem; margin: 8px 0; }

/* ---------- header & nav ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 4px 0 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand h1 { font-size: 1.9rem; line-height: 1; }
.brand p { color: var(--muted); font-size: .95rem; }
.brand-art { width: 64px; height: 64px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.top-btns { display: flex; gap: 10px; }

.tabs {
  display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 4px 12px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(180deg, #ffeaf2 70%, transparent);
}
.tab {
  flex: none; text-decoration: none; font-weight: 700;
  background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 4px 16px; min-height: 44px;
  display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 4px 0 var(--ink);
  transition: transform .12s;
}
.tab:hover { transform: translateY(-2px); }
.tab.on { background: var(--pink); transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.tab span { font-size: 1.2rem; }
.tab i { font-style: normal; }

footer { text-align: center; margin-top: 36px; color: var(--muted); display: grid; justify-items: center; gap: 4px; }
.foot-art { width: 70px; animation: bob 3.5s ease-in-out infinite; }

.art { display: block; height: auto; }
.avatar .art, .medal .art, .empty .art { width: 100%; }

/* ---------- home ---------- */
.hero { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; background: linear-gradient(135deg, #fff 0%, #ffeaf2 100%); margin-top: 8px; }
.avatar {
  width: 150px; height: 150px; flex: none; border-radius: 50%; overflow: hidden;
  border: 4px solid var(--ink); box-shadow: 0 5px 0 var(--ink); background: var(--lemon);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; display: block; }
.avatar .art { padding: 10px; }
.hero-text { flex: 1; min-width: 240px; display: grid; gap: 4px; }
.hero h2 { font-size: 2.1rem; }
.nick { font-size: 1.3rem; font-weight: 700; color: #e0558a; }
.hero .row { margin-top: 6px; }

.family { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.family li { display: flex; gap: 10px; align-items: baseline; }
.role { background: var(--sky); border: 2px solid var(--ink); border-radius: 999px; padding: 0 12px; font-weight: 700; font-size: .9rem; flex: none; min-width: 5.2em; text-align: center; }
.family li:nth-child(2n) .role { background: var(--pink); }
.family li:nth-child(3n) .role { background: var(--mint); }

.hobbies { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.hobbies li {
  display: flex; align-items: center; gap: 8px; font-weight: 600;
  background: var(--lav); border: 2px solid var(--ink); border-radius: 999px; padding: 2px 16px 2px 8px;
}
.hobbies li:nth-child(3n+1) { background: var(--lemon); }
.hobbies li:nth-child(3n+2) { background: var(--mint); }
.hobbies li span { font-size: 1.4rem; }

/* ---------- timetable ---------- */
.week { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.day { display: grid; gap: 10px; align-content: start; padding: 14px; }
.day h3 { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0; }
.day.today { background: #fff8e1; }
.slot {
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
  background: var(--c); border: 3px solid var(--ink); border-radius: 16px; padding: 6px 12px; display: grid;
  box-shadow: 0 3px 0 var(--ink); transition: transform .12s;
}
.slot:hover { transform: translateY(-2px) rotate(-1deg); }
.slot b { font-size: 1.05rem; }
.slot em { font-size: .9rem; opacity: .85; }

/* ---------- achievements ---------- */
.ach { display: flex; gap: 18px; }
.medal { width: 84px; flex: none; animation: bob 4s ease-in-out infinite; }
.ach-body { flex: 1; min-width: 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.thumb {
  padding: 0; cursor: pointer; width: 84px; height: 84px; overflow: hidden;
  border: 3px solid var(--ink); border-radius: 14px; background: var(--sky);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { transform: scale(1.05) rotate(-1.5deg); }

/* ---------- albums ---------- */
.albums { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.album { padding: 0; overflow: hidden; text-decoration: none; transition: transform .12s; }
.album:hover { transform: translateY(-4px) rotate(-1deg); }
.cover { position: relative; aspect-ratio: 4 / 3; background: var(--sky); display: grid; place-items: center; font-size: 4rem; border-bottom: 3px solid var(--ink); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 25%; }
.count { position: absolute; right: 10px; bottom: 10px; font-size: .9rem; font-weight: 700; background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 0 10px; }
.album-info { padding: 12px 16px 14px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin: 18px 0; }
.thumb.big { width: 100%; height: auto; aspect-ratio: 1; box-shadow: 0 4px 0 var(--ink); }

/* ---------- youtube ---------- */
.channels { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.channel { display: grid; gap: 8px; justify-items: start; }
.logo {
  width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--ink);
  background: hsl(var(--h) 90% 82%); display: grid; place-items: center; font-size: 1.9rem; font-weight: 800;
}

/* ---------- vaccines ---------- */
.upcoming { background: #fff8e1; margin-bottom: 8px; }
.upcoming ul { margin: 0; padding-left: 20px; }
.vac { display: flex; gap: 16px; align-items: center; }
.vac-date { flex: none; width: 76px; height: 76px; border-radius: 20px; border: 3px solid var(--ink); background: var(--mint); display: grid; place-content: center; text-align: center; line-height: 1.1; }
.vac-date b { font-size: 1.25rem; }
.vac-body { flex: 1; min-width: 0; }
.vac-body h3 { margin: 0; }


/* ---------- tasks, rewards ---------- */
.quest { text-align: center; display: grid; gap: 8px; justify-items: center; background: linear-gradient(135deg, #fff 0%, #fff8e1 100%); margin: 6px 0 18px; }
.quest-total { font-size: 1.15rem; }
.dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dot { font-size: 2rem; filter: grayscale(1) opacity(.3); transition: filter .3s, transform .3s; }
.dot.on { filter: none; transform: scale(1.15) rotate(-8deg); }
.btn.big { min-height: 56px; font-size: 1.3rem; padding: 6px 28px; animation: bob 1.6s ease-in-out infinite; }

.task { display: flex; align-items: center; gap: 10px; padding: 8px 12px; transition: background .2s; }
.task.done { background: #e6fbef; }
.task-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer;
  font: inherit; color: inherit; background: none; border: 0; min-height: 56px; padding: 4px;
}
.check { font-size: 1.7rem; }
.task-emoji { font-size: 2rem; }
.task-title { font-weight: 700; font-size: 1.15rem; flex: 1; }
.task.done .task-title { text-decoration: line-through; opacity: .65; }
.task-stars { white-space: nowrap; }

.chests { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.chest { text-align: center; display: grid; gap: 6px; justify-items: center; padding: 12px; }
.chest-art { width: 110px; transition: transform .2s; }
.chest:hover .chest-art { transform: translateY(-4px) rotate(-3deg); }
.chest-art .art { width: 100%; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; border-bottom: 2px dashed var(--pink); padding-bottom: 8px; }
.history li b { flex: 1; min-width: 150px; }

.scene { position: relative; overflow: hidden; padding: 28px 20px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.scene-art .art { width: 200px; }
.shake { animation: shake-chest .5s infinite; }
@keyframes shake-chest { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
.pop { animation: pop-in .6s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes pop-in { from { transform: scale(.4); } }
.burst { position: absolute; inset: 0; pointer-events: none; }
.burst span { position: absolute; bottom: -10px; font-size: 1.8rem; animation: rise 1.8s ease-out forwards; }
@keyframes rise { to { transform: translateY(-330px) rotate(30deg); opacity: 0; } }

/* ---------- dialogs ---------- */
dialog {
  border: 3px solid var(--ink); border-radius: 26px; box-shadow: var(--shadow);
  padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  background: #fff; color: var(--ink); font: inherit; overflow-x: hidden;
}
dialog::backdrop { background: rgba(90, 62, 92, .45); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .22s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.dlg-form { padding: 20px; display: grid; gap: 12px; }
.dlg-form h2 { font-size: 1.5rem; }
.dlg-form section, .dlg-form form { display: grid; gap: 10px; }
.field { display: grid; gap: 2px; }
.field span { font-weight: 700; font-size: .95rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fffdf8; width: 100%;
  border: 3px solid var(--ink); border-radius: 14px; padding: 6px 12px; min-height: 44px;
}
textarea { resize: vertical; }
input[type=file] { padding: 8px; background: #fff; }
.form-err { color: #c2255c; font-weight: 700; min-height: 0; }
.dlg-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.ask-msg { font-size: 1.15rem; font-weight: 600; }

.lightbox { width: min(960px, 100vw - 16px); background: transparent; border: 0; box-shadow: none; overflow: visible; }
.lb-body { position: relative; display: grid; justify-items: center; gap: 10px; }
.lb-body img { max-width: 100%; max-height: calc(100vh - 130px); border: 4px solid var(--ink); border-radius: 22px; background: #fff; box-shadow: var(--shadow); object-fit: contain; }
.lb-x { position: absolute; top: -6px; right: -6px; z-index: 2; background: #fff; width: 44px; padding: 0; }
.lb-nav { position: absolute; top: 45%; z-index: 2; width: 48px; padding: 0; background: #fff; }
.lb-nav.prev { left: 6px; }
.lb-nav.next { right: 6px; }
.lb-bar { display: flex; gap: 14px; align-items: center; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 2px 8px 2px 18px; font-weight: 700; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); z-index: 100;
  background: var(--lemon); border: 3px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow);
  padding: 6px 22px; font-weight: 700; max-width: calc(100vw - 24px); text-align: center; transition: transform .3s cubic-bezier(.3, 1.5, .5, 1), opacity .3s;
  opacity: 0; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- login ---------- */
.gate { min-height: 90vh; display: grid; place-items: center; }
.gate-card { width: min(430px, 100%); display: grid; gap: 8px; text-align: center; padding: 24px; }
.gate-card form { display: grid; gap: 10px; text-align: left; margin-top: 8px; }
.gate-art { width: 130px; margin: -70px auto 0; animation: bob 3s ease-in-out infinite; }
.gate-card h1 { font-size: 2rem; }
.link { cursor: pointer; font-weight: 700; text-decoration: underline; margin-top: 8px; }
.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  h2 { font-size: 1.4rem; }
  .brand h1 { font-size: 1.5rem; }
  .brand-art { width: 52px; height: 52px; }
  .hero { justify-content: center; text-align: center; }
  .hero .row, .hero .pill-row { justify-content: center; }
  .info div { grid-template-columns: 1fr; gap: 0; }
  .ach, .vac { flex-direction: column; align-items: flex-start; }
  .medal { width: 64px; }
  .deco { opacity: .3; }

  #app { padding-bottom: 170px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 20;
    display: flex; flex-wrap: nowrap; gap: 2px; overflow-x: auto; scrollbar-width: none;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: #fff; border-top: 3px solid var(--ink);
  }
  .tab {
    flex: 0 0 68px; flex-direction: column; justify-content: center; gap: 0; border: 0; box-shadow: none; border-radius: 16px;
    padding: 2px 0; min-height: 54px; font-size: .72rem; line-height: 1.1; text-align: center;
  }
  .tab span { font-size: 1.45rem; }
  .tab.on { transform: none; box-shadow: none; }
  .lg { display: none; }
  .sec-actions .btn.primary {
    position: fixed; right: 14px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 15;
    min-height: 52px; font-size: 1.05rem; box-shadow: 0 5px 0 var(--ink), 0 10px 18px rgba(90, 62, 92, .3);
  }
  #toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 26px 26px 0 0; max-height: 92vh; border-bottom: 0; }
  dialog.lightbox { margin: auto; }
  .dlg-actions { position: sticky; bottom: 0; background: #fff; padding: 10px 0 calc(8px + env(safe-area-inset-bottom)); border-top: 2px dashed var(--pink); }
  .btn.small, .chip { min-height: 44px; }
}

@media (min-width: 641px) { .sm { display: none; } }

@media (hover: none) {
  .btn:hover { transform: none; box-shadow: 0 4px 0 var(--ink); }
  .tab:hover, .slot:hover, .thumb:hover, .album:hover, a.tile:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- bản online: Mochi đăng nhập thì ẩn các nút chỉ dành cho bố mẹ ---------- */
.role-child [data-act^="add-"],
.role-child .btn[data-act^="edit-"],
.role-child [data-act="avatar"],
.role-child [data-act="lb-del"],
.role-child [data-act="rules"],
.role-child [data-act="toggle-prizes"],
.role-child [data-act="dlg-delete"] { display: none !important; }
