:root {
  --ink: #0e1430;
  --ink-2: #161e44;
  --card: #1d2752;
  --card-hi: #27336a;
  --line: #2f3b73;
  --text: #eef1ff;
  --muted: #9aa6d6;
  --gold: #ffc24b;
  --gold-deep: #f5a623;
  --lime: #58e08c;
  --lime-deep: #2fbf6a;
  --red: #ff6b7d;
  --red-deep: #e8455c;
  --radius: 18px;
  --shadow: 0 14px 40px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1100px 700px at 80% -10%, #20296010, transparent),
    radial-gradient(900px 600px at -10% 110%, #2a1a5510, transparent),
    var(--ink);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 820px; margin: 0 auto; padding: 28px 20px 80px; }

/* --- header --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px;
}
.brand {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -.5px;
  display: flex; align-items: center; gap: 10px;
}
.brand .spark { color: var(--gold); }
.who { color: var(--muted); font-size: 14px; }
.who a { color: var(--gold); text-decoration: none; }
.who a:hover { text-decoration: underline; }

/* --- buttons --- */
.btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 500;
  font-size: 17px;
  border: none;
  border-radius: 14px;
  padding: 14px 22px;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  box-shadow: 0 6px 0 #c9851a, var(--shadow);
  transition: transform .06s ease, box-shadow .06s ease;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9851a; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost {
  background: transparent; color: var(--text);
  border: 1.5px solid var(--line); box-shadow: none;
}
.btn.ghost:active { transform: none; }

/* --- hero / search --- */
.hero { text-align: center; margin: 18px 0 30px; }
.hero h1 {
  font-family: 'Fredoka', sans-serif; font-weight: 600;
  font-size: 38px; line-height: 1.05; margin: 0 0 8px; letter-spacing: -1px;
}
.hero p { color: var(--muted); margin: 0; font-size: 16px; }

.searchcard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13px; color: var(--muted);
  margin-bottom: 7px; font-weight: 600; letter-spacing: .2px;
}
.input, select {
  width: 100%; padding: 15px 16px; font-size: 16px;
  background: var(--ink-2); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
  font-family: inherit;
}
.input:focus, select:focus { border-color: var(--gold); }
.row { display: flex; gap: 12px; align-items: flex-end; }
.row .field { flex: 1; margin-bottom: 0; }
.row .countfield { width: 120px; flex: none; }

/* --- refinement chips --- */
.refine { margin-top: 18px; }
.refine .q { font-weight: 600; margin: 14px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 999px; cursor: pointer;
  background: var(--ink-2); border: 1.5px solid var(--line);
  color: var(--text); font-size: 14px; font-family: inherit;
}
.chip.sel { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 600; }

/* --- history --- */
.section-title {
  font-family: 'Fredoka', sans-serif; font-weight: 500;
  font-size: 20px; margin: 36px 0 14px;
}
.empty {
  color: var(--muted); background: var(--ink-2);
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 26px; text-align: center;
}
.quiz-list { display: grid; gap: 10px; }
.quiz-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 18px; gap: 12px;
}
.quiz-item .topic { font-weight: 600; }
.quiz-item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.score-chip {
  font-family: 'Fredoka', sans-serif; font-weight: 600;
  background: var(--ink-2); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 6px 13px; font-size: 14px; white-space: nowrap;
}
.score-chip.good { color: var(--lime); border-color: var(--lime-deep); }
.quiz-actions { display: flex; gap: 8px; }
.mini { font-size: 14px; padding: 9px 14px; }

/* --- play screen --- */
.progress-wrap { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.bar { flex: 1; height: 10px; background: var(--ink-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--lime)); width: 0; transition: width .3s ease; }
.qcount { color: var(--muted); font-size: 14px; white-space: nowrap; }

