:root {
  --bg1: #e9f3ff;
  --bg2: #fff4e3;
  --ink: #2d2350;
  --ink-soft: #6b628c;
  --card: #ffffff;
  --line: #e7e2f7;
  --primary: #7c5cff;
  --primary-dark: #5b3fe0;
  --sun: #ffc93c;
  --good: #2ec27e;
  --good-bg: #e2f9ee;
  --bad: #ff5d73;
  --bad-bg: #ffe6ea;
  --think: #fff6d6;
  --think-line: #ffd965;
  --a: #ff7aa2; --b: #4fb4ff; --c: #ffb340; --d: #45cf8f;
  --shadow: 0 6px 0 rgba(45, 35, 80, .12), 0 12px 28px rgba(45, 35, 80, .10);
  --radius: 26px;
  font-family: 'Baloo 2', 'Comic Sans MS', 'Trebuchet MS', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: linear-gradient(170deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  font-size: 20px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; }

/* floating clouds */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.sky span { position: absolute; font-size: 56px; opacity: .55; animation: float 14s ease-in-out infinite; }
.sky span:nth-child(1) { top: 6%; left: 4%; }
.sky span:nth-child(2) { top: 14%; right: 10%; font-size: 30px; animation-delay: -3s; }
.sky span:nth-child(3) { top: 58%; right: 3%; font-size: 70px; animation-delay: -6s; }
.sky span:nth-child(4) { bottom: 12%; left: 8%; font-size: 32px; animation-delay: -2s; }
.sky span:nth-child(5) { bottom: 4%; left: 46%; font-size: 44px; animation-delay: -9s; }
@keyframes float { 50% { transform: translate(18px, -14px); } }

.app {
  position: relative; z-index: 1;
  max-width: 760px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 800; }
h1 { font-size: clamp(30px, 6vw, 44px); }
h2 { font-size: clamp(24px, 4.6vw, 32px); }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.stack { display: grid; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 60px; padding: 10px 26px;
  border-radius: 999px;
  background: var(--primary); color: #fff;
  font-size: 22px; font-weight: 800;
  box-shadow: 0 6px 0 var(--primary-dark);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--primary-dark); }
.btn:disabled { filter: grayscale(.8) opacity(.6); cursor: default; }
.btn.big { min-height: 72px; font-size: 26px; padding: 12px 34px; }
.btn.wide { width: 100%; }
.btn.sun { background: var(--sun); color: var(--ink); box-shadow: 0 6px 0 #e0a400; }
.btn.sun:active { box-shadow: 0 1px 0 #e0a400; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 6px 0 var(--line); }
.btn.ghost:active { box-shadow: 0 1px 0 var(--line); }
.btn.small { min-height: 46px; font-size: 18px; padding: 6px 18px; }
.icon-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: #fff; box-shadow: 0 4px 0 var(--line); font-size: 24px;
  display: grid; place-items: center;
}

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.me { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; }
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 32px;
  background: #fff; box-shadow: 0 4px 0 var(--line);
  flex: none;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border-radius: 999px; padding: 6px 14px;
  font-weight: 800; box-shadow: 0 4px 0 var(--line); font-size: 20px;
}

