/* ===========================
   CSS Variables & Base
=========================== */
:root {
  --ink: #0f172a;
  --paper: #f0f9ff;
  --sky-light: #e0f2fe;
  --sky-mid: #bae6fd;
  --sky-deep: #7dd3fc;
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --red: #dc2626;
  --green: #16a34a;
  --yellow: #fbbf24;
  --muted: #475569;
  --line: 2.5px solid var(--ink);
  font-family: "Mitr", sans-serif;
  color: var(--ink);
}

html { overflow-x: hidden; }
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden !important;
  overscroll-behavior: none;
  background: var(--sky-light);
}

/* ===========================
   Sky Background
=========================== */
.sky-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: linear-gradient(
    165deg,
    #e0f7ff 0%,
    #bae6fd 28%,
    #93c5fd 55%,
    #7dd3fc 78%,
    #a5f3fc 100%
  );
  overflow: hidden;
}

.thai-pattern {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.35;
  animation: drift 18s ease-in-out infinite alternate;
}
.orb-1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, #93c5fd, #60a5fa00);
  top: -120px; left: -80px;
  animation-duration: 22s;
}
.orb-2 {
  width: 380px; height: 380px;
  background: radial-gradient(circle, #a5f3fc, #06b6d400);
  bottom: -60px; right: -60px;
  animation-duration: 17s; animation-delay: -8s;
}
.orb-3 {
  width: 280px; height: 280px;
  background: radial-gradient(circle, #ddd6fe, #7c3aed00);
  top: 40%; left: 60%;
  animation-duration: 25s; animation-delay: -4s;
}
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(30px, -40px) scale(1.08); }
}

/* ===========================
   Header
=========================== */
.site-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(14px, 4vw, 36px);
  pointer-events: none;
}

.brand, .sound-btn, .lang-btn, .support-link { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  transition: transform .22s cubic-bezier(.2,.8,.2,1), filter .22s ease;
}
.brand img { width: 96px; height: auto; display: block; }
.brand:hover { transform: translateY(-4px); filter: drop-shadow(0 6px 8px rgba(14,165,233,.25)); }
.brand:active { transform: translateY(-1px) scale(.98); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.support-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: rgba(255,255,255,.76);
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  transition: transform .15s, box-shadow .15s;
}
.support-link b { color: #0284c7; }
.support-link:hover { transform: translateY(-2px); box-shadow: 4px 5px 0 var(--ink); }

.lang-btn {
  padding: 8px 14px;
  background: rgba(255,255,255,0.75);
  border: 2px solid var(--ink);
  border-radius: 99px;
  box-shadow: 3px 3px 0 var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform .15s, box-shadow .15s;
  white-space: nowrap;
}
.lang-btn:hover { transform: translateY(-2px); box-shadow: 4px 5px 0 var(--ink); }
.lang-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }

.sound-btn {
  width: 44px; height: 44px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(8px);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .15s, box-shadow .15s;
}
.sound-btn:hover { transform: translateY(-2px); box-shadow: 4px 5px 0 var(--ink); }
.sound-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0; }
.sound-btn svg { width: 23px; fill: var(--ink); }
.sound-btn path { stroke: var(--ink); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.sound-btn path:first-child { fill: var(--ink); }
.sound-btn.muted .sound-wave { display: none; }

/* ===========================
   Screens
=========================== */
main {
  position: relative;
  z-index: 1;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
}

.screen {
  display: none;
  height: 100svh;
  min-height: 0;
  max-height: 100svh;
  overflow: hidden;
  width: min(760px, 100%);
  margin: auto;
  padding: clamp(72px, 11vh, 96px) 22px clamp(12px, 3vh, 28px);
}
.screen.active {
  display: flex;
  animation: screen-in .38s cubic-bezier(.2,.8,.2,1);
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(14px) rotate(.15deg); }
  to { opacity: 1; transform: none; }
}

/* ===========================
   Intro Screen
=========================== */
.intro {
  position: relative;
  align-items: center;
  flex-direction: column;
  text-align: center;
  justify-content: center;
}

.hero-sticker {
  background: var(--accent);
  color: #fff;
  border: 2.5px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 6px 14px;
  transform: rotate(-2deg);
  font-weight: 600;
  font-size: 12px;
  border-radius: 4px;
}