.question {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow);
}
.question h2 {
  font-family: 'Fredoka', sans-serif; font-weight: 500;
  font-size: 24px; line-height: 1.25; margin: 0 0 20px;
}
.options { display: grid; gap: 12px; }
.opt {
  text-align: left; width: 100%; cursor: pointer;
  background: var(--ink-2); border: 2px solid var(--line);
  color: var(--text); border-radius: 14px; padding: 16px 18px;
  font-size: 16px; font-family: inherit; transition: transform .06s, border-color .15s, background .15s;
  display: flex; align-items: center; gap: 12px;
}
.opt:hover:not(:disabled) { border-color: var(--gold); transform: translateY(-1px); }
.opt .key {
  width: 28px; height: 28px; flex: none; border-radius: 8px;
  background: var(--card-hi); display: grid; place-items: center;
  font-family: 'Fredoka', sans-serif; font-size: 14px; color: var(--muted);
}
.opt.correct { border-color: var(--lime-deep); background: rgba(88,224,140,.13); }
.opt.correct .key { background: var(--lime-deep); color: #06210f; }
.opt.wrong { border-color: var(--red-deep); background: rgba(255,107,125,.12); }
.opt.wrong .key { background: var(--red-deep); color: #2a0509; }
.opt:disabled { cursor: default; }

.feedback {
  margin-top: 18px; border-radius: 14px; padding: 16px 18px;
  font-size: 15px; line-height: 1.5; display: none;
}
.feedback.show { display: block; animation: pop .25s ease; }
.feedback.ok { background: rgba(88,224,140,.12); border: 1px solid var(--lime-deep); }
.feedback.no { background: rgba(255,107,125,.10); border: 1px solid var(--red-deep); }
.feedback .head { font-family: 'Fredoka', sans-serif; font-size: 18px; margin-bottom: 4px; }
#fbshort { font-size: 15px; line-height: 1.45; }
.showhow {
  margin-top: 10px; background: transparent; border: none; cursor: pointer;
  color: var(--gold); font-family: 'Fredoka', sans-serif; font-weight: 500;
  font-size: 14px; padding: 4px 0;
}
.showhow:hover { text-decoration: underline; }
#fbbody { white-space: pre-wrap; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line); font-size: 15px; line-height: 1.55; }
.feedback.ok .head { color: var(--lime); }
.feedback.no .head { color: var(--red); }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.play-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; }
.scoreboard { font-family: 'Fredoka', sans-serif; font-size: 16px; color: var(--gold); }

/* --- results --- */
.result {
  text-align: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 40px 26px; box-shadow: var(--shadow);
}
.result .big {
  font-family: 'Fredoka', sans-serif; font-size: 56px; font-weight: 600;
  color: var(--gold); line-height: 1; margin: 8px 0;
}
.result h2 { font-family: 'Fredoka', sans-serif; font-weight: 500; margin: 0 0 6px; }
.result p { color: var(--muted); margin: 4px 0 22px; }
.result .btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* --- login --- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 34px 28px; box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; font-size: 34px; margin-bottom: 6px; }
.login-card .tag { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.login-card .btn { width: 100%; margin-top: 8px; }
.err { background: rgba(255,107,125,.12); border: 1px solid var(--red-deep);
  color: var(--red); border-radius: 12px; padding: 11px 14px; font-size: 14px; margin-bottom: 16px; }

.hidden { display: none !important; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .wrap { padding: 18px 14px 64px; }
  .hero h1 { font-size: 28px; }
  .hero { margin: 10px 0 22px; }
  .row { flex-direction: column; align-items: stretch; }
  .row .countfield { width: 100%; }
  /* Keep the top bar on one tidy line; shrink the joke button to its emoji. */
  .topbar { gap: 10px; }
  .topbar .right { gap: 8px; }
  .joke-btn { padding: 8px 11px; }
  .joke-btn .label { display: none; }
  .brand { font-size: 24px; }
  .question { padding: 20px 16px; }
  .question h2 { font-size: 21px; }
  .opt { padding: 15px 14px; font-size: 16px; }   /* large tap targets */
  .quiz-item { flex-wrap: wrap; }
  .quiz-actions { width: 100%; justify-content: flex-end; }
  .joke-modal { padding: 24px 18px 20px; }
}
/* iPad / tablet: keep content comfortably narrow, not edge-to-edge. */
@media (min-width: 561px) and (max-width: 1024px) {
  .wrap { max-width: 720px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* --- joke button + modal --- */
.joke-btn {
  font-family: 'Fredoka', sans-serif; font-weight: 500; font-size: 14px;
  border: 1.5px solid var(--line); background: var(--ink-2); color: var(--text);
  border-radius: 999px; padding: 8px 15px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; transition: border-color .15s, transform .06s;
}
.joke-btn:hover { border-color: var(--gold); }
.joke-btn:active { transform: scale(.96); }
.joke-btn .emoji { font-size: 15px; }

.topbar .right { display: flex; align-items: center; gap: 12px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(6,9,24,.72);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
  backdrop-filter: blur(3px);
}
.modal-overlay.show { display: flex; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.joke-modal {
  width: 100%; max-width: 440px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 26px 24px; box-shadow: var(--shadow); position: relative;
  animation: pop .2s ease;
}
.joke-modal .close {
  position: absolute; top: 14px; right: 14px; background: var(--ink-2);
  border: 1.5px solid var(--line); color: var(--muted); width: 32px; height: 32px;
  border-radius: 9px; cursor: pointer; font-size: 18px; line-height: 1;
}
.joke-modal .close:hover { color: var(--text); border-color: var(--gold); }
.joke-modal .jhead {
  font-family: 'Fredoka', sans-serif; font-weight: 500; font-size: 20px;
  color: var(--gold); margin: 0 0 16px; display: flex; align-items: center; gap: 8px;
}
.joke-body {
  font-size: 18px; line-height: 1.5; min-height: 64px;
  display: flex; align-items: center;
}
.joke-foot { display: flex; gap: 10px; margin-top: 22px; }
.joke-foot .btn { flex: 1; }

/* --- review screen --- */
.review-list { display: grid; gap: 16px; }
.review-q {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px;
}
.review-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.review-num {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 14px;
  color: var(--muted);
}
.review-tag {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
}
.review-tag.right { background: rgba(88,224,140,.15); color: var(--lime); }
.review-tag.wrong { background: rgba(255,107,125,.15); color: var(--red); }
.review-tag.skipped { background: var(--ink-2); color: var(--muted); }
.review-question {
  font-family: 'Fredoka', sans-serif; font-weight: 500; font-size: 18px;
  margin-bottom: 14px; line-height: 1.3;
}
.review-options { display: grid; gap: 8px; margin-bottom: 14px; }
.review-opt {
  display: flex; align-items: center; gap: 11px;
  background: var(--ink-2); border: 2px solid var(--line);
  border-radius: 12px; padding: 11px 14px; font-size: 15px;
}
.review-opt .key {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  background: var(--card-hi); display: grid; place-items: center;
  font-family: 'Fredoka', sans-serif; font-size: 13px; color: var(--muted);
}
.review-opt .opt-text { flex: 1; }
.review-opt .opt-mark { font-size: 12px; color: var(--muted); white-space: nowrap; }
.review-opt.correct { border-color: var(--lime-deep); background: rgba(88,224,140,.10); }
.review-opt.correct .key { background: var(--lime-deep); color: #06210f; }
.review-opt.correct .opt-mark { color: var(--lime); }
.review-opt.wrong { border-color: var(--red-deep); background: rgba(255,107,125,.10); }
.review-opt.wrong .key { background: var(--red-deep); color: #2a0509; }
.review-opt.wrong .opt-mark { color: var(--red); }
.review-short { font-size: 15px; line-height: 1.5; color: var(--text); margin-bottom: 6px; }
.review-walk {
  white-space: pre-wrap; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line); font-size: 15px; line-height: 1.55;
}

/* --- regenerate refinement questions (quiet text link, right-aligned) --- */
.regen-row {
  display: flex; justify-content: flex-end;
  margin: 2px 0 18px; padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.regen-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--gold); font-family: 'Fredoka', sans-serif; font-weight: 500;
  font-size: 13px; padding: 4px 2px; display: inline-flex; align-items: center;
  gap: 6px; transition: opacity .15s;
}
.regen-btn:hover { opacity: .75; text-decoration: underline; }
.regen-btn:disabled { opacity: .5; cursor: default; }

/* --- delete quiz trash icon --- */
.trash-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); padding: 7px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.trash-btn:hover { color: var(--red); background: rgba(255,107,125,.10); }
.trash-btn:active { transform: scale(.92); }
