:root {
  --bg: #fff3c4;
  --dot: #f6e3a1;
  --ink: #2d1b4e;
  --muted: #6e5d8c;
  --line: #2d1b4e;
  --card: #fffdf7;
  --real: #59b4ff;
  --fake: #ff6fae;
  --good: #34c77b;
  --bad: #ff5a4e;
  --blob: #b37cff;
  --cheek: #ff9ec7;
  --eye: #ffffff;
  --sheet: #fffdf7;
  --shadow: 5px 5px 0 var(--line);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1530;
    --dot: #2a1e40;
    --ink: #f6eeff;
    --muted: #b9a8d6;
    --line: #0c0716;
    --card: #2f2347;
    --real: #4aa3ee;
    --fake: #f2589c;
    --good: #2fb46f;
    --bad: #ef4b40;
    --blob: #a06cf0;
    --eye: #fffaf0;
    --sheet: #2f2347;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1530; --dot: #2a1e40; --ink: #f6eeff; --muted: #b9a8d6; --line: #0c0716;
  --card: #2f2347; --real: #4aa3ee; --fake: #f2589c; --good: #2fb46f; --bad: #ef4b40;
  --blob: #a06cf0; --eye: #fffaf0; --sheet: #2f2347; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 2.5px, transparent 2.5px);
  background-size: 26px 26px;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  font-family: "Fredoka", sans-serif;
  font-size: 0.7em;
  padding: 0 0.4em;
  border: 2px solid currentColor;
  border-radius: 6px;
  opacity: 0.55;
}

/* Header */
.top {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 0;
}
.logo {
  margin: 0;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: clamp(2.1rem, 9vw, 2.8rem);
  letter-spacing: -0.02em;
  line-height: 1;
  user-select: none;
}
.logo span {
  display: inline-block;
  transform: rotate(var(--r, 0deg)) translateY(var(--y, 0));
  color: var(--c, var(--ink));
  -webkit-text-stroke: 2px var(--line);
  paint-order: stroke fill;
  text-shadow: 2px 3px 0 var(--line);
}
.logo:hover span { animation: wobble 0.6s ease-in-out var(--d, 0s); }
@keyframes wobble {
  0%, 100% { transform: rotate(var(--r)) translateY(var(--y)); }
  40% { transform: rotate(calc(var(--r) * -2)) translateY(-6px); }
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--line);
  transition: transform 0.1s, box-shadow 0.1s;
}
.icon-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }

main {
  width: 100%;
  max-width: 560px;
  padding: 0 16px 24px;
  flex: 1;
}
.subtitle {
  margin: 8px 0 4px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Mascot + speech bubble */
.buddy {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 10px;
  min-height: 112px;
}
.mascot { width: 104px; flex: none; overflow: visible; }
.m-line { stroke: var(--line); }
.m-blob { fill: var(--blob); stroke: var(--line); stroke-width: 3.5; }
.m-foot { fill: var(--blob); stroke: var(--line); stroke-width: 3; }
.m-bobble { fill: var(--fake); stroke: var(--line); stroke-width: 3; }
.m-cheek { fill: var(--cheek); opacity: 0.75; }
.m-eyeball { fill: var(--eye); stroke: var(--line); stroke-width: 3; }
.m-pupils { fill: var(--line); transition: transform 0.15s ease-out; }
.m-mouth { fill: none; stroke: var(--line); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.m-body, .m-eyes-open { transform-box: fill-box; transform-origin: 50% 100%; }
.m-eyes-open { transform-origin: 50% 50%; animation: blink 4.5s infinite; }
.m-eyes-happy, .m-eyes-dizzy { display: none; }
.mascot.happy .m-eyes-open, .mascot.dizzy .m-eyes-open { display: none; }
.mascot.happy .m-eyes-happy { display: inline; }
.mascot.dizzy .m-eyes-dizzy { display: inline; }
.mascot.happy .m-mouth { fill: var(--line); }
.mascot.idle .m-body { animation: breathe 2.6s ease-in-out infinite; }
.mascot.thinking .m-body { animation: jiggle 0.35s ease-in-out infinite; }
.mascot.happy .m-body { animation: hop 0.55s cubic-bezier(.3,1.6,.5,1) 2; }
.mascot.dizzy .m-body { animation: squish 0.7s ease-in-out; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.04, 0.96); } }
@keyframes jiggle { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  20% { transform: translateY(0) scale(1.12, 0.86); }
  55% { transform: translateY(-22px) scale(0.92, 1.1); }
}
@keyframes squish {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.25, 0.7) rotate(-4deg); }
  60% { transform: scale(0.95, 1.05) rotate(3deg); }
  100% { transform: scale(1, 1); }
}

