/* ===================== Reset & Base ===================== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --ink: #1f2937;
  --ink-dim: #6b7280;
  --surface: #ffffff;
  --accent: #ffc93c;
  --shout: #ff4d6d;
  --shadow: 0 12px 28px rgba(31, 41, 55, 0.22);
  --radius-lg: 24px;
  --radius-md: 16px;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: 'IBM Plex Sans Thai', 'Mitr', sans-serif;
  overscroll-behavior: none;
  background: linear-gradient(135deg, #ff9f43, #ffc93c, #2ed9c3, #54a0ff);
  background-size: 400% 400%;
  animation: gradientShift 14s ease infinite;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

h1, h2, h3, .btn {
  font-family: 'Mitr', 'IBM Plex Sans Thai', sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 24px 16px 44px;
  position: relative;
}

/* ===================== Screens ===================== */
.screen {
  display: none;
  animation: fadeSlideIn 0.35s ease;
}
.screen.active {
  display: block;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================== Shared elements ===================== */
.back-home {
  display: inline-block;
  margin-bottom: 12px;
  color: rgba(31,41,55,0.75);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.back-home:active {
  opacity: 0.6;
}

.card {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 100px;
  padding: 17px 18px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:active {
  transform: scale(0.96);
  filter: brightness(0.94);
}
.btn-big {
  padding: 19px;
  font-size: 1.2rem;
}
.btn-primary {
  background: linear-gradient(135deg, #ff4d6d, #ff9f43);
  box-shadow: 0 10px 22px rgba(255, 77, 109, 0.35);
}

.section-label {
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--ink);
}

/* ===================== Start screen ===================== */
.start-wrap {
  text-align: center;
  padding-top: 10px;
}
.badge-emoji {
  font-size: 3rem;
  margin-bottom: 6px;
  animation: floatY 2.4s ease-in-out infinite;
}
@keyframes floatY {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}
.game-title {
  font-size: 2.1rem;
  line-height: 1.2;
  margin: 6px 0 10px;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
.game-subtitle {
  color: rgba(255,255,255,0.95);
  font-size: 0.95rem;
  margin-bottom: 24px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.start-card {
  text-align: left;
}
.count-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.count-btn {
  padding: 13px 0;
  border-radius: 12px;
  border: 2px solid #ffe8b3;
  background: #fff8ea;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
}
.count-btn.selected {
  background: linear-gradient(135deg, #ff4d6d, #ff9f43);
  color: #fff;
  border-color: transparent;
}
.count-hint {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.85rem;
  margin: 14px 0 0;
}

.mode-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid #e5e7eb;
  background: #f9fafb;
  text-align: left;
}
.mode-btn.selected {
  border-color: #ff4d6d;
  background: #fff0f3;
}
.mode-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
}
.mode-desc {
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.rule-card {
  text-align: left;
}
.rule-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--ink-dim);
}

/* ===================== Round screen ===================== */
.round-wrap {
  padding-top: 6px;
  text-align: center;
}
.question-card {
  animation: popCard 0.45s ease;
  border: 3px solid var(--accent);
}
@keyframes popCard {
  0% { opacity: 0; transform: scale(0.7) rotate(-4deg); }
  70% { transform: scale(1.05) rotate(1deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
.question-text {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.4;
}

.phase-area {
  margin: 30px 0;
}
.phase-label {
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 16px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.25);
  min-height: 1.4em;
}
.phase-number {
  font-size: 5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 16px rgba(0,0,0,0.3);
  line-height: 1;
}
.phase-number.tick {
  animation: numberPop 0.5s ease;
}
@keyframes numberPop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}
.phase-number.drama {
  font-size: 9rem;
}
.phase-shout {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--shout);
  background: #fff;
  border-radius: 24px;
  padding: 26px 14px;
  margin: 0;
  box-shadow: var(--shadow);
  animation: shoutPop 0.4s ease;
}
@keyframes shoutPop {
  0% { transform: scale(0.4) rotate(-6deg); opacity: 0; }
  60% { transform: scale(1.1) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

/* ===================== Small screens ===================== */
@media (max-width: 340px) {
  .game-title { font-size: 1.7rem; }
  .question-text { font-size: 1.4rem; }
  .phase-number { font-size: 4rem; }
  .phase-number.drama { font-size: 7rem; }
}