.intro h1 {
  font-family: "Chakra Petch", sans-serif;
  font-size: clamp(62px, 12vh, 108px);
  line-height: .85;
  margin: clamp(10px,1.8vh,18px) 0;
  letter-spacing: -.07em;
  color: var(--ink);
  text-shadow: 4px 4px 0 rgba(255,255,255,0.6), 7px 7px 0 rgba(14,165,233,0.2);
}
.intro h1 span { color: var(--accent); display: inline-block; transform: rotate(-4deg); }

.lead {
  font-size: clamp(14px, 2vh, 18px);
  line-height: 1.5;
  margin: 0 0 clamp(8px, 1.4vh, 14px);
  color: var(--muted);
}

.rules {
  display: flex;
  background: rgba(255,255,255,0.7);
  border: 2.5px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  transform: rotate(.8deg);
  margin-bottom: clamp(10px, 1.8vh, 18px);
  border-radius: 8px;
  backdrop-filter: blur(8px);
}
.rules div {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 8px 16px;
}
.rules div + div { border-left: 2px dashed var(--ink); }
.rules strong { font: 700 22px "Chakra Petch"; }
.rules span { font-size: 11px; }

.mode-picker { border: 0; padding: 0; margin: 0; width: 100%; }
.mode-picker legend { font-weight: 600; margin: 0 auto clamp(6px,1.1vh,10px); grid-column: 1/-1; }
.mode-picker { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }

.mode {
  position: relative;
  display: flex;
  min-height: clamp(90px, 15vh, 122px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 6px;
  background: rgba(255,255,255,0.65);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  backdrop-filter: blur(6px);
}
.mode:hover { transform: translateY(-3px); box-shadow: 4px 6px 0 var(--ink); }
.mode.selected {
  background: rgba(219,234,254,0.9);
  transform: rotate(-1.5deg) translateY(-4px);
  box-shadow: 6px 7px 0 var(--ink);
  border-color: var(--accent);
}
.mode input { position: absolute; opacity: 0; }
.mode svg { width: clamp(36px,5.5vh,46px); height: clamp(36px,5.5vh,46px); fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.mode b { font-size: 16px; }
.mode small { color: var(--muted); font-size: 10px; }

.primary-btn, .secondary-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 17px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  cursor: pointer;
}
.primary-btn {
  width: min(360px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent);
  color: #fff;
  padding: 12px 14px 12px 22px;
  box-shadow: 5px 5px 0 var(--ink);
  margin-top: clamp(8px, 1.6vh, 16px);
  transition: transform .15s, box-shadow .15s;
}
.primary-btn i {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 50%;
  font-style: normal;
}
.primary-btn:hover { transform: translateY(-3px); box-shadow: 7px 8px 0 var(--ink); }
.primary-btn:active { transform: translate(3px,3px); box-shadow: 2px 2px 0; }

.tiny-note { font-size: 10px; color: var(--muted); margin: clamp(4px,.8vh,8px) 0 0; }

/* ===========================
   Game Screen
=========================== */
.game { flex-direction: column; align-items: stretch; }

.game-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: clamp(5px,1vh,10px);
}
.game-hud > div:first-child { display: flex; flex-direction: column; }
.game-hud small { font-size: 11px; }
.game-hud strong { font: 700 25px "Chakra Petch"; }
.round {
  font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,0.7);
  border: 2px solid var(--ink);
  padding: 5px 12px; border-radius: 99px;
  backdrop-filter: blur(6px);
}
.streak { text-align: right; font-size: 18px; }
.streak.pop { animation: pop .3s; }
@keyframes pop { 50% { transform: scale(1.35) rotate(-7deg); } }

.timer {
  height: 11px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  background: rgba(255,255,255,0.5);
  overflow: hidden;
}
.timer div { height: 100%; width: 100%; background: var(--green); transition: width .1s linear, background .2s; }
.timer.danger div { background: var(--red); }

.timer-copy { text-align: center; font-size: 11px; color: var(--muted); margin: 4px 0 clamp(8px,1.5vh,16px); }
.timer-copy span { font-weight: 700; color: var(--ink); }

