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

:root {
  --ink: #241a45;
  --ink-dim: #6a5f8f;
  --surface: #ffffff;
  --accent: #ffc93c;
  --bottle-color-1: #2ecc71;
  --bottle-color-2: #1a8f4e;
  --shadow: 0 12px 28px rgba(36, 26, 69, 0.25);
  --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, #ff6b9d, #6c5ce7, #4834d4, #ffc93c);
  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(255,255,255,0.9);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.back-home:active {
  opacity: 0.7;
}

.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:disabled {
  opacity: 0.6;
  transform: none;
}
.btn-big {
  padding: 19px;
  font-size: 1.2rem;
}
.btn-primary {
  background: linear-gradient(135deg, #ff8a3d, var(--accent));
  color: #2b1a00;
  box-shadow: 0 10px 22px rgba(255, 201, 60, 0.4);
}
.btn-secondary {
  background: linear-gradient(135deg, #6c5ce7, #4834d4);
  color: #fff;
  box-shadow: 0 10px 22px rgba(108, 92, 231, 0.4);
}

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

/* ===================== Start screen ===================== */
.start-wrap {
  text-align: center;
  padding-top: 6px;
}
.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.25);
}
.game-subtitle {
  color: rgba(255,255,255,0.92);
  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 #eee0ff;
  background: #f7f4ff;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
}
.count-btn.selected {
  background: linear-gradient(135deg, #ff8a3d, var(--accent));
  color: #2b1a00;
  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 #e5e0f5;
  background: #f7f4ff;
  text-align: left;
}
.mode-btn.selected {
  border-color: #6c5ce7;
  background: #efeaff;
}
.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);
}

/* ===================== Play screen ===================== */
.play-wrap {
  padding-top: 4px;
  text-align: center;
}

.circle-area {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 10px auto 26px;
}

.player-ring {
  position: absolute;
  inset: 0;
}

.player-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  border: 3px solid transparent;
  transition: transform 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.player-badge.winner {
  border-color: var(--accent);
  background: linear-gradient(135deg, #ff8a3d, var(--accent));
  color: #2b1a00;
  transform: scale(1.25);
  animation: winnerPulse 0.9s ease infinite;
  z-index: 2;
}
@keyframes winnerPulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(0,0,0,0.2), 0 0 0 0 rgba(255,201,60,0.6); }
  50% { box-shadow: 0 4px 12px rgba(0,0,0,0.2), 0 0 0 12px rgba(255,201,60,0); }
}

.bottle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 140px;
  margin: -70px 0 0 -12px;
  transform-origin: 50% 50%;
  transform: rotate(0deg);
  transition: transform 4s cubic-bezier(0.24, 0.86, 0.2, 1);
}
.bottle-body {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 72%;
  background: linear-gradient(180deg, var(--bottle-color-1), var(--bottle-color-2));
  border-radius: 12px 12px 6px 6px;
  box-shadow: inset -4px 0 8px rgba(0,0,0,0.15);
}
.bottle-neck {
  position: absolute;
  top: 0;
  left: 50%;
  width: 10px;
  height: 34%;
  margin-left: -5px;
  background: linear-gradient(180deg, var(--bottle-color-2), var(--bottle-color-1));
  border-radius: 5px 5px 0 0;
}
.bottle-cap {
  position: absolute;
  top: -7px;
  left: 50%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

#btn-spin {
  max-width: 280px;
  margin: 0 auto 18px;
}

.result-panel {
  text-align: center;
  animation: popCard 0.4s ease;
}
@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); }
}
.result-winner-text {
  margin: 0 0 4px;
  font-size: 1.6rem;
  font-weight: 700;
}
.mission-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px dashed #eee0ff;
}
.mission-label {
  margin: 0 0 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-dim);
}
.mission-text {
  margin: 0 0 16px;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.5;
}

/* ===================== Small screens ===================== */
@media (max-width: 340px) {
  .game-title { font-size: 1.7rem; }
  .circle-area { width: 260px; height: 260px; }
}
