/* ============================================================
   JazLearnThai - "Duo-Play" design system
   Thesis: a game you want to open daily. Bright navy + tassel-yellow,
   chunky rounded geometry, and tactile 3D press-down buttons.

   Signature: every interactive surface has a solid darker bottom edge
   that collapses as the surface presses down (:active), so the whole UI
   feels physically pressable. Correct answers bounce the mascot; wrong
   answers shake it. All motion respects prefers-reduced-motion.

   Layout goal: the full learning loop (prompt + 4 options) and the answer
   feedback fit the first fold on a phone. Mobile-first density.
   ============================================================ */

:root {
  /* --- brand palette --- */
  --navy:        #2E2C8B;   /* structure, text, hero */
  --navy-deep:   #23215F;   /* button 3D edges, deep shadow */
  --navy-soft:   #EEEEFB;   /* tinted fills on light */
  --yellow:      #FFE100;   /* primary action + XP */
  --yellow-deep: #E0B500;   /* yellow 3D edge */
  --green:       #3FD07A;   /* correct */
  --green-deep:  #29A65E;
  --green-soft:  #E4F9ED;
  --red:         #FF5468;   /* wrong */
  --red-deep:    #D63A4D;
  --red-soft:    #FFE7EA;
  --pink:        #F5A9BC;   /* hearts / lives */
  --sky:         #8ECAE6;   /* progress / audio accent */
  --gold:        #F2C037;

  --canvas:      #FFFDF5;   /* warm off-white page */
  --canvas-2:    #FFF7E0;
  --surface:     #FFFFFF;
  --surface-2:   #F7F7FC;

  --ink:         #2E2C8B;   /* primary text = navy */
  --ink-2:       #4A4880;
  --ink-soft:    #7C7AA6;
  --ink-faint:   #A9A7C6;
  --line:        #E7E6F5;

  /* chunky radii */
  --r-xl: 28px;
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;

  /* soft lift shadows (distinct from the hard 3D press edges) */
  --lift-sm: 0 3px 10px -4px rgba(46,44,139,.18);
  --lift-md: 0 14px 30px -14px rgba(46,44,139,.30);
  --lift-lg: 0 28px 60px -26px rgba(46,44,139,.40);

  --font-display: "Baloo 2", "Nunito", ui-rounded, system-ui, sans-serif;
  --font-body: "Nunito", ui-rounded, system-ui, "Segoe UI", sans-serif;

  /* Thai learning surfaces. Easy (default) = looped, beginner-friendly face;
     hard mode swaps in the loopless display face (see body.font-hard). */
  --font-thai: "Sarabun", "IBM Plex Sans Thai", sans-serif;

  --safe-b: env(safe-area-inset-bottom, 0px);
}

body.font-hard { --font-thai: "Mitr", "IBM Plex Sans Thai", sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  /* soft dotted "confetti" texture over a warm canvas */
  background-color: var(--canvas);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(46,44,139,.055) 1.4px, transparent 0),
    radial-gradient(760px 480px at 90% -10%, rgba(255,225,0,.16), transparent 60%),
    radial-gradient(700px 520px at -8% 110%, rgba(142,202,230,.18), transparent 60%);
  background-size: 22px 22px, auto, auto;
  background-attachment: fixed;
}

/* ================= 3D PRESS BUTTONS (the signature) ================= */
/* A solid darker bottom edge (box-shadow, not blur) that collapses while
   the surface translates down on press. Reused across every control. */
.btn-primary, .opt, .btn-ghost {
  --edge: var(--navy-deep);
  --lift: 5px;
  border: 0; cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, background .14s ease, border-color .14s ease;
}
.btn-primary:active:not(:disabled),
.opt:active:not(:disabled),
.btn-ghost:active {
  transform: translateY(var(--lift));
  box-shadow: 0 0 0 0 var(--edge) !important;
}
:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }

/* ---------- App shell ---------- */
.app {
  position: relative; z-index: 1;
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px 28px;
  display: flex; flex-direction: column; gap: 13px;
  /* opacity-only entrance: never leaves a lingering transform, so the pinned
     Lanjut button stays viewport-relative on phones. */
  animation: fade .45s ease both;
}

/* ---------- Brand bar ---------- */
.brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand-logo { height: 40px; width: auto; flex: 0 0 auto; }

.dir-toggle {
  display: inline-flex; background: var(--surface); border: 2px solid var(--line);
  border-radius: 999px; padding: 4px; gap: 3px; box-shadow: var(--lift-sm);
}
.dir-toggle button {
  border: 0; background: transparent; color: var(--ink-soft); cursor: pointer;
  font-family: var(--font-display); font-size: .82rem; font-weight: 700;
  padding: 8px 14px; border-radius: 999px; transition: all .16s ease;
}
.dir-toggle button:hover { color: var(--navy); }
.dir-toggle button.active {
  color: var(--navy);
  background: var(--yellow);
  box-shadow: 0 3px 0 0 var(--yellow-deep);
}

/* ---------- Identity strip ---------- */
.me-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.me-hi { font-size: .95rem; color: var(--ink-soft); font-weight: 600; }
.me-hi b { color: var(--navy); font-weight: 800; }
.me-switch {
  border: 2px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer;
  font-family: var(--font-display); font-size: .78rem; font-weight: 700;
  padding: 7px 15px; border-radius: 999px; transition: all .15s ease;
}
.me-switch:hover { border-color: var(--navy); color: var(--navy); }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; z-index: 40; padding: 24px;
  display: flex; align-items: center; justify-content: center;
  animation: fade .25s ease both;
}
.login-card {
  position: relative; width: 100%; max-width: 400px;
  background: var(--surface); border: 3px solid var(--navy);
  border-radius: var(--r-xl); padding: 44px 26px 26px;
  box-shadow: 0 12px 0 0 var(--navy-deep), var(--lift-lg);
  text-align: center; animation: pop .4s cubic-bezier(.2,.9,.3,1) both;
}
.login-mascot {
  width: 108px; height: auto; display: block; margin: -84px auto 6px;
  filter: drop-shadow(0 10px 14px rgba(46,44,139,.22));
  animation: bob 3s ease-in-out infinite;
}
.login-logo { width: 190px; max-width: 78%; height: auto; margin: 6px auto 4px; display: block; }
.login-title { font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; margin: 10px 0 8px; color: var(--navy); }
.login-sub { color: var(--ink-soft); font-size: .92rem; line-height: 1.5; margin: 0 0 22px; font-weight: 600; }
.login-input {
  width: 100%; border: 2.5px solid var(--line); background: var(--surface-2);
  border-radius: var(--r-md); padding: 14px 16px; margin-bottom: 14px;
  font-family: var(--font-body); font-size: 1rem; font-weight: 600; color: var(--navy);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.login-input::placeholder { color: var(--ink-faint); font-weight: 600; }
.login-input:focus { outline: 0; border-color: var(--navy); box-shadow: 0 0 0 4px var(--navy-soft); }
.login-error { color: var(--red-deep); font-size: .86rem; line-height: 1.45; margin: 14px 0 0; font-weight: 700; }
.login-note { color: var(--ink-faint); font-size: .82rem; margin: 18px 0 0; font-weight: 600; }

/* ---------- Stats chips ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.stat {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 10px 4px 9px; text-align: center; box-shadow: var(--lift-sm);
}
.stat.due    { border-color: #DAD9F3; }
.stat.mastered { border-color: #CFEAD9; }
.stat.ok     { border-color: #CFEED9; }
.stat.bad    { border-color: #FBD4D9; }
.stat.streak { border-color: #FBE7A6; background: var(--canvas-2); }
.stat .num { display: block; font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; line-height: 1; color: var(--navy); }
.stat.ok .num     { color: var(--green-deep); }
.stat.bad .num    { color: var(--red-deep); }
.stat.streak .num { color: var(--gold); }
.stat.mastered .num { color: var(--green-deep); }
.stat .lbl { display: block; margin-top: 5px; font-size: .55rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .5px; font-weight: 800; line-height: 1.15; }

/* ---------- Card ---------- */
.card {
  position: relative;
  background: var(--surface);
  border: 3px solid var(--navy);
  border-radius: var(--r-xl);
  padding: 20px 18px 18px;
  box-shadow: 0 10px 0 0 var(--navy-deep), var(--lift-md);
  display: flex; flex-direction: column; gap: 14px;
}
.card.dealt { animation: deal .42s cubic-bezier(.2,.8,.2,1) both; }

/* Mascot peeks over the top-right corner and reacts to the answer. */
.mascot { position: absolute; top: -46px; right: 10px; width: 88px; height: 92px; pointer-events: none; z-index: 2; }
.mascot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 8px 10px rgba(46,44,139,.20)); }
.mascot .m-idle { animation: bob 3s ease-in-out infinite; }
.mascot .m-correct, .mascot .m-wrong { opacity: 0; transform: scale(.7); }
body.correct-answer .mascot .m-idle,
body.wrong-answer   .mascot .m-idle { opacity: 0; }
body.correct-answer .mascot .m-correct { opacity: 1; transform: scale(1); animation: pop-bounce .5s cubic-bezier(.2,1.3,.4,1) both; }
body.wrong-answer   .mascot .m-wrong   { opacity: 1; transform: scale(1); animation: mascot-shake .45s ease both; }