.bubble {
  position: relative;
  flex: 1;
  padding: 12px 16px;
  font-family: "Fredoka", sans-serif;
  font-weight: 500;
  font-size: 1.08rem;
  line-height: 1.3;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 20px;
  box-shadow: 3px 3px 0 var(--line);
}
.bubble::before {
  content: "";
  position: absolute;
  left: -13px;
  top: 50%;
  width: 18px;
  height: 18px;
  background: var(--card);
  border-left: 3px solid var(--line);
  border-bottom: 3px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
}
.bubble.pop { animation: pop 0.3s cubic-bezier(.3,1.7,.5,1); }
@keyframes pop { from { transform: scale(0.85); } to { transform: scale(1); } }

/* Progress pips */
.pips {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
}
.pips li {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: var(--card);
}
.pips li.now { background: var(--blob); animation: pulse 1.2s ease-in-out infinite; }
.pips li.good { background: var(--good); }
.pips li.bad { background: var(--bad); }
@keyframes pulse { 50% { transform: scale(1.18); } }

/* The word card */
.card {
  position: relative;
  container-type: inline-size;
  min-height: 200px;
  padding: 18px 18px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--card);
  border: 3.5px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  transform: rotate(-0.8deg);
  transition: background-color 0.3s;
  overflow: hidden;
}
.card.enter { animation: boing 0.5s cubic-bezier(.3,1.6,.5,1); }
@keyframes boing {
  from { transform: rotate(-6deg) scale(0.7); opacity: 0; }
  to { transform: rotate(-0.8deg) scale(1); opacity: 1; }
}
.card.good { background: color-mix(in srgb, var(--good) 16%, var(--card)); }
.card.bad { background: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.card.bad.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: rotate(-0.8deg) translateX(0); }
  25% { transform: rotate(-0.8deg) translateX(-8px); }
  75% { transform: rotate(-0.8deg) translateX(8px); }
}
.card-count {
  position: absolute;
  top: 12px;
  left: 18px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.word {
  margin-top: 14px;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: min(3.6rem, calc(100cqi / (var(--len, 8) * 0.6)));
  line-height: 1.1;
  letter-spacing: 0.01em;
  word-break: break-all;
}
.stamp {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 3px 10px;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 3px solid currentColor;
  border-radius: 8px;
  transform: rotate(8deg);
  opacity: 0;
}
.stamp.show { animation: slam 0.35s cubic-bezier(.2,1.6,.5,1) forwards; }
.stamp.good { color: var(--good); }
.stamp.bad { color: var(--bad); }
@keyframes slam {
  from { opacity: 0; transform: rotate(8deg) scale(2.4); }
  to { opacity: 1; transform: rotate(8deg) scale(1); }
}
.reveal { margin-top: 10px; animation: rise 0.35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.verdict {
  margin: 0 0 6px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.15rem;
}
.verdict .is-real { color: var(--real); }
.verdict .is-fake { color: var(--fake); }
.def { margin: 0; max-width: 34ch; font-size: 1.02rem; line-height: 1.45; }
.pos { font-style: italic; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: #1c1030;
  border: 3.5px solid var(--line);
  border-radius: 18px;
  box-shadow: 4px 4px 0 var(--line);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active, .btn.pressed { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--line); }
.btn:disabled { cursor: wait; filter: saturate(0.6); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px dashed var(--ink); outline-offset: 4px; }
.btn-real { background: var(--real); }
.btn-fake { background: var(--fake); }
.btn-next, .btn-share { background: #ffd23f; width: 100%; margin-top: 18px; }
.btn kbd { display: none; }
@media (hover: hover) and (pointer: fine) { .btn kbd { display: inline; } }
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
}
.actions .btn { min-height: 64px; }
.wide { width: 100%; margin-top: 8px; }

/* Results */
.results { text-align: center; animation: rise 0.4s ease-out; }
.score {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 5rem;
  line-height: 1;
  margin-top: 6px;
}
.score small { font-size: 0.4em; color: var(--muted); }
.rank {
  display: inline-block;
  margin: 10px 0 4px;
  padding: 6px 16px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.2rem;
  background: var(--blob);
  color: #fff;
  border: 3px solid var(--line);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--line);
  transform: rotate(-2deg);
}
.emoji-row { font-size: 1.6rem; letter-spacing: 0.12em; margin: 12px 0 0; }
.next-in { color: var(--muted); font-weight: 700; margin: 14px 0 0; }
.next-in b { font-family: "Fredoka", sans-serif; color: var(--ink); font-variant-numeric: tabular-nums; }
.recap-title { font-family: "Fredoka", sans-serif; font-size: 1.3rem; margin: 26px 0 10px; }
.recap { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; text-align: left; }
.recap li {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 4px 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 16px;
  box-shadow: 3px 3px 0 var(--line);
}
.recap .mark {
  grid-row: span 2;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  border: 2.5px solid var(--line);
  border-radius: 50%;
}
.recap .mark.good { background: var(--good); }
.recap .mark.bad { background: var(--bad); }
.recap .rw { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 1.15rem; word-break: break-word; }
.recap .rd { font-size: 0.95rem; line-height: 1.4; }
.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-family: "Nunito", sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: 3px;
  color: #1c1030;
  border: 2px solid var(--line);
  border-radius: 999px;
}
.tag-real { background: var(--real); }
.tag-fake { background: var(--fake); }