.question-card {
  position: relative;
  display: flex;
  min-height: clamp(150px,22vh,210px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.82);
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  box-shadow: 6px 6px 0 var(--ink);
  transform: rotate(-.4deg);
  margin: 0 3px clamp(10px,1.8vh,18px);
  overflow: visible;
  backdrop-filter: blur(10px);
}
.question-card::before, .question-card::after {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--sky-mid);
  top: 15px;
}
.question-card::before { left: 16px; }
.question-card::after { right: 16px; }
.question-card p { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.question-card h2 {
  font: 700 clamp(60px,16vw,100px)/1 "Chakra Petch";
  letter-spacing: -.04em;
  margin: 4px 0;
  color: var(--ink);
}
.category {
  background: var(--ink);
  color: #fff;
  padding: 3px 12px;
  border-radius: 99px;
  font-size: 10px;
}
.tape {
  position: absolute;
  width: 100px; height: 26px;
  background: rgba(186,230,253,0.6);
  top: -15px;
  transform: rotate(2.5deg);
  border-left: 2px dashed rgba(14,165,233,.4);
  border-right: 2px dashed rgba(14,165,233,.4);
}
.question-card.correct { animation: correct-card .42s; }
.question-card.wrong { animation: wrong-card .38s; }
@keyframes correct-card { 50% { transform: scale(1.022) rotate(.8deg); background: rgba(187,247,208,.9); } }
@keyframes wrong-card { 20%,60% { transform: translateX(-8px) rotate(-1deg); } 40%,80% { transform: translateX(8px) rotate(1deg); } }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(7px,1.2vh,12px); }

.choice {
  position: relative;
  min-height: clamp(56px,8vh,72px);
  padding: 10px 14px 10px 48px;
  text-align: left;
  font: 500 13px/1.4 "Mitr";
  background: rgba(255,255,255,0.78);
  border: 2px solid var(--ink);
  border-radius: 10px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  backdrop-filter: blur(6px);
}
.choice::before {
  content: attr(data-key);
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  font: 700 12px "Chakra Petch";
  background: var(--sky-light);
}
.choice:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 5px 6px 0 var(--ink); }
.choice:active:not(:disabled) { transform: translate(2px,2px); box-shadow: 1px 1px 0; }
.choice.correct { background: rgba(187,247,208,.9); }
.choice.wrong { background: rgba(254,202,202,.9); }
.choice:disabled { color: var(--ink); cursor: default; }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 40;
  transform: translate(-50%, 28px); opacity: 0;
  background: var(--ink); color: #fff;
  padding: 9px 18px; border-radius: 99px;
  font-size: 13px; transition: .18s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===========================
   Result Screen
=========================== */
.result { flex-direction: column; align-items: center; text-align: center; }

.result-stamp {
  display: grid; place-items: center;
  width: 100px; height: 100px;
  border: 4px double var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font: 700 30px "Chakra Petch";
  transform: rotate(-10deg);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  animation: stamp .45s cubic-bezier(.2,1.7,.3,1);
}
@keyframes stamp { from { transform: scale(2.2) rotate(-30deg); opacity: 0; } }

.result h2 { font-size: clamp(28px,6vw,46px); margin: 16px 0 0; }
.result > p { color: var(--muted); margin: 4px 0 18px; }

.score-poster {
  display: flex; align-items: baseline; justify-content: center;
  width: 100%; padding: clamp(10px,1.8vh,18px);
  background: rgba(255,255,255,0.72);
  border: 2.5px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  transform: rotate(.8deg);
  border-radius: 10px;
  backdrop-filter: blur(8px);
}
.score-poster span { margin-right: 18px; font-weight: 600; }
.score-poster strong { font: 700 64px/1 "Chakra Petch"; }
.score-poster small { font: 600 18px "Chakra Petch"; }

.result-grid {
  display: grid; grid-template-columns: repeat(3,1fr);
  width: 100%; gap: 8px; margin: clamp(10px,1.8vh,18px) 0;
}
.result-grid div {
  display: flex; flex-direction: column;
  background: rgba(255,255,255,0.65);
  border: 2px solid var(--ink);
  border-radius: 9px; padding: 10px;
  backdrop-filter: blur(6px);
}
.result-grid b { font: 700 26px "Chakra Petch"; }
.result-grid span { font-size: 10px; color: var(--muted); }