/* login */
.hero { text-align: center; padding: 20px 0 8px; }
.hero .logo { font-size: 84px; display: block; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-4deg); } }
.field { display: grid; gap: 6px; font-weight: 700; }
.field input {
  min-height: 60px; border-radius: 18px; border: 3px solid var(--line);
  padding: 8px 18px; font-size: 24px; outline: none;
}
.field input:focus { border-color: var(--primary); }
.avatar-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px; }
.avatar-pick button {
  font-size: 36px; height: 62px; border-radius: 18px; background: #f5f2ff;
  border: 3px solid transparent;
}
.avatar-pick button[aria-pressed="true"] { border-color: var(--primary); background: #fff; transform: scale(1.08); }

.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 6px 0; }
.pin-dots span { width: 24px; height: 24px; border-radius: 50%; background: var(--line); transition: background .15s, transform .15s; }
.pin-dots span.on { background: var(--primary); transform: scale(1.15); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 330px; margin: 0 auto; }
.pinpad button {
  height: 70px; border-radius: 22px; background: #fff; font-size: 32px; font-weight: 800;
  box-shadow: 0 5px 0 var(--line);
}
.pinpad button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.error { color: var(--bad); font-weight: 800; text-align: center; min-height: 1.4em; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

/* home */
.today { padding: 0; overflow: hidden; }
.today .pic { height: min(62vw, 320px); width: 100%; overflow: hidden; background: #f3efff; display: flex; align-items: center; justify-content: center; }
.today .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.today .pic .emoji { font-size: 120px; }
.today .body { padding: 20px 22px 24px; display: grid; gap: 12px; }
.tag {
  display: inline-block; align-self: start; justify-self: start;
  background: #f0ebff; color: var(--primary-dark); font-weight: 800;
  padding: 2px 14px; border-radius: 999px; font-size: 17px; text-transform: capitalize;
}
.late {
  display: inline-block; background: #fff1d6; color: #a86a00; font-weight: 800;
  padding: 0 10px; border-radius: 999px; font-size: 15px; white-space: nowrap;
}
.result-badge { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; }
.stars { letter-spacing: 2px; }

.list { display: grid; gap: 12px; }
.list-item {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border-radius: 20px; padding: 12px 16px;
  box-shadow: 0 4px 0 var(--line); text-align: left; width: 100%;
}
.list-item .em { font-size: 34px; flex: none; }
.list-item .t { font-weight: 800; line-height: 1.2; }
.list-item .s { font-size: 16px; color: var(--ink-soft); }

/* reading */
.progress { display: flex; gap: 8px; justify-content: center; margin: 4px 0 14px; }
.progress span { height: 12px; flex: 1; max-width: 60px; border-radius: 99px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); }
.progress span.on { background: var(--primary); box-shadow: none; }
.progress span.ok { background: var(--good); box-shadow: none; }
.progress span.no { background: var(--bad); box-shadow: none; }
.read-pic { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #fff; }
.read-pic img { width: 100%; display: block; max-height: 360px; object-fit: cover; }
.story { font-size: clamp(22px, 3.6vw, 27px); line-height: 1.6; }
.story p { margin: 0; }
.pop { animation: pop .35s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }

.think {
  background: var(--think); border: 3px dashed var(--think-line);
  border-radius: 22px; padding: 16px 18px; display: grid; gap: 10px;
}
.think .q { font-weight: 800; font-size: 22px; display: flex; gap: 10px; }
.think .q::before { content: '🤔'; font-size: 30px; line-height: 1; }
.think .a { background: #fff; border-radius: 16px; padding: 10px 14px; font-size: 20px; }

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

/* dialog */
.overlay {
  position: fixed; inset: 0; z-index: 10; background: rgba(45, 35, 80, .45);
  display: grid; place-items: center; padding: 16px;
}
.dialog { max-width: 440px; width: 100%; text-align: center; }
.dialog .big-emoji { font-size: 70px; }

/* quiz */
.question { font-size: clamp(24px, 4.4vw, 32px); font-weight: 800; line-height: 1.25; }
.options { display: grid; gap: 14px; }
.option {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: #fff; border-radius: 22px; padding: 12px 16px; min-height: 72px;
  font-size: 22px; font-weight: 700; box-shadow: 0 5px 0 var(--line);
  border: 3px solid transparent; transition: transform .08s;
}
.option:not(:disabled):hover { transform: translateY(-2px); }
.option:not(:disabled):active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.option:disabled { cursor: default; }
.option .letter {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 24px;
}
.option:nth-child(1) .letter { background: var(--a); }
.option:nth-child(2) .letter { background: var(--b); }
.option:nth-child(3) .letter { background: var(--c); }
.option:nth-child(4) .letter { background: var(--d); }
.option.correct { border-color: var(--good); background: var(--good-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.faded { opacity: .5; }
.tf { grid-template-columns: 1fr 1fr; }
.tf .option { flex-direction: column; justify-content: center; text-align: center; min-height: 130px; font-size: 26px; }
.tf .option .letter { width: auto; height: auto; background: none !important; font-size: 54px; }

.feedback { border-radius: 22px; padding: 16px 18px; font-size: 21px; display: grid; gap: 4px; }
.feedback.ok { background: var(--good-bg); border: 3px solid var(--good); }
.feedback.no { background: var(--bad-bg); border: 3px solid var(--bad); }
.feedback b { font-size: 26px; }

/* results */
.score-ring {
  width: 190px; height: 190px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; text-align: center;
  background: conic-gradient(var(--good) calc(var(--p) * 1%), #f0ebff 0);
}
.score-ring > div { width: 150px; height: 150px; border-radius: 50%; background: #fff; display: grid; place-content: center; }
.score-ring b { font-size: 52px; line-height: 1; }
.points-pop { font-size: 34px; font-weight: 800; color: var(--primary-dark); animation: pop .5s .2s both; }

/* leaderboard */
.tabs { display: flex; background: #fff; border-radius: 999px; padding: 5px; box-shadow: 0 4px 0 var(--line); }
.tabs button { flex: 1; min-height: 48px; border-radius: 999px; font-weight: 800; font-size: 19px; }
.tabs button[aria-selected="true"] { background: var(--primary); color: #fff; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin-top: 10px; }
.podium .p { flex: 1; max-width: 170px; text-align: center; }
.podium .p .avatar { margin: 0 auto 4px; width: 66px; height: 66px; font-size: 40px; }
.podium .p .name { font-weight: 800; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium .block {
  border-radius: 18px 18px 6px 6px; color: #fff; font-weight: 800; font-size: 30px;
  display: grid; place-items: center; margin-top: 6px;
}
.podium .p1 .block { height: 130px; background: linear-gradient(#ffd54a, #f4ae00); }
.podium .p2 .block { height: 96px; background: linear-gradient(#cfd8e8, #9ba9c2); }
.podium .p3 .block { height: 74px; background: linear-gradient(#ffb98a, #e0844a); }
.lb-row { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 18px; padding: 10px 14px; box-shadow: 0 4px 0 var(--line); }
.lb-row.me { outline: 3px solid var(--primary); }
.lb-row .rank { width: 34px; text-align: center; font-weight: 800; font-size: 22px; color: var(--ink-soft); }
.lb-row .avatar { width: 46px; height: 46px; font-size: 26px; box-shadow: none; background: #f5f2ff; }
.lb-row .name { font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pts { font-weight: 800; font-size: 22px; }

/* confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
#confetti i {
  position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.loading { text-align: center; padding: 80px 0; font-size: 60px; animation: bob 1.2s infinite; }

@media (max-width: 480px) {
  body { font-size: 18px; }
  .card { padding: 18px; }
  .btn.big { font-size: 22px; min-height: 64px; padding: 10px 22px; }
  .option { font-size: 20px; min-height: 64px; }
  .tf .option { min-height: 110px; }
  .nav .btn { padding: 10px 18px; }
}

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