* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg1: #6a5cff;
  --bg2: #22c1c3;
  --card: #ffffff;
  --ink: #26324a;
  --accent: #ff7a59;
  --green: #2ecc71;
  --red: #ff5c6c;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  color: var(--ink);
  display: flex;
  justify-content: center;
  padding: 16px;
}

.app {
  width: 100%;
  max-width: 560px;
}

.topbar {
  text-align: center;
  color: #fff;
  margin-bottom: 18px;
}
.topbar h1 {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  text-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.subtitle { opacity: .95; margin-top: 4px; }

.card {
  background: var(--card);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 14px 30px rgba(0,0,0,.22);
}
.screen h2 {
  text-align: center;
  margin-bottom: 18px;
  color: var(--bg1);
}
.hidden { display: none; }

/* ปุ่มระดับ */
.levels {
  display: grid;
  gap: 14px;
}
.level-btn {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 2px 14px;
  align-items: center;
  text-align: left;
  border: 3px solid #eef1ff;
  background: #f7f8ff;
  border-radius: 18px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s;
}
.level-btn:hover { transform: translateY(-3px); border-color: var(--bg1); background:#fff; }
.level-btn .emoji { grid-row: 1 / 3; font-size: 2.4rem; }
.level-btn .lname { font-weight: bold; font-size: 1.2rem; color: var(--ink); }
.level-btn .lrange { color: #7c85a3; font-size: .95rem; }

.hint {
  text-align: center;
  margin-top: 16px;
  color: #7c85a3;
}

/* หน้าเกม */
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.stat {
  flex: 1;
  background: #f2f4ff;
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
}
.stat-label { display: block; font-size: .8rem; color: #7c85a3; }
.stat-value { font-size: 1.5rem; font-weight: bold; }

.timebar-wrap {
  height: 12px;
  background: #eef1ff;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 22px;
}
.timebar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), #ffd93b, var(--red));
  transition: width 1s linear;
}

.question {
  text-align: center;
  font-size: clamp(2.2rem, 10vw, 3.4rem);
  font-weight: bold;
  color: var(--bg1);
  margin: 6px 0 10px;
  letter-spacing: 2px;
}

.feedback {
  text-align: center;
  min-height: 28px;
  font-weight: bold;
  font-size: 1.15rem;
  margin-bottom: 14px;
}
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--red); }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.choice {
  padding: 22px 0;
  font-size: 1.8rem;
  font-weight: bold;
  border: none;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 0 #e0603f;
  transition: transform .08s;
}
.choice:active { transform: translateY(4px); box-shadow: 0 2px 0 #e0603f; }
.choice.correct { background: var(--green); box-shadow: 0 6px 0 #24a45b; }
.choice.wrong { background: var(--red); box-shadow: 0 6px 0 #d63a4a; }
.choice:disabled { cursor: default; opacity: .95; }

.ghost-btn {
  display: block;
  margin: 20px auto 0;
  background: transparent;
  border: 2px solid #cfd6ee;
  color: #7c85a3;
  padding: 10px 24px;
  border-radius: 30px;
  cursor: pointer;
  font-size: 1rem;
}
.ghost-btn:hover { border-color: var(--bg1); color: var(--bg1); }

.primary-btn {
  background: var(--bg1);
  color: #fff;
  border: none;
  padding: 14px 30px;
  border-radius: 30px;
  font-size: 1.15rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 6px 0 #4b3fd6;
}
.primary-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #4b3fd6; }

/* หน้าสรุปผล */
.result-emoji { text-align: center; font-size: 4rem; margin: 6px 0 18px; }
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.rstat {
  background: #f2f4ff;
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}
.rstat span { display: block; color: #7c85a3; font-size: .9rem; }
.rstat b { font-size: 1.6rem; color: var(--bg1); }
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.foot {
  text-align: center;
  color: #ffffffcc;
  margin-top: 18px;
  font-size: .9rem;
}

@keyframes pop {
  0% { transform: scale(.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.question.pop { animation: pop .25s ease; }

@media (max-width: 400px) {
  .card { padding: 18px; }
  .choice { font-size: 1.5rem; padding: 18px 0; }
}