.review {
  width: 100%; text-align: left;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: rgba(255,255,255,0.7);
  overflow: hidden;
  backdrop-filter: blur(6px);
}
.review summary { padding: 12px 16px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
.review[open] summary { border-bottom: 2px solid var(--ink); }
.review[open] #review-list { max-height: 18vh; overflow-y: auto; overscroll-behavior: contain; }
.review-item { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 10px 14px; border-bottom: 1px dashed #94a3b8; font-size: 12px; }
.review-item:last-child { border: 0; }
.review-item b { font: 700 16px "Chakra Petch"; }
.review-item em { font-style: normal; color: var(--muted); }

.result-actions { display: flex; width: 100%; gap: 10px; margin-top: clamp(10px,1.6vh,16px); }
.result-actions .primary-btn { margin: 0; flex: 1; }
.secondary-btn {
  flex: 1;
  background: rgba(255,255,255,0.7);
  padding: 14px;
  box-shadow: 4px 4px 0 var(--ink);
  backdrop-filter: blur(6px);
  transition: transform .15s, box-shadow .15s;
}
.secondary-btn:hover { transform: translateY(-2px); box-shadow: 5px 6px 0 var(--ink); }
.secondary-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0; }

/* ===========================
   Particles
=========================== */
#particles span {
  position: fixed; z-index: 50; pointer-events: none;
  font-size: 22px;
  animation: fly .8s ease-out forwards;
}
@keyframes fly { to { transform: translate(var(--x),var(--y)) rotate(var(--r)); opacity: 0; } }

/* ===========================
   Mobile
=========================== */
@media (max-width: 600px) {
  .site-header { padding: 10px 12px; }
  .brand img { width: 72px; }
  .support-link { padding: 6px 9px; font-size: 10px; }
  .support-link b { display: none; }
  .lang-btn { font-size: 11px; padding: 6px 10px; }
  .screen { padding: 72px 13px 12px; }
  .intro h1 { margin-top: 8px; }
  .lead br { display: none; }
  .rules div { padding: 6px 10px; }
  .mode-picker { gap: 6px; }
  .mode { min-height: clamp(82px,13vh,106px); padding: 5px 3px; }
  .mode svg { width: 36px; height: 36px; }
  .mode b { font-size: 14px; }
  .mode small { font-size: 9px; }
  .question-card { min-height: clamp(130px,20vh,165px); margin-bottom: 10px; }
  .choices { grid-template-columns: 1fr; gap: 7px; }
  .choice { min-height: clamp(46px,7vh,56px); font-size: 12px; padding-top: 8px; padding-bottom: 8px; }
  .toast { bottom: 16px; }
  .score-poster strong { font-size: 50px; }
  .result-grid { gap: 5px; }
  .result-grid div { padding: 7px 4px; }
  .result-actions { flex-direction: column-reverse; gap: 7px; }
  .result-actions button { width: 100%; padding: 10px; }
  .result-stamp { width: 76px; height: 76px; font-size: 24px; }
  .result h2 { font-size: 26px; margin-top: 6px; }
}

@media (max-height: 720px) {
  .screen { padding-top: 64px; padding-bottom: 8px; }
  .hero-sticker { font-size: 10px; padding: 4px 10px; }
  .intro h1 { font-size: clamp(52px,10vh,72px); margin: 6px 0; }
  .lead { font-size: 12px; margin-bottom: 5px; }
  .rules { margin-bottom: 7px; }
  .rules strong { font-size: 18px; }
  .mode-picker legend { font-size: 12px; margin-bottom: 4px; }
  .mode { min-height: 80px; }
  .mode svg { width: 32px; height: 32px; }
  .primary-btn { margin-top: 7px; padding-top: 8px; padding-bottom: 8px; }
  .primary-btn i { width: 30px; height: 30px; }
  .tiny-note { font-size: 9px; margin-top: 3px; }
  .game-hud { margin-bottom: 4px; }
  .timer-copy { margin: 3px 0 7px; }
  .question-card { min-height: 122px; margin-bottom: 8px; }
  .question-card h2 { font-size: 52px; }
  .choices { gap: 5px; }
  .choice { min-height: 42px; padding-top: 6px; padding-bottom: 6px; }
  .result-stamp { width: 60px; height: 60px; font-size: 21px; }
  .result h2 { font-size: 24px; margin-top: 4px; }
  .result > p { font-size: 12px; margin-bottom: 4px; }
  .score-poster { padding: 6px; }
  .score-poster strong { font-size: 40px; }
  .result-grid { margin: 6px 0; }
  .result-grid b { font-size: 20px; }
  .review summary { padding: 7px 12px; font-size: 12px; }
  .result-actions { margin-top: 6px; }
  .result-actions button { padding: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