.card-meta { display: flex; align-items: center; justify-content: space-between; padding-right: 74px; }
.level { display: inline-flex; align-items: center; gap: 8px; }
.level-label { font-size: .62rem; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-faint); font-weight: 800; }
.pips { display: inline-flex; gap: 5px; }
.pip { width: 9px; height: 9px; border-radius: 50%; background: var(--line); transition: background .2s ease, transform .2s ease; }
.pip.on { background: var(--yellow); box-shadow: 0 1px 0 var(--yellow-deep); transform: scale(1.1); }
.pip.on.mastered { background: var(--green); box-shadow: 0 1px 0 var(--green-deep); }
.dir-pill {
  font-size: .72rem; font-weight: 800; color: var(--navy);
  background: var(--navy-soft); border: 2px solid #DEDDF6;
  padding: 4px 11px; border-radius: 999px;
}

.prompt-wrap { text-align: center; padding: 6px 4px 0; }
.prompt-tag { display: inline-block; font-size: .76rem; color: var(--ink-soft); font-weight: 800; margin-bottom: 8px; letter-spacing: .3px; }
.prompt {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.75rem; line-height: 1.25; color: var(--navy); word-break: break-word;
}
.prompt.is-thai { font-family: var(--font-thai); font-size: 2.8rem; font-weight: 700; letter-spacing: .5px; }