.foot { padding: 8px 16px 20px; font-size: 0.85rem; color: var(--muted); font-weight: 700; }

/* Dialogs */
.sheet {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 22px 22px 20px;
  color: var(--ink);
  background: var(--sheet);
  border: 3.5px solid var(--line);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--line);
}
.sheet[open] { animation: boing 0.35s cubic-bezier(.3,1.5,.5,1); }
.sheet::backdrop { background: rgb(20 10 40 / 0.45); }
.sheet h2 { font-family: "Fredoka", sans-serif; margin: 0 0 12px; font-size: 1.6rem; }
.sheet h3 { font-family: "Fredoka", sans-serif; margin: 18px 0 8px; }
.sheet p { line-height: 1.5; margin: 0 0 10px; }
.sheet .fine { font-size: 0.88rem; color: var(--muted); }
.close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 34px;
  height: 34px;
  font-size: 1.5rem;
  line-height: 1;
  background: none;
  border: none;
}
.sheet { position: fixed; }
.help-examples { display: grid; gap: 10px; margin: 6px 0 14px; }
.help-examples > div {
  padding: 10px 12px;
  background: var(--bg);
  border: 2.5px solid var(--line);
  border-radius: 14px;
  line-height: 1.35;
}
.help-examples .tag { margin: 0 6px 0 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat-grid b { display: block; font-family: "Fredoka", sans-serif; font-size: 1.8rem; }
.stat-grid span { font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.dist li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: center; font-weight: 800; }
.dist .bar {
  min-width: 26px;
  width: var(--w);
  padding: 1px 8px;
  text-align: right;
  font-size: 0.85rem;
  background: var(--muted);
  color: #fff;
  border-radius: 6px;
}
.dist li.today .bar { background: var(--good); }

/* Toast + confetti */
.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 10;
  padding: 10px 18px;
  max-width: calc(100vw - 32px);
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  color: var(--bg);
  background: var(--ink);
  border-radius: 14px;
  transform: translate(-50%, -150%);
  transition: transform 0.3s cubic-bezier(.3,1.5,.5,1);
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti span {
  position: absolute;
  top: -40px;
  font-size: 1.6rem;
  animation: fall var(--t) linear forwards;
}
@keyframes fall {
  to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
@media (max-width: 380px) {
  .actions { gap: 10px; }
  .btn { font-size: 1.02rem; padding: 12px; }
  .mascot { width: 86px; }
  .bubble { font-size: 0.98rem; }
}
