:root {
  --mango: #FF9F1C;
  --mango-deep: #F27405;
  --sun: #FFD23F;
  --sun-soft: #FFF1B8;
  --cream: #FFF8E8;
  --paper: #FFFFFF;
  --ink: #3A2412;
  --ink-soft: #7A5A3E;
  --line: #F5D9A8;
  --leaf: #3FA535;
  --leaf-soft: #E3F6DF;
  --berry: #E5383B;
  --berry-soft: #FFE3E1;
  --radius: 20px;
  --shadow: 0 4px 0 #EBC27A, 0 10px 24px rgba(242, 116, 5, .12);
  --font-display: "Baloo 2", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, #FFE27A 0, transparent 40%),
    radial-gradient(circle at 110% 10%, #FFC46B 0, transparent 35%),
    var(--cream);
  background-attachment: fixed;
  line-height: 1.5;
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 3.5vw, 1.7rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--mango-deep); font-weight: 700; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--mango-deep); outline-offset: 2px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: linear-gradient(90deg, var(--mango) 0%, var(--sun) 100%);
  box-shadow: 0 3px 0 rgba(232, 100, 27, .35);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); }
.brand-mango .mango { width: 40px; height: 40px; display: block; }
.brand-name { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; white-space: nowrap; }
.brand-name b { color: #fff; text-shadow: 0 2px 0 var(--mango-deep); }
.nav { display: flex; align-items: center; gap: 8px; }
.nav .hello { font-weight: 800; display: none; }
@media (min-width: 640px) { .nav .hello { display: inline; } }
@media (max-width: 420px) {
  .brand-name { font-size: 1.1rem; }
  .brand-mango .mango { width: 34px; height: 34px; }
  .nav { gap: 6px; }
  .nav .btn { padding: 6px 12px; }
}
@media (max-width: 340px) { .brand-name { font-size: .95rem; } }

.app { max-width: 1040px; margin: 0 auto; padding: 24px 16px 80px; outline: none; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 20px;
  border: 0; border-radius: 999px; cursor: pointer;
  font-weight: 800; text-decoration: none; text-align: center;
  background: var(--mango-deep); color: #fff;
  box-shadow: 0 4px 0 #B85300;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #B85300; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.btn.sun { background: var(--sun); color: var(--ink); box-shadow: 0 4px 0 #D9A800; }
.btn.ghost { background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }
.btn.danger { background: var(--paper); color: var(--berry); border: 2px solid #F7C3C1; box-shadow: 0 4px 0 #F7C3C1; }
.btn.block { width: 100%; }
.nav .btn { min-height: 38px; padding: 6px 14px; white-space: nowrap; }
.wide-only { display: none; }
@media (min-width: 560px) { .wide-only { display: inline; } }
.topbar { min-width: 0; }
.brand { min-width: 0; }

/* cards & layout */
.card {
  background: var(--paper); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 2px solid var(--line);
}
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.muted { color: var(--ink-soft); }
.small { font-size: .9rem; }
.center { text-align: center; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800;
  background: var(--sun-soft); color: var(--ink); text-transform: uppercase; letter-spacing: .04em;
}
.pill.exam { background: #FFD9C2; }
.pill.test { background: #FFE9A8; }
.pill.photo { background: var(--leaf-soft); }

/* forms */
label { display: block; font-weight: 800; margin-bottom: 6px; }
.field + .field { margin-top: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: 14px; background: #FFFDF7;
  font-size: 16px; /* stops iOS zoom */
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--mango); outline: none; box-shadow: 0 0 0 4px rgba(255, 159, 28, .25); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; margin: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--mango-deep); }
.error-box { background: var(--berry-soft); color: #9B1C1F; border-radius: 14px; padding: 10px 14px; font-weight: 700; }
.error-box:empty { display: none; }

/* landing */
.hero { display: grid; gap: 28px; align-items: center; padding: 12px 0 24px; }
@media (min-width: 860px) { .hero { grid-template-columns: 1.1fr .9fr; } }
.hero-mascot { display: flex; justify-content: center; }
.hero-mascot .mango { width: min(240px, 60vw); height: auto; animation: bob 3s ease-in-out infinite; }
.hero h1 .hl { background: linear-gradient(transparent 55%, var(--sun) 55%); padding: 0 4px; }
.features { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 24px; }
.feature { background: var(--paper); border-radius: 16px; padding: 14px 16px; border: 2px solid var(--line); }
.feature b { display: block; font-family: var(--font-display); font-size: 1.1rem; }
.feature .ico { font-size: 1.5rem; }
.tabs { display: flex; background: var(--sun-soft); border-radius: 999px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 999px; font-weight: 800; cursor: pointer; min-height: 44px; }
.tabs button.on { background: var(--paper); box-shadow: 0 2px 0 var(--line); }

@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) scale(1.05); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* dashboard */
.welcome { display: flex; gap: 16px; align-items: center; }
.welcome .mango { width: 84px; height: 84px; flex: none; }
.actions { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .actions { grid-template-columns: repeat(3, 1fr); } }
.action {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink);
  background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); transition: transform .1s;
}
.action:hover { transform: translateY(-2px); }
.action .ico { font-size: 2rem; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: var(--sun-soft); flex: none; }
.action.hot { background: linear-gradient(135deg, var(--mango) 0%, var(--sun) 100%); border-color: transparent; }
.action.hot .ico { background: rgba(255, 255, 255, .6); }
.action b { display: block; font-family: var(--font-display); font-size: 1.15rem; }
.action span.sub { font-size: .88rem; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--paper); border: 2px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.stat .label { font-size: .82rem; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-family: var(--font-display); font-size: 2rem; font-weight: 800; line-height: 1.1; color: var(--ink); }
.stat .bar { height: 8px; border-radius: 4px; background: var(--sun-soft); margin-top: 8px; overflow: hidden; }
.stat .bar i { display: block; height: 100%; background: var(--mango); border-radius: 4px; }

.two-col { display: grid; gap: 16px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; align-items: start; } }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 2px dashed var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) {
  .list li.quiz-item { flex-wrap: wrap; }
  .list li.quiz-item .btns { width: 100%; justify-content: flex-start; }
}
.score-badge {
  flex: none; width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 1.05rem;
  background: var(--sun-soft); color: var(--ink); border: 2px solid var(--line);
}
.score-badge.great { background: var(--leaf-soft); border-color: #B7E3AF; }
.score-badge.low { background: var(--berry-soft); border-color: #F7C3C1; }
.empty { text-align: center; padding: 16px 8px; }
.empty .mango { width: 80px; height: 80px; }

/* editor */
.q-card { border-left: 8px solid var(--mango); }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.q-num { font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; }
.opt-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.opt-row input[type=radio] { width: 24px; height: 24px; flex: none; accent-color: var(--leaf); }
.opt-row input[type=text] { flex: 1; }
.icon-btn { flex: none; width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--line); background: var(--paper); cursor: pointer; font-weight: 800; }
.tf-pick { display: flex; gap: 10px; }
.tf-pick label { flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; cursor: pointer; margin: 0; }
.tf-pick input { accent-color: var(--leaf); width: 20px; height: 20px; }
.settings { display: grid; gap: 14px; }
@media (min-width: 700px) { .settings { grid-template-columns: 2fr 1fr 1fr; } }
.sticky-save {
  position: sticky; bottom: 12px; z-index: 10; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  background: rgba(255, 248, 232, .92); backdrop-filter: blur(6px); padding: 10px; border-radius: 999px; border: 2px solid var(--line);
}
@media (max-width: 480px) {
  .sticky-save { flex-wrap: nowrap; gap: 8px; padding: 8px; }
  .sticky-save .count { display: none; }
  .sticky-save .btn { flex: 1; padding: 10px 12px; }
}

/* photo */
.drop {
  display: grid; place-items: center; gap: 8px; text-align: center; padding: 28px 16px;
  border: 3px dashed var(--mango); border-radius: var(--radius); background: #FFFBEF; cursor: pointer;
}
.drop.over { background: var(--sun-soft); }
.drop .ico { font-size: 2.6rem; }
.thumbs { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.thumb { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; border: 2px solid var(--line); background: #fff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(58, 36, 18, .8); color: #fff; cursor: pointer; font-weight: 800; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 2px solid var(--line); border-radius: 999px; cursor: pointer; font-weight: 800; background: var(--paper); margin: 0; }
.chip input { accent-color: var(--mango-deep); width: 18px; height: 18px; }
.chip:has(input:checked) { background: var(--sun-soft); border-color: var(--mango); }

.loading { text-align: center; padding: 40px 16px; }
.loading .mango { width: 130px; height: 130px; animation: wiggle .9s ease-in-out infinite; }

/* taking */
.take-bar {
  position: sticky; top: 64px; z-index: 15; display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--paper); border: 2px solid var(--line); border-radius: 999px; padding: 8px 10px 8px 18px; margin-bottom: 16px;
  box-shadow: 0 4px 0 var(--line);
}
.timer { font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.timer.warn { color: var(--berry); animation: wiggle 1s ease-in-out infinite; }
.progress { flex: 1; height: 12px; background: var(--sun-soft); border-radius: 6px; overflow: hidden; min-width: 60px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--mango), var(--sun)); transition: width .25s; }
.q-prompt { font-size: clamp(1.15rem, 3vw, 1.4rem); font-weight: 800; white-space: pre-wrap; }
.choices { display: grid; gap: 10px; margin-top: 16px; }
.choice {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 14px 16px; min-height: 56px; border-radius: 16px; border: 2px solid var(--line); background: #FFFDF7;
  font-weight: 700; box-shadow: 0 3px 0 var(--line); transition: transform .08s;
}
.choice:hover { border-color: var(--mango); }
.choice .letter { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--sun-soft); font-family: var(--font-display); font-weight: 800; }
.choice.on { border-color: var(--mango-deep); background: #FFF0D1; box-shadow: 0 3px 0 var(--mango); }
.choice.on .letter { background: var(--mango-deep); color: #fff; }
.tf-choices { grid-template-columns: 1fr 1fr; }
.q-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.dot { width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-weight: 800; font-size: .85rem; cursor: pointer; }
.dot.done { background: var(--sun); border-color: #E6B800; }
.dot.here { outline: 3px solid var(--mango-deep); outline-offset: 1px; }

/* results */
.result-hero { text-align: center; }
.result-hero .mango { width: 130px; height: 130px; animation: bob 2.4s ease-in-out infinite; }
.big-score { font-family: var(--font-display); font-weight: 800; font-size: clamp(3rem, 12vw, 4.5rem); line-height: 1; }
.review { border-left: 8px solid var(--line); }
.review.right { border-left-color: var(--leaf); }
.review.wrong { border-left-color: var(--berry); }
.ans { border-radius: 12px; padding: 8px 12px; margin-top: 8px; font-weight: 700; }
.ans.yours.right { background: var(--leaf-soft); }
.ans.yours.wrong { background: var(--berry-soft); }
.ans.correct { background: var(--leaf-soft); }
.explain { background: var(--sun-soft); border-radius: 12px; padding: 8px 12px; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 800;
  transition: transform .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--berry); }