/* ---------- Options (3D press tiles) ---------- */
.options { display: grid; gap: 11px; }
.opt {
  position: relative; text-align: left;
  background: var(--surface); border: 2.5px solid var(--line);
  color: var(--navy);
  font-family: var(--font-body); font-size: 1.04rem; font-weight: 700;
  padding: 13px 14px 13px 50px; border-radius: var(--r-md);
  box-shadow: 0 4px 0 0 var(--line);
  animation: rise .32s ease both;
}
.opt.is-thai { font-family: var(--font-thai); font-size: 1.35rem; font-weight: 600; }
.opt .badge {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); border: 2px solid var(--line); color: var(--ink-soft);
  font-family: var(--font-display); font-size: .82rem; font-weight: 800;
}
.opt:hover:not(:disabled) { border-color: var(--navy); box-shadow: 0 4px 0 0 var(--navy); transform: translateY(-1px); }
.opt:hover:not(:disabled) .badge { border-color: var(--navy); color: var(--navy); }
.opt:disabled { cursor: default; }
.opt.correct { background: var(--green-soft); border-color: var(--green); color: var(--green-deep); box-shadow: 0 4px 0 0 var(--green-deep); }
.opt.correct .badge { background: var(--green); border-color: var(--green); color: #fff; }
.opt.wrong { background: var(--red-soft); border-color: var(--red); color: var(--red-deep); box-shadow: 0 4px 0 0 var(--red-deep); animation: shake .4s ease; }
/* Save failed (e.g. server hiccup): shake the tapped tile; the card re-arms. */
.opt.shake-err { animation: shake .4s ease; }
.opt.wrong .badge { background: var(--red); border-color: var(--red); color: #fff; }

/* After answering, the two un-picked distractors collapse to reclaim the fold. */
.opt.gone {
  padding-top: 0; padding-bottom: 0; margin: 0;
  max-height: 0; min-height: 0; opacity: 0; border-width: 0; box-shadow: none;
  pointer-events: none; overflow: hidden;
  transition: max-height .28s ease, opacity .2s ease, padding .28s ease;
}

/* ---------- Reveal + example ---------- */
.afterthought { display: flex; flex-direction: column; gap: 11px; animation: rise .34s ease both; }
.reveal {
  background: var(--canvas-2); border: 2px solid var(--yellow); border-radius: var(--r-md);
  padding: 13px 15px; line-height: 1.45;
}
.reveal .r-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.reveal .r-thai { font-family: var(--font-thai); font-size: 1.5rem; font-weight: 700; color: var(--navy); }
.reveal .r-roman { color: var(--green-deep); font-weight: 800; font-size: 1rem; }
.reveal .r-tone { color: var(--ink-faint); font-size: .82rem; font-weight: 700; }
.reveal .r-meaning { font-weight: 800; margin-top: 3px; color: var(--navy); }
.reveal .r-note { display: block; color: var(--ink-2); font-size: .86rem; margin-top: 6px; font-weight: 600; }

.example {
  background: var(--surface-2); border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 13px 15px;
}
.example .ex-label { font-size: .64rem; text-transform: uppercase; letter-spacing: .8px; color: var(--sky); font-weight: 800; margin-bottom: 8px; }
.example .ex-thai { font-family: var(--font-thai); font-size: 1.4rem; font-weight: 600; line-height: 1.4; color: var(--navy); }
.example .ex-roman { color: var(--green-deep); font-weight: 800; font-size: .94rem; margin-top: 4px; }
.example .ex-meaning { color: var(--ink-soft); font-style: italic; font-size: .94rem; margin-top: 3px; font-weight: 600; }

.bd-toggle {
  margin-top: 11px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 2px dashed var(--line); background: transparent; cursor: pointer;
  font-family: var(--font-display); font-size: .82rem; font-weight: 800; color: var(--navy);
  padding: 9px 12px; border-radius: var(--r-sm); transition: background .15s ease, border-color .15s ease;
}
.bd-toggle:hover { background: var(--surface); border-color: var(--navy); }
.bd-toggle .chev { transition: transform .2s ease; font-size: .7rem; }
.bd-toggle.open .chev { transform: rotate(180deg); }
.breakdown { margin-top: 11px; border-top: 2px dashed var(--line); padding-top: 11px; display: flex; flex-direction: column; gap: 8px; }
.breakdown.collapsed { display: none; }
.bd-row { display: grid; grid-template-columns: minmax(54px,auto) minmax(78px,auto) 1fr; gap: 12px; align-items: baseline; font-size: .92rem; }
.bd-thai { font-family: var(--font-thai); font-weight: 600; color: var(--navy); }
.bd-roman { color: var(--green-deep); font-weight: 700; }
.bd-arti { color: var(--ink-soft); font-weight: 600; }

/* ---------- Primary + ghost buttons ---------- */
.card-actions { display: flex; }
.btn-primary {
  width: 100%;
  font-family: var(--font-display); font-size: 1.08rem; font-weight: 800; color: var(--navy);
  padding: 15px; border-radius: var(--r-md);
  background: var(--yellow);
  box-shadow: 0 5px 0 0 var(--yellow-deep);
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  letter-spacing: .2px;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.03); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.kbd { font-family: var(--font-body); font-size: .72rem; font-weight: 800; background: rgba(46,44,139,.14); color: var(--navy); border-radius: 6px; padding: 2px 7px; }

.footer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.font-toggle { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 2px solid var(--line); border-radius: 999px; padding: 3px 4px 3px 12px; box-shadow: var(--lift-sm); }
.font-toggle .ft-label { font-family: var(--font-thai); font-size: .78rem; font-weight: 700; color: var(--ink-soft); white-space: nowrap; }
.font-toggle button { border: 0; background: transparent; cursor: pointer; font-family: var(--font-display); font-size: .76rem; font-weight: 800; color: var(--ink-soft); padding: 7px 12px; border-radius: 999px; transition: all .15s ease; }
.font-toggle button:hover { color: var(--navy); }
.font-toggle button.active { color: var(--navy); background: var(--yellow); box-shadow: 0 2px 0 0 var(--yellow-deep); }

.btn-ghost {
  --edge: #D8D7EE; --lift: 4px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink-soft);
  font-family: var(--font-display); font-size: .84rem; font-weight: 800;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 4px 0 0 #E4E3F2;
}
.btn-ghost:hover { border-color: var(--red); color: var(--red-deep); box-shadow: 0 4px 0 0 var(--red); }
.hint { font-size: .78rem; color: var(--ink-faint); text-align: center; margin: -2px 0 0; font-weight: 600; }

/* ---------- Done state ---------- */
.done { text-align: center; background: var(--surface); border: 3px solid var(--navy); border-radius: var(--r-xl); padding: 30px 26px 34px; box-shadow: 0 10px 0 0 var(--navy-deep), var(--lift-md); }
.done-mascot { width: 128px; height: auto; margin: 0 auto 6px; display: block; animation: bob 3s ease-in-out infinite; }
.done h2 { font-family: var(--font-display); font-weight: 800; margin: 0 0 8px; color: var(--navy); }
.done p { color: var(--ink-soft); margin: 0; line-height: 1.5; font-weight: 600; }

/* ---------- Summary overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 30; padding: 64px 20px 20px;
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto;
  background: rgba(35,33,95,.55); backdrop-filter: blur(7px);
  animation: fade .25s ease both;
}
.summary-card {
  position: relative; background: var(--surface); border: 3px solid var(--navy);
  border-radius: var(--r-xl); padding: 30px 24px 24px; max-width: 460px; width: 100%;
  box-shadow: 0 12px 0 0 var(--navy-deep), var(--lift-lg); text-align: center;
  animation: pop .4s cubic-bezier(.2,.9,.3,1) both; margin: auto;
}
.summary-mascot { width: 96px; height: auto; display: block; margin: -74px auto 2px; filter: drop-shadow(0 10px 14px rgba(46,44,139,.22)); }
.summary-close { position: absolute; top: 12px; right: 14px; border: 0; background: var(--surface-2); width: 32px; height: 32px; border-radius: 50%; font-size: 1.3rem; line-height: 1; color: var(--ink-soft); cursor: pointer; }
.summary-close:hover { color: var(--navy); background: var(--navy-soft); }
.summary-kicker { font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; color: var(--sky); font-weight: 800; }

.ring-wrap { position: relative; width: 132px; height: 132px; margin: 14px auto 16px; }
.ring { width: 132px; height: 132px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--green); stroke-width: 12; stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .9s cubic-bezier(.2,.8,.2,1); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-num { font-family: var(--font-display); font-weight: 800; font-size: 2.1rem; color: var(--navy); line-height: 1; }
.ring-lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-faint); margin-top: 3px; font-weight: 800; }

.summary-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-bottom: 18px; }
.sstat { background: var(--surface-2); border: 2px solid var(--line); border-radius: var(--r-md); padding: 12px 4px; }
.sstat .num { display: block; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; line-height: 1; color: var(--navy); }
.sstat.ok .num { color: var(--green-deep); }
.sstat.bad .num { color: var(--red-deep); }
.sstat.streak .num { color: var(--gold); }
.sstat .lbl { display: block; font-size: .58rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .4px; margin-top: 5px; font-weight: 800; }

.summary-miss { margin-bottom: 18px; text-align: left; }
.summary-miss h3 { font-size: .74rem; color: var(--red-deep); text-transform: uppercase; letter-spacing: .6px; margin: 0 0 9px; font-weight: 800; }
.summary-miss ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 210px; overflow-y: auto; }
.summary-miss li { background: var(--red-soft); border: 2px solid #FBD4D9; border-radius: var(--r-sm); padding: 10px 13px; font-size: .94rem; font-weight: 600; }
.summary-miss li .m-thai { font-family: var(--font-thai); font-weight: 700; color: var(--navy); }
.summary-miss li .m-roman { color: var(--green-deep); font-weight: 700; }
.summary-miss li .m-arti { color: var(--ink-soft); }
.summary-miss .clean { background: var(--green-soft); border-color: #BFE9CF; color: var(--green-deep); padding: 12px 14px; border-radius: var(--r-sm); font-weight: 800; }

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes deal { from { opacity: 0; transform: translateY(16px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes shake { 10%,90%{transform:translateX(-1px)} 20%,80%{transform:translateX(2px)} 30%,50%,70%{transform:translateX(-4px)} 40%,60%{transform:translateX(4px)} }
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
@keyframes pop-bounce { 0%{transform:scale(.6)} 55%{transform:scale(1.15)} 100%{transform:scale(1)} }
@keyframes mascot-shake { 0%,100%{transform:translateX(0) rotate(0)} 25%{transform:translateX(-5px) rotate(-5deg)} 75%{transform:translateX(5px) rotate(5deg)} }

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

/* ---------- Phone: pin continue, keep loop in the fold ---------- */
@media (max-width: 560px) {
  .app { padding: 13px 13px 24px; gap: 11px; }
  .brand { justify-content: space-between; }
  .brand-logo { height: 34px; }
  .dir-toggle { padding: 3px; }
  .dir-toggle button { padding: 7px 10px; font-size: .76rem; }

  .stats { gap: 6px; }
  .stat { padding: 9px 3px 8px; border-radius: 13px; }
  .stat .num { font-size: 1.16rem; }
  .stat .lbl { font-size: .5rem; }

  .card { padding: 16px 14px 14px; gap: 12px; }
  .mascot { width: 72px; height: 76px; top: -40px; right: 6px; }
  .card-meta { padding-right: 62px; }
  .prompt.is-thai { font-size: 2.5rem; }
  .prompt { font-size: 1.55rem; }

  /* When answered, the Lanjut button pins to the bottom so the user never
     scrolls to continue; the example/breakdown scroll above it. */
  body.answered { padding-bottom: 82px; }
  body.answered .card-actions:not([hidden]) {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 10px 13px calc(12px + var(--safe-b));
    background: linear-gradient(to top, var(--canvas) 62%, rgba(255,253,245,0));
  }
  body.answered .footer-row, body.answered .hint { display: none; }

  .summary-stats { grid-template-columns: repeat(2, 1fr); }
  .bd-row { grid-template-columns: minmax(48px,auto) 1fr; }
  .bd-row .bd-arti { grid-column: 1 / -1; margin-top: -2px; }
}

/* Wider screens: a little more generosity. */
@media (min-width: 561px) {
  .app { max-width: 600px; padding: 24px 20px 36px; gap: 16px; }
  .card { padding: 26px 24px 22px; gap: 18px; }
  .mascot { width: 98px; height: 104px; top: -52px; }
  .prompt.is-thai { font-size: 3.1rem; }
  .prompt { font-size: 2rem; }
  .stat .num { font-size: 1.45rem; }
}
