/* ─── Reset & Global ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
}

/* ─── Game Container ─── */
#game-container {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 500px;
  margin: 0 auto;
  height: 100dvh;
  height: 100vh; /* fallback */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

/* ─── Header Bar ─── */
header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  min-height: 48px;
}

#level-display {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

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

#hint-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-width: 44px;
  min-height: 44px;
}

#hint-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.35);
}

#hint-btn .icon {
  font-size: 1.15rem;
}

#reset-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.3rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#reset-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

/* ─── Bonus Words Bar ─── */
#bonus-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 16px 4px;
}

#bonus-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-height: 32px;
}

#bonus-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.25);
}

.bonus-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 10px;
  padding: 0 5px;
}

#bonus-charge-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  min-height: 32px;
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
}

#bonus-charge-meter .charge-label {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.bonus-charge-track {
  display: flex;
  align-items: center;
  gap: 5px;
}

.bonus-charge-pip {
  width: 14px;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
}

.bonus-charge-pip.filled {
  background: linear-gradient(90deg, #ffd56f, #ffb347);
  box-shadow:
    0 0 8px rgba(255, 198, 80, 0.6),
    inset 0 0 0 1px rgba(255, 240, 190, 0.7);
  transform: translateY(-1px);
}

#bonus-btn.bonus-gain,
.bonus-badge.bonus-gain,
#bonus-charge-meter.bonus-gain {
  animation: bonusGainPop 0.45s ease;
}

#bonus-charge-meter.charge-reset .bonus-charge-pip {
  animation: chargeResetSweep 0.6s ease;
}

#hint-btn.hint-reward {
  animation: hintRewardPulse 0.7s ease;
}

@keyframes bonusGainPop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes chargeResetSweep {
  0%   { opacity: 1; }
  30%  { opacity: 0.3; transform: scaleX(1.1); }
  100% { opacity: 1; transform: scaleX(1); }
}

@keyframes hintRewardPulse {
  0%   { transform: scale(1); box-shadow: 0 0 0 rgba(255, 235, 120, 0); }
  35%  { transform: scale(1.08); box-shadow: 0 0 12px rgba(255, 235, 120, 0.6); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(255, 235, 120, 0); }
}

/* ─── Bonus Words Panel ─── */
#bonus-panel {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translate(-50%, 100%);
  width: 100%;
  max-width: 500px;
  max-height: 55vh;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
  z-index: 60;
  transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#bonus-panel.visible {
  transform: translate(-50%, 0);
}

.bonus-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 10px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.bonus-panel-header h3 {
  font-size: 1.05rem;
  font-weight: 800;
  color: #4a3b6b;
}

#bonus-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #999;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s;
}

#bonus-close:active {
  background: #f0f0f0;
}

#bonus-words-list {
  padding: 14px 20px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}

.bonus-empty {
  color: #aaa;
  font-size: 0.9rem;
  font-weight: 600;
  width: 100%;
  text-align: center;
  padding: 20px 0;
}

.bonus-word-chip {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 50px;
  letter-spacing: 1px;
  animation: chipIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chipIn {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#bonus-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

#bonus-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Grid Area (Word List) ─── */
#grid-area {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  padding: 4px 12px;
}

#grid-container {
  --cell-size: 36px;
  --cell-gap: 6px;
  --cell-font: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* Word list — words stacked vertically, each word's letters horizontal */
.word-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--cell-gap);
  width: 100%;
}

.word-row {
  display: flex;
  gap: var(--cell-gap);
  justify-content: center;
}

.word-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.13);
  border: 2px solid rgba(255, 255, 255, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

.word-cell.revealed {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.cell-letter {
  font-size: var(--cell-font);
  font-weight: 800;
  color: #4a3b6b;
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.2s, transform 0.2s;
}

.word-cell.revealed .cell-letter {
  opacity: 1;
  transform: scale(1);
}

/* Word cell animations */
.word-cell.pop-in .cell-letter {
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.word-cell.pulse {
  animation: pulse 0.5s ease;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); background: rgba(255, 220, 100, 0.9); }
}

.word-cell.hint-glow {
  animation: hintGlow 1s ease;
}

@keyframes hintGlow {
  0%, 100% { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
  50%      { box-shadow: 0 0 12px 4px rgba(255, 200, 50, 0.7); }
}

/* ─── Current Word Display ─── */
#current-word {
  flex-shrink: 0;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 4px;
  min-height: 44px;
  line-height: 44px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  text-transform: uppercase;
}

#current-word.active {
  animation: wordBounce 0.12s ease;
}

@keyframes wordBounce {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

#current-word.shake {
  animation: shake 0.4s ease;
  color: #ff6b6b;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-8px); }
  30%      { transform: translateX(8px); }
  45%      { transform: translateX(-6px); }
  60%      { transform: translateX(6px); }
  75%      { transform: translateX(-3px); }
  90%      { transform: translateX(3px); }
}

#current-word.correct {
  animation: correctFlash 0.4s ease;
  color: #51e898;
}

@keyframes correctFlash {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}

/* ─── Wheel Area ─── */
#wheel-area {
  flex-shrink: 0;
  height: 40%;
  min-height: 200px;
  position: relative;
  touch-action: none;
}

#wheel-container {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.wheel-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
}

.wheel-letter {
  position: absolute;
  width: clamp(44px, 13vw, 60px);
  height: clamp(44px, 13vw, 60px);
  border-radius: 50%;
  background: #fff;
  color: #4a3b6b;
  font-size: clamp(18px, 5.5vw, 26px);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: background 0.12s, transform 0.12s, box-shadow 0.12s;
  z-index: 2;
}

.wheel-letter.selected {
  background: #ffa726;
  color: #fff;
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: 0 4px 14px rgba(255, 167, 38, 0.45);
}

/* SVG connecting line */
.wheel-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.swipe-line {
  fill: none;
  stroke: rgba(255, 167, 38, 0.6);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Toast ─── */
#toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(40, 30, 60, 0.88);
  color: #fff;
  padding: 12px 28px;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

#toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ─── Level Complete Overlay ─── */
#level-complete {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 50, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#level-complete.visible {
  opacity: 1;
  pointer-events: auto;
}

.complete-content {
  text-align: center;
  transform: scale(0.8);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#level-complete.visible .complete-content {
  transform: scale(1);
}

.complete-star {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 8px;
}

.complete-content h2 {
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 6px;
}

.complete-content p {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 28px;
}

#next-level-btn {
  background: linear-gradient(135deg, #ffa726, #ff7043);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 800;
  padding: 14px 48px;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 112, 67, 0.4);
  transition: transform 0.1s;
  min-height: 50px;
}

#next-level-btn:active {
  transform: scale(0.95);
}

/* ─── All Done message ─── */
.all-done {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  padding: 40px 20px;
}

/* ─── Confetti-like decorative dots on complete ─── */
#level-complete.visible::before,
#level-complete.visible::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: confettiFall 1.5s ease-out forwards;
}

#level-complete.visible::before {
  background: #ffa726;
  top: 20%;
  left: 30%;
  animation-delay: 0.1s;
}

#level-complete.visible::after {
  background: #51e898;
  top: 15%;
  right: 25%;
  animation-delay: 0.3s;
}

@keyframes confettiFall {
  0%   { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateY(120px) rotate(360deg); }
}

/* ─── Responsive ─── */
@supports (height: 100dvh) {
  #game-container {
    height: 100dvh;
  }
}

@media (min-width: 501px) {
  #game-container {
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
  }
}
