:root {
  --bg1: #e9f3ff;
  --bg2: #fff4e6;
  --ink: #2b2d42;
  --muted: #6b7086;
  --card: #ffffff;
  --line: #e7e8f2;
  --brand: #7b5cff;
  --brand-2: #5a3fe0;
  --ok: #22b573;
  --ok-bg: #e3f9ee;
  --bad: #ef476f;
  --bad-bg: #ffe8ee;
  --wait: #ffb703;
  --star: #ffc93c;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(43, 45, 66, .08), 0 14px 30px rgba(43, 45, 66, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Baloo 2', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg1), var(--bg2)) fixed;
  font-size: 18px;
  line-height: 1.35;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: .2em 0; line-height: 1.15; }
h1 { font-size: clamp(26px, 4vw, 40px); font-weight: 800; }
h2 { font-size: 28px; font-weight: 800; }
h3 { font-size: 21px; font-weight: 700; }
.sub { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- background sky ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.cloud { position: absolute; width: 160px; height: 50px; background: #fff; border-radius: 50px; opacity: .8; animation: drift 60s linear infinite; }
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 70px; height: 70px; top: -34px; left: 26px; }
.cloud::after { width: 54px; height: 54px; top: -22px; left: 82px; }
.c1 { top: 12%; left: -200px; }
.c2 { top: 45%; left: -200px; animation-duration: 85s; animation-delay: -30s; transform: scale(.7); }
.c3 { top: 75%; left: -200px; animation-duration: 70s; animation-delay: -55s; transform: scale(.85); }
@keyframes drift { to { left: 110%; } }
.twinkle { position: absolute; color: var(--star); font-size: 22px; animation: twinkle 3s ease-in-out infinite; }
.t1 { top: 18%; left: 8%; } .t2 { top: 30%; right: 10%; animation-delay: -1s; }
.t3 { bottom: 20%; left: 14%; animation-delay: -2s; } .t4 { bottom: 12%; right: 18%; animation-delay: -.5s; }
@keyframes twinkle { 50% { transform: scale(1.5) rotate(20deg); opacity: .4; } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; color: var(--brand-2); }
.logo { font-size: 26px; }
.me { display: flex; align-items: center; gap: 6px; padding: 2px 12px 2px 4px; background: #f3efff; border-radius: 99px; font-weight: 700; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: #f1f2f8;
  display: grid; place-items: center; font-size: 20px; cursor: pointer; transition: transform .15s;
}
.icon-btn:hover { transform: scale(1.08); }

.screen { max-width: 1180px; margin: 0 auto; padding: 18px 16px 60px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 16px; border: 0; cursor: pointer;
  background: #fff; font-weight: 700; box-shadow: 0 4px 0 #d9dbe8; transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9dbe8; }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-2); }
.btn.primary:active { box-shadow: 0 1px 0 var(--brand-2); }
.btn.ghost { background: #f1f2f8; box-shadow: none; }
.btn.danger { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #c22d52; }
.btn.ghost.danger { background: var(--bad-bg); color: var(--bad); box-shadow: none; }
.btn.big { padding: 14px 24px; font-size: 20px; border-radius: 18px; }
.link { color: var(--brand-2); font-weight: 700; }
.mini { border: 0; border-radius: 10px; padding: 3px 10px; font-size: 15px; font-weight: 700; cursor: pointer; background: #f1f2f8; }
.mini.ok { background: var(--ok); color: #fff; }
.mini.bad { background: var(--bad); color: #fff; }
.mini.link { background: none; text-decoration: underline; padding: 0 4px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }

/* ---------- mascots ---------- */
.mascot { width: 110px; height: auto; overflow: visible; flex-shrink: 0; }
.mascot.tiny { width: 34px; }
.mascot.mid { width: 120px; }
.mascot.big { width: 150px; }
.mascot .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
.mascot.mood-wow .eyes { animation: none; }
.mascot .antenna { animation: glow 1.4s ease-in-out infinite; }
.mascot .figure { transform-origin: 60px 120px; }
.mascot.bob .figure { animation: bob 2.6s ease-in-out infinite; }
.mascot.d1 .figure { animation-delay: -.4s; } .mascot.d2 .figure { animation-delay: -1.2s; } .mascot.d3 .figure { animation-delay: -2s; }
.mascot.jump .figure, .mascot.jump-loop .figure { animation: jump .7s cubic-bezier(.3, 1.6, .5, 1) 2; }
.mascot.jump-loop .figure { animation-iteration-count: infinite; animation-duration: 1.2s; }
.mascot.mood-wow .arm-r, .mascot.jump .arm-r { transform-box: fill-box; transform-origin: bottom center; animation: wave .5s ease-in-out infinite alternate; }
.mascot.nod .figure { animation: nod .5s ease-in-out 2; }
.mascot.shake .figure { animation: wiggle .5s ease-in-out 2; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
@keyframes jump { 0%, 100% { transform: translateY(0) scale(1); } 30% { transform: translateY(0) scale(1.1, .9); } 60% { transform: translateY(-26px) scale(.95, 1.05); } }
@keyframes wave { from { transform: rotate(-25deg) translateY(-8px); } to { transform: rotate(25deg) translateY(-14px); } }
@keyframes nod { 50% { transform: rotate(6deg); } }
@keyframes wiggle { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes glow { 50% { fill: #ffd166; } }

.bubble {
  position: relative; background: #fff; border: 3px solid var(--ink); border-radius: 20px;
  padding: 10px 16px; font-weight: 600; box-shadow: 4px 4px 0 var(--ink);
}
.bubble::before {
  content: ''; position: absolute; left: -14px; top: 22px; border: 8px solid transparent; border-right: 12px solid var(--ink);
}

/* ---------- entrance animations ---------- */
.pop { animation: pop .45s cubic-bezier(.2, 1.4, .5, 1) both; }
@keyframes pop { from { opacity: 0; transform: scale(.85) translateY(12px); } }
.shake { animation: wiggle .4s; border-color: var(--bad) !important; }

/* ---------- profiles ---------- */
.hero { text-align: center; padding: 10px 0 20px; }
.hero-crew { display: flex; justify-content: center; gap: 4px; }
.hero-crew .mascot { width: 100px; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; margin-bottom: 24px; }
.profile-card {
  position: relative; background: var(--c, #fff); border-radius: 28px; box-shadow: var(--shadow);
  transition: transform .2s; min-height: 230px; display: flex;
}
.profile-card:hover { transform: translateY(-6px) rotate(-1deg); }
.profile-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 20px 12px; }
.profile-main strong { font-size: 24px; }
.profile-main small { color: #444; font-weight: 600; }
.profile-card .edit { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 50%; background: rgba(255, 255, 255, .7); display: grid; place-items: center; }
.profile-card.add { flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 4px dashed #c8c3ef; background: rgba(255, 255, 255, .6); box-shadow: none; }
.plus { font-size: 54px; color: var(--brand); line-height: 1; }

/* ---------- profile form ---------- */
.form-card { max-width: 680px; margin: 0 auto; }
.preview-card { display: flex; align-items: center; gap: 18px; background: var(--c); border-radius: 22px; padding: 16px 20px; margin: 10px 0 16px; }
.field { display: block; font-weight: 700; margin: 12px 0 6px; }
.field input, .answers input {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 14px;
  border: 3px solid var(--line); background: #fbfbff; font-size: 20px; outline: none; transition: border-color .15s;
}
.field input:focus, .answers input:focus { border-color: var(--brand); background: #fff; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.char { border: 3px solid transparent; background: #f6f6fb; border-radius: 18px; padding: 8px 4px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; font-weight: 700; transition: transform .15s; }
.char .mascot { width: 72px; }
.char:hover { transform: translateY(-3px); }
.char.sel { border-color: var(--brand); background: #f1edff; }
.char.sel .mascot .figure { animation: bob 1.2s ease-in-out infinite; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.swatch { width: 42px; height: 42px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.swatch.sel { box-shadow: 0 0 0 4px var(--brand); }

/* ---------- home ---------- */
.welcome { display: flex; align-items: center; gap: 22px; background: linear-gradient(120deg, var(--c), #fff 85%); }
.welcome-text { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: rgba(255, 255, 255, .85); border-radius: 16px; padding: 6px 14px; display: flex; flex-direction: column; font-size: 14px; color: var(--muted); font-weight: 600; }
.stat b { font-size: 22px; color: var(--ink); }
.tabs { display: flex; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap; }
.tab { border: 0; background: #fff; border-radius: 16px; padding: 10px 18px; font-weight: 800; font-size: 19px; cursor: pointer; box-shadow: 0 4px 0 #d9dbe8; }
.tab.sel { background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-2); }
.grades { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.grade { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 4px 14px; font-weight: 700; cursor: pointer; }
.grade.sel { border-color: var(--brand); background: #f1edff; color: var(--brand-2); }
.grade.locked { color: #aaa; }
.suggest { display: flex; align-items: center; gap: 16px; background: linear-gradient(120deg, #fff3c4, #fff); }
.suggest .mascot { width: 80px; }
.suggest > div { flex: 1; }
.suggest small { color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; scrollbar-width: thin; }
.chip { flex-shrink: 0; border: 0; background: #fff; border-radius: 99px; padding: 6px 14px; font-weight: 700; cursor: pointer; box-shadow: 0 2px 0 #d9dbe8; }
.chip.sel { background: var(--ink); color: #fff; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: 14px 14px 12px;
  background: #fff; border-radius: 20px; border-top: 10px solid var(--t); box-shadow: var(--shadow);
  transition: transform .2s; min-height: 150px;
}
.tile:hover { transform: translateY(-5px) rotate(.8deg); }
.tile .week { font-weight: 800; font-size: 20px; color: var(--t); }
.tile .topic { font-weight: 600; line-height: 1.2; flex: 1; }
.tile .meta { font-size: 14px; color: var(--muted); }
.tile.done::after { content: '✔'; position: absolute; top: 8px; right: 12px; color: var(--ok); font-weight: 800; }
.star { color: #dfe1ea; font-size: 22px; }
.star.on { color: var(--star); text-shadow: 0 2px 0 #e0a800; }
.soon { text-align: center; display: flex; flex-direction: column; align-items: center; }

/* ---------- player ---------- */
.player-top { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.pt-title { display: flex; flex-direction: column; flex: 1; }
.pt-title b { font-size: 22px; }
.pt-title span { color: var(--muted); font-weight: 600; }
.dots { display: flex; gap: 6px; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: #dfe1ea; transition: all .3s; }
.dot.past { background: var(--ok); }
.dot.now { background: var(--brand); transform: scale(1.3); box-shadow: 0 0 0 4px #e3dcff; }
.player-body { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.sheet { padding: 10px; }
.sheet-img { position: relative; width: 100%; }
.sheet-img img { width: 100%; height: 100%; display: block; border-radius: 12px; }
.qpin {
  position: absolute; width: 30px; height: 30px; transform: translate(-115%, -50%);
  border-radius: 50%; border: 3px dashed var(--brand); background: rgba(255, 255, 255, .7); cursor: pointer;
  display: grid; place-items: center; font-weight: 800; font-size: 18px; padding: 0;
}
.qpin.focus { background: var(--brand); border-style: solid; box-shadow: 0 0 0 6px rgba(123, 92, 255, .25); }
.qpin.ok { background: var(--ok); border: 3px solid #fff; color: #fff; width: 38px; height: 38px; box-shadow: 0 3px 8px rgba(0, 0, 0, .2); }
.qpin.bad { background: var(--bad); border: 3px solid #fff; color: #fff; width: 38px; height: 38px; box-shadow: 0 3px 8px rgba(0, 0, 0, .2); }
.qpin.stamp { animation: stamp .45s cubic-bezier(.2, 1.6, .5, 1) both; }
@keyframes stamp { from { transform: translate(-115%, -50%) scale(3) rotate(-30deg); opacity: 0; } }
.panel { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; }
.coach { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.coach .mascot { width: 84px; }
.coach .bubble { flex: 1; font-size: 17px; }
.answers { display: flex; flex-direction: column; gap: 10px; }
.ans-row { border-radius: 16px; padding: 6px; transition: background .2s; }
.ans-row label { display: flex; align-items: center; gap: 10px; }
.ans-row input { margin: 0; flex: 1; min-width: 0; }
.qnum { min-width: 40px; height: 40px; border-radius: 12px; background: #f1edff; color: var(--brand-2); display: grid; place-items: center; font-weight: 800; }
.mark { width: 28px; font-size: 24px; font-weight: 800; text-align: center; }
.ans-row.ok { background: var(--ok-bg); } .ans-row.ok .mark { color: var(--ok); } .ans-row.ok input { border-color: var(--ok); }
.ans-row.bad { background: var(--bad-bg); } .ans-row.bad .mark { color: var(--bad); } .ans-row.bad input { border-color: var(--bad); }
.ans-row.wait { background: #fff6dc; } .ans-row.wait input { border-color: var(--wait); }
.fb { font-size: 15px; padding: 6px 4px 2px 50px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.key { margin-top: 14px; padding: 12px; background: #fffbea; border: 2px dashed var(--wait); border-radius: 16px; }
.key img { display: block; width: 100%; margin-top: 6px; border-radius: 8px; background: #fff; }
.key summary { cursor: pointer; font-weight: 700; }
.actions { margin-top: 16px; }
.actions .btn { flex: 1; }
.hint { color: var(--muted); font-size: 15px; margin: 0; }

/* ---------- result ---------- */
.result { text-align: center; max-width: 760px; margin: 10px auto; display: flex; flex-direction: column; align-items: center; }
.big-stars .star { font-size: 72px; display: inline-block; animation: starpop .6s cubic-bezier(.2, 1.8, .5, 1) both; }
@keyframes starpop { from { transform: scale(0) rotate(-180deg); } }
.score { font-size: 24px; }
.score b { font-size: 30px; color: var(--brand-2); }
.record { font-weight: 800; color: #e07a00; font-size: 20px; }
.detail { margin-top: 18px; width: 100%; text-align: left; }
.detail summary { cursor: pointer; font-weight: 700; color: var(--brand-2); }
.detail-page { margin-top: 10px; }
.detail-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.dq { padding: 2px 10px; border-radius: 10px; font-size: 15px; }
.dq.ok { background: var(--ok-bg); } .dq.bad { background: var(--bad-bg); }
.dq i { color: var(--muted); }

/* ---------- history ---------- */
.chart { width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-dasharray: 4 6; }
.chart .axis { font-size: 13px; fill: var(--muted); }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 2000; animation: draw 1.5s ease-out both; }
.chart .area { fill: rgba(123, 92, 255, .1); }
.chart .pt { fill: #fff; stroke: var(--brand); stroke-width: 3; }
.chart .pt.s3 { fill: var(--star); } .chart .pt.s2 { fill: #ffe7a0; }
@keyframes draw { from { stroke-dashoffset: 2000; } to { stroke-dashoffset: 0; } }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr[data-ws] { cursor: pointer; }
.tbl tr[data-ws]:hover, .tbl tr.sel { background: #f6f3ff; }
.tbl .star { font-size: 16px; }
.tbl small { color: var(--muted); }
.who { display: flex; align-items: center; gap: 6px; }
.up { color: var(--ok); } .down { color: var(--bad); }

/* ---------- modal & confetti ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(43, 45, 66, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 26px; padding: 24px; max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .player-body { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .dots { display: none; }
}
@media (max-width: 560px) {
  body { font-size: 17px; }
  .brand { font-size: 17px; }
  .me span { display: none; }
  .welcome { flex-direction: column; text-align: center; }
  .welcome-text { align-items: center; }
  .suggest { flex-wrap: wrap; justify-content: center; text-align: center; }
  .suggest .btn { width: 100%; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { min-height: 130px; padding: 10px; }
  .profile-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .profile-card { min-height: 190px; }
  .mascot.big { width: 120px; }
  .big-stars .star { font-size: 56px; }
  .bubble::before { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- answer key crops ---------- */
.fb { padding-left: 50px; }
.fb-label { font-weight: 700; color: #b07800; }
.fb.self, .fb.done { flex-direction: column; align-items: flex-start; }
.fb-ask { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.keycrop {
  display: block; position: relative; overflow: hidden; max-width: 100%;
  background: #fff; border: 2px dashed var(--wait); border-radius: 10px;
}
.keycrop img { position: absolute; max-width: none; height: auto; }
.full-key { flex: 0 0 auto !important; }
.lightbox { max-width: min(980px, 96vw); gap: 12px; }
.lb-scroll { width: 100%; overflow-x: auto; background: #fffbea; border-radius: 12px; padding: 10px; }
.lb-scroll img { display: block; min-width: 640px; width: 100%; }

/* ---------- sync & family ---------- */
.sync { font-size: 20px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 26px; font-weight: 700; letter-spacing: .08em; background: #f1edff; color: var(--brand-2); padding: 6px 16px; border-radius: 14px; }
.code-input { font-family: ui-monospace, Menlo, monospace; font-size: 22px; letter-spacing: .08em; text-transform: uppercase; padding: 10px 14px; border-radius: 14px; border: 3px solid var(--line); width: 16ch; max-width: 100%; }
.code-input:focus { border-color: var(--brand); outline: none; }
.join summary { cursor: pointer; font-weight: 700; color: var(--brand-2); margin-top: 8px; }
.boot { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); }
