/* ================= Mí App — giao diện ================= */
:root {
  --ink: #5A4743;
  --ink-soft: #8A7671;
  --card: #FFFFFF;
  --line: #F0E4DC;
  --pink: #FF8FB1;
  --pink-deep: #F0628F;
  --yellow: #FFD84D;
  --orange: #FFB347;
  --mint: #8FD3B6;
  --mint-deep: #4FAE86;
  --blue: #7FB7FF;
  --blue-deep: #4E8FE0;
  --lilac: #B9A6FF;
  --sky-a: #FFF4D6;
  --sky-b: #FFE3EC;
  --font: 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(180deg, var(--sky-a), var(--sky-b));
  overflow: hidden; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  transition: background .8s;
}
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--ink); }

body[data-session="sang"] { --sky-a: #FFF1C9; --sky-b: #FFE0EA; }
body[data-session="trua"] { --sky-a: #CDEBFF; --sky-b: #FFF6E3; }
body[data-session="toi"]  { --sky-a: #3C3F7E; --sky-b: #8C78C2; }
body[data-session="dem"]  { --sky-a: #1E2250; --sky-b: #3E3A78; }
body[data-session="tudo"] { --sky-a: #DDF7EA; --sky-b: #FFF3D9; }
body[data-session="ngay"] { --sky-a: #E3F6FF; --sky-b: #FFE6F0; }

.app { position: relative; height: 100%; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; }

/* ---------- Bầu trời ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.sky .sun { position: absolute; top: calc(70px + var(--safe-t)); right: 8%; width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #FFF3A6, #FFD84D); box-shadow: 0 0 0 14px rgba(255,216,77,.22), 0 0 0 30px rgba(255,216,77,.12); }
.sky .moon { display: none; position: absolute; top: calc(72px + var(--safe-t)); right: 10%; width: 62px; height: 62px; border-radius: 50%;
  box-shadow: -14px 6px 0 0 #FFF1B8; transform: rotate(-20deg); }
.sky .stars { display: none; position: absolute; inset: 0; background-image:
  radial-gradient(2px 2px at 12% 18%, #fff, transparent), radial-gradient(2px 2px at 30% 8%, #fff, transparent),
  radial-gradient(1.5px 1.5px at 52% 22%, #fff, transparent), radial-gradient(2px 2px at 72% 30%, #fff, transparent),
  radial-gradient(1.5px 1.5px at 86% 12%, #fff, transparent), radial-gradient(2px 2px at 20% 38%, #fff, transparent),
  radial-gradient(1.5px 1.5px at 62% 6%, #fff, transparent), radial-gradient(1.5px 1.5px at 40% 34%, #fff, transparent);
  animation: twinkle 3s ease-in-out infinite alternate; }
.sky .cloud { position: absolute; width: 120px; height: 38px; background: rgba(255,255,255,.85); border-radius: 40px; animation: drift 38s linear infinite; }
.sky .cloud::before, .sky .cloud::after { content: ''; position: absolute; background: inherit; border-radius: 50%; }
.sky .cloud::before { width: 54px; height: 54px; left: 18px; top: -26px; }
.sky .cloud::after { width: 40px; height: 40px; left: 60px; top: -16px; }
.sky .c1 { top: calc(120px + var(--safe-t)); left: -140px; }
.sky .c2 { top: calc(220px + var(--safe-t)); left: -140px; transform: scale(.7); animation-duration: 52s; animation-delay: -20s; opacity: .8; }
body[data-session="trua"] .sky .sun { top: calc(56px + var(--safe-t)); right: 40%; }
body[data-session="toi"] .sky .sun, body[data-session="dem"] .sky .sun { display: none; }
body[data-session="toi"] .sky .moon, body[data-session="dem"] .sky .moon,
body[data-session="toi"] .sky .stars, body[data-session="dem"] .sky .stars { display: block; }
body[data-session="toi"] .sky .cloud, body[data-session="dem"] .sky .cloud { opacity: .18; }
@keyframes drift { from { transform: translateX(0) } to { transform: translateX(calc(100vw + 300px)) } }
@keyframes twinkle { from { opacity: .5 } to { opacity: 1 } }

/* ---------- Thanh trên ---------- */
.top { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 16px 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 20px;
  background: rgba(255,255,255,.78); font-weight: 700; font-size: 17px; box-shadow: 0 2px 8px rgba(90,71,67,.08); }
.pill.star { margin-left: auto; font-size: 18px; }
/* Nút kể chuyện buổi tối (cạnh nút sticker) */
.story-btn { margin-left: auto; position: relative; width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.85); font-size: 24px; box-shadow: 0 2px 8px rgba(90,71,67,.12); animation: storyGlow 2.4s ease-in-out infinite; }
.story-btn::before { content: ''; position: absolute; inset: -6px; }  /* vùng chạm 60px */
.story-btn[hidden] { display: none; }
.story-btn:not([hidden]) + .pill.star { margin-left: 0; }
@keyframes storyGlow { 50% { box-shadow: 0 0 0 6px rgba(255,214,102,.35), 0 2px 8px rgba(90,71,67,.12); } }
.pill.star b { min-width: 1.2em; text-align: left; }
.pill.star.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.25) } }
.parent-btn { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.35); font-size: 18px; opacity: .55; position: relative; }
.parent-btn .ring { position: absolute; inset: -3px; border-radius: 50%; border: 3px solid var(--pink); clip-path: inset(0 100% 0 0); }
.parent-btn.holding .ring { animation: hold 1.5s linear forwards; }
@keyframes hold { to { clip-path: inset(0 0 0 0); } }

/* ---------- Sân khấu: Mây + bong bóng lời ---------- */
.stage { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 4px 16px 0; }
.bubble { position: relative; max-width: 92%; background: #fff; border-radius: 24px; padding: 12px 18px; font-size: 19px; line-height: 1.35;
  font-weight: 600; text-align: center; box-shadow: 0 6px 18px rgba(90,71,67,.12); margin-bottom: 4px; min-height: 52px;
  display: flex; align-items: center; justify-content: center; transition: opacity .2s; }
.bubble::after { content: ''; position: absolute; bottom: -12px; left: 50%; margin-left: -12px; border: 12px solid transparent; border-top-color: #fff; border-bottom: 0; }
.bubble.pop { animation: pop .35s cubic-bezier(.3,1.6,.5,1); }
.bubble.empty { opacity: 0; }
@keyframes pop { from { transform: scale(.85); opacity: .3 } }
.mascot { width: min(78vw, 330px); flex: 0 1 auto; min-height: 150px; height: min(40vh, 350px); cursor: pointer; }
.mascot svg { filter: drop-shadow(0 6px 12px rgba(90,71,67,.12)); }

/* ---------- Bảng việc phía dưới ---------- */
.panel { position: relative; z-index: 2; background: var(--card); border-radius: 30px 30px 0 0; padding: 14px 16px calc(16px + var(--safe-b));
  box-shadow: 0 -8px 30px rgba(90,71,67,.12); display: flex; flex-direction: column; gap: 12px; }
.track { display: flex; gap: 14px; overflow-x: auto; padding: 8px 8px 4px; scrollbar-width: none; align-items: center; min-height: 52px; }
.track::-webkit-scrollbar { display: none; }
.dot { flex: 0 0 auto; position: relative; width: 42px; height: 42px; border-radius: 50%; background: #F6EEE8; display: grid; place-items: center; font-size: 22px; filter: grayscale(.6); opacity: .65; }
button.dot { border: 0; padding: 0; cursor: pointer; font: inherit; -webkit-tap-highlight-color: transparent; }
button.dot::before { content: ''; position: absolute; inset: -7px; }  /* vùng chạm 56px */
button.dot:active { transform: scale(.92); }
.dot img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.dot.done { background: #DDF5EA; filter: none; opacity: 1; }
.dot.done::after { content: '✓'; position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--mint-deep); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; border: 2px solid #fff; }
.dot.now { width: 52px; height: 52px; font-size: 28px; filter: none; opacity: 1; background: #FFE6EF; box-shadow: 0 0 0 3px var(--pink); animation: nowPulse 1.6s ease-in-out infinite; }
@keyframes nowPulse { 50% { box-shadow: 0 0 0 6px rgba(255,143,177,.45); } }
.track .sep { flex: 0 0 10px; height: 3px; border-radius: 2px; background: #F0E4DC; }

.task-card { display: flex; align-items: center; gap: 14px; }
.task-icon { flex: 0 0 auto; width: 84px; height: 84px; border-radius: 26px; background: #FFF1E4; display: grid; place-items: center; font-size: 50px; overflow: hidden; }
.task-icon img { width: 100%; height: 100%; object-fit: cover; }
.task-text small { display: block; font-size: 14px; color: var(--ink-soft); font-weight: 700; letter-spacing: .02em; }
.task-text h2 { margin: 0; font-size: 26px; line-height: 1.15; }

.actions { display: flex; align-items: center; gap: 12px; }
.round { flex: 0 0 auto; width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; font-size: 34px; transition: transform .1s; }
.round.small { width: 56px; height: 56px; font-size: 24px; background: #FFF6EF; border: 2px solid var(--line); }
.round:active, .btn-done:active, .btn-soft:active, .reward-card:active { transform: translateY(4px); box-shadow: none !important; }
.mic { background: linear-gradient(180deg, #9CCBFF, var(--blue)); box-shadow: 0 6px 0 var(--blue-deep); color: #fff; position: relative; }
.mic svg { width: 34px; height: 34px; }
.mic::before { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 4px solid var(--pink); opacity: 0; transform: scale(calc(1 + var(--lvl, 0) * .18)); transition: transform .08s; }
.mic.listening { background: linear-gradient(180deg, #FFA9C4, var(--pink)); box-shadow: 0 6px 0 var(--pink-deep); }
.mic.listening::before { opacity: 1; }
.mic.thinking { background: linear-gradient(180deg, #D4C8FF, var(--lilac)); box-shadow: 0 6px 0 #8F7AE6; animation: spin 1.2s linear infinite; }
@keyframes spin { 50% { transform: scale(.92) } }
.btn-done { flex: 1; min-width: 0; height: 76px; border-radius: 38px; font-size: clamp(18px, 5.4vw, 24px); white-space: nowrap; font-weight: 800; color: #6B3B0F;
  background: linear-gradient(180deg, #FFE580, var(--yellow) 45%, var(--orange)); box-shadow: 0 6px 0 #E0922E, 0 10px 18px rgba(224,146,46,.3);
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: transform .1s; }
.btn-done .star-ic { font-size: 1.2em; }
.btn-done.wiggle, .round.wiggle { animation: wiggle .6s ease-in-out 2; }
@keyframes wiggle { 20% { transform: rotate(-4deg) scale(1.04) } 40% { transform: rotate(4deg) scale(1.04) } 60% { transform: rotate(-2deg) } 80% { transform: rotate(2deg) } }
.btn-soft { height: 54px; border-radius: 27px; background: #F2EDFF; color: #5B48B8; font-weight: 800; font-size: 18px; box-shadow: 0 4px 0 #D6CCFF; display: flex; align-items: center; justify-content: center; gap: 8px; transition: transform .1s; }
.btn-soft.mint { background: #E2F7EE; color: #2F7D5C; box-shadow: 0 4px 0 #BFE8D5; }
.btn-soft.pink { background: #FFE6EF; color: #B23A66; box-shadow: 0 4px 0 #FFC6D9; }
.hidden { display: none !important; }

.hold-btn { position: relative; overflow: hidden; }
.hold-btn .fill { position: absolute; inset: 0; background: rgba(79,174,134,.25); transform: scaleX(0); transform-origin: left; }
.hold-btn.holding .fill { transition: transform 1s linear; transform: scaleX(1); }
.hold-btn span { position: relative; }

.empty-state { text-align: center; padding: 6px 0 2px; }
.empty-state .big { font-size: 46px; line-height: 1; }
.empty-state h2 { margin: 6px 0 2px; font-size: 24px; }
.empty-state p { margin: 0; color: var(--ink-soft); font-size: 16px; }

/* ---------- Lớp phủ ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; justify-content: flex-end; background: rgba(60,40,40,.35);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fadeIn .25s; }
.overlay.center { justify-content: center; align-items: center; padding: 20px; }
@keyframes fadeIn { from { opacity: 0 } }
.sheet { background: #fff; border-radius: 30px 30px 0 0; padding: 20px 18px calc(20px + var(--safe-b)); max-height: 92vh; overflow-y: auto; animation: up .35s cubic-bezier(.2,.9,.3,1); width: 100%; max-width: 560px; margin: 0 auto; }
@keyframes up { from { transform: translateY(40px); opacity: .4 } }
.sheet h2 { margin: 0 0 4px; font-size: 26px; text-align: center; }
.sheet .sub { margin: 0 0 14px; text-align: center; color: var(--ink-soft); font-size: 16px; }
.x-btn { position: absolute; top: calc(12px + var(--safe-t)); right: 14px; width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.9); font-size: 22px; font-weight: 800; z-index: 3; box-shadow: 0 2px 8px rgba(0,0,0,.1); }

/* Màn hình chào */
.splash { background: linear-gradient(180deg, var(--sky-a), var(--sky-b)); justify-content: center; align-items: center; text-align: center; gap: 6px; -webkit-backdrop-filter: none; backdrop-filter: none; z-index: 60; }
.splash .mascot { height: min(46vh, 380px); }
.splash h1 { margin: 0; font-size: 34px; color: var(--ink); }
body[data-session="toi"] .splash h1, body[data-session="dem"] .splash h1 { color: #fff; }
.splash .btn-done { flex: 0 0 auto; width: min(80vw, 320px); animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.05) } }

/* Phần thưởng */
.rewards { display: grid; gap: 12px; }
.reward-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 24px; background: #FFF6EF; border: 3px solid #FFE3CC; box-shadow: 0 5px 0 #FFE3CC; text-align: left; font-size: 21px; font-weight: 800; transition: transform .1s; animation: up .4s backwards; }
.reward-card:nth-child(2) { animation-delay: .08s; background: #F1FAF6; border-color: #CDEFE0; box-shadow: 0 5px 0 #CDEFE0; }
.reward-card:nth-child(3) { animation-delay: .16s; background: #F4F1FF; border-color: #E0D8FF; box-shadow: 0 5px 0 #E0D8FF; }
.reward-card .e { font-size: 46px; line-height: 1; width: 56px; text-align: center; }
.reward-won { text-align: center; padding: 8px 0; }
.reward-won .e { font-size: 90px; line-height: 1.1; animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
.reward-won h3 { margin: 6px 0 14px; font-size: 26px; }

/* Truyện */
.story { background: linear-gradient(180deg, #FFF6E8, #FFE7F0); justify-content: flex-start; -webkit-backdrop-filter: none; backdrop-filter: none; z-index: 70; }
body[data-session="toi"] .story, body[data-session="dem"] .story { background: linear-gradient(180deg, #2E3170, #5B4E98); color: #fff; }
.story-inner { flex: 1; display: flex; flex-direction: column; align-items: center; padding: calc(70px + var(--safe-t)) 22px calc(18px + var(--safe-b)); gap: 14px; max-width: 560px; margin: 0 auto; width: 100%; }
.story-title { font-size: 18px; font-weight: 800; opacity: .75; margin: 0; }
.story-scene { width: 170px; height: 170px; border-radius: 50%; background: rgba(255,255,255,.75); display: grid; place-items: center; font-size: 62px; line-height: 1; letter-spacing: -6px; white-space: nowrap; box-shadow: 0 8px 24px rgba(90,71,67,.12); animation: pop .4s; }
.story-scene.art { width: min(100%, 420px, calc(40vh * 4 / 3)); height: auto; aspect-ratio: 4 / 3; border-radius: 28px; overflow: hidden; background: rgba(255,255,255,.4); }
.story-scene.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.story-text { font-size: 22px; line-height: 1.5; text-align: center; font-weight: 600; flex: 1; display: flex; align-items: center; }
.story-bottom { display: flex; align-items: flex-end; gap: 12px; width: 100%; }
.story-bottom .mascot { width: 130px; height: 140px; min-height: 0; flex: 0 0 auto; }
.story-ctrl { flex: 1; display: flex; gap: 10px; justify-content: flex-end; align-items: center; padding-bottom: 14px; }
.story-ctrl .round { width: 60px; height: 60px; font-size: 26px; background: #fff; box-shadow: 0 4px 0 #EADBD2; color: var(--ink); }
.pages { display: flex; gap: 6px; justify-content: center; }
.pages i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .25; }
.pages i.on { opacity: .9; width: 20px; border-radius: 4px; }
.story-list { display: grid; gap: 12px; }

/* Album sticker */
.week { background: #FFF6EF; border-radius: 20px; padding: 12px 14px; margin-bottom: 14px; }
.week .row { display: flex; justify-content: space-between; font-weight: 800; font-size: 17px; }
.bar { height: 18px; border-radius: 9px; background: #F2E4DA; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; border-radius: 9px; background: linear-gradient(90deg, var(--yellow), var(--orange)); transition: width .6s; }
.stickers { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.stickers span { aspect-ratio: 1; display: grid; place-items: center; font-size: 30px; background: #FBF6F2; border-radius: 16px; }
.stickers span.today { background: #FFF1C9; animation: pop .4s backwards; }

/* Đếm giờ */
.timer { background: linear-gradient(180deg, #E6F6FF, #FFF0F6); justify-content: center; align-items: center; -webkit-backdrop-filter: none; backdrop-filter: none; z-index: 65; gap: 14px; text-align: center; }
.timer-ring { position: relative; width: min(84vw, 340px); aspect-ratio: 1; }
.timer-ring > svg.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer-ring .mascot { position: absolute; inset: 12%; width: auto; height: auto; min-height: 0; }
.timer-time { font-size: 48px; font-weight: 800; line-height: 1; }
.timer h2 { margin: 0; font-size: 24px; }

/* Cổng ba mẹ */
.gate { background: #fff; border-radius: 28px; padding: 22px; width: min(92vw, 380px); text-align: center; animation: pop .3s; }
.gate h3 { margin: 0 0 6px; font-size: 22px; }
.gate p { margin: 0 0 14px; color: var(--ink-soft); }
.gate .q { font-size: 34px; font-weight: 800; margin-bottom: 14px; }
.gate .opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.gate .opts button { height: 58px; border-radius: 16px; background: #F6EEE8; font-size: 24px; font-weight: 800; }

/* Thông báo nhỏ */
.toast { position: fixed; left: 50%; top: calc(16px + var(--safe-t)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 20px; font-weight: 700; z-index: 200; animation: fadeIn .2s; max-width: 90vw; text-align: center; }

/* Pháo giấy & sticker bay */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 120; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(var(--r)); } }
.fly-sticker { position: fixed; left: 50%; top: 42%; z-index: 130; font-size: 20px; transform: translate(-50%, -50%) scale(.2); opacity: 0; pointer-events: none;
  transition: transform .5s cubic-bezier(.3,1.6,.5,1), opacity .3s, left .7s cubic-bezier(.5,0,.6,1), top .7s cubic-bezier(.5,0,.6,1); }
.fly-sticker.show { opacity: 1; transform: translate(-50%, -50%) scale(5); }
.fly-sticker.go { transform: translate(-50%, -50%) scale(1); }

@media (min-height: 760px) { .bubble { font-size: 21px; } }
@media (max-height: 640px) { .task-icon { width: 64px; height: 64px; font-size: 38px; border-radius: 20px; } .task-text h2 { font-size: 22px; } .round, .btn-done { height: 64px; } .round { width: 64px; } .mascot { height: 34vh; } }
