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

:root {
  --purple: #6c3fc5;
  --purple-light: #f5f0ff;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --radius-lg: 20px;
  --shadow: 0 4px 16px rgba(0,0,0,.10);
}

html { font-size: 16px; }
body {
  font-family: 'Fredoka One', cursive;
  background: linear-gradient(160deg, #f0f9ff, #fdf4ff);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Floating Background Words ── */
#bgWords {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}
.floating-word {
  position: absolute;
  color: var(--purple);
  opacity: 0.08;
  font-size: clamp(1rem, 4vw, 1.5rem);
  white-space: nowrap;
  animation: floatBG 25s linear infinite;
  user-select: none;
}
@keyframes floatBG {
  from { transform: translate(0, 0) rotate(0deg); }
  to   { transform: translate(100vw, -100vh) rotate(360deg); }
}

/* Lower opacity during game for concentration */
.game-active .floating-word {
  opacity: 0.02;
  transition: opacity 1s ease;
}
.floating-word {
  transition: opacity 1s ease;
}

/* ── Language Bar ── */
#langBar {
  position: fixed;
  top: 10px; right: 10px;
  z-index: 500;
  display: flex;
  gap: 6px;
}
.lang-btn {
  border: 2px solid #ddd;
  background: #fff;
  border-radius: 8px;
  font-size: .9rem;
  cursor: pointer;
  padding: 4px 8px;
  transition: border .15s, background .15s;
  min-height: 34px;
}
.lang-btn.active { border-color: var(--purple); background: var(--purple-light); }

/* ── Screens ── */
.screen {
  display: none;
  min-height: 100vh;
  padding: 60px 16px 24px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
}
.screen.active { display: flex; }

h1 {
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  color: var(--purple);
  text-align: center;
  margin-bottom: 6px;
  text-shadow: 1px 2px 0 #e0cfff;
}
.subtitle {
  color: #888;
  font-size: clamp(.85rem, 3vw, 1rem);
  margin-bottom: 20px;
  text-align: center;
}

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: 14px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1rem, 3.5vw, 1.15rem);
  cursor: pointer;
  padding: 12px 24px;
  min-height: 48px;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 12px rgba(0,0,0,.13);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.btn:hover  { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-purple  { background: var(--purple); color: #fff; }
.btn-green   { background: var(--green);  color: #fff; }
.btn-red     { background: var(--red);    color: #fff; }
.btn-gray    { background: #e5e7eb; color: #555; box-shadow: none; }
.btn-outline { background: #fff; color: var(--purple); border: 2px solid var(--purple); box-shadow: none; }
.btn-sm      { padding: 8px 14px; font-size: .88rem; min-height: 38px; border-radius: 10px; }

/* ── HOW TO PLAY ── */
/* ── SVG Snail ── */
.snail-wrap {
  margin-bottom: 4px;
  animation: snailFloat 3.5s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15));
}
.snail-svg {
  width: clamp(100px, 28vw, 150px);
  height: auto;
  display: block;
  margin: 0 auto;
}
/* Eye-blink animation on the snail */
@keyframes snailFloat {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50%       { transform: translateY(-10px) rotate(1deg); }
}

.steps-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
  width: 100%;
  max-width: 480px;
}
.step-card {
  background: #fff;
  border-radius: 16px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.step-num {
  display: inline-block;
  background: var(--purple);
  color: #fff;
  border-radius: 50%;
  width: 24px; height: 24px;
  line-height: 24px;
  font-size: .8rem;
  margin-bottom: 6px;
}
.step-icon {
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  color: var(--purple);
  margin-bottom: 6px;
  display: block;
}
.step-card p { font-size: clamp(.75rem, 2.5vw, .88rem); color: #444; line-height: 1.35; }

/* ── Back Button ── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-family: 'Fredoka One', cursive;
  font-size: .9rem;
  color: #777;
  cursor: pointer;
  padding: 6px 14px;
  margin-bottom: 14px;
  transition: border .2s, color .2s;
}
.btn-back:hover { border-color: var(--purple); color: var(--purple); }
.game-back {
  position: absolute;
  top: -40px;
  left: 0;
  margin-bottom: 0;
}
#boardWrap { position: relative; padding-top: 44px; }

/* Add/Remove player row */
.add-remove-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.add-remove-row .btn { flex: 1; font-size: .9rem; min-height: 42px; padding: 8px 10px; }

/* ── SETUP ── */
#setup { background: transparent; }
.setup-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 460px;
}
.setup-label { font-size: .95rem; color: #777; margin-bottom: 8px; }
.count-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.count-btn {
  border: 3px solid #ddd;
  background: #fff;
  border-radius: 10px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  padding: 7px 16px;
  cursor: pointer;
  transition: all .15s;
  min-height: 44px;
}
.count-btn.sel { border-color: var(--purple); background: var(--purple-light); color: var(--purple); }

.names-grid { display: grid; gap: 10px; margin-bottom: 16px; }
.player-row {
  background: #f9fafb;
  border-radius: 12px;
  padding: 10px;
  border: 2px solid #eee;
}
.player-row-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.player-row-top input {
  flex: 1;
  border: 2px solid #eee;
  border-radius: 10px;
  font-family: 'Fredoka One', cursive;
  font-size: .95rem;
  padding: 8px 12px;
  outline: none;
  transition: border .2s;
  min-height: 44px;
}
.player-row-top input:focus { border-color: var(--purple); }
.pion-selector { display: flex; gap: 6px; flex-wrap: wrap; }
.pion-opt {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.pion-opt:hover   { transform: scale(1.12); border-color: #aaa; }
.pion-opt.selected {
  border-color: var(--purple);
  background: var(--purple-light);
  transform: scale(1.18);
  box-shadow: 0 0 0 2px var(--purple);
}
.pion-opt.taken {
  opacity: 0.25;
  cursor: not-allowed;
  transform: none !important;
  border-color: #eee !important;
  box-shadow: none !important;
  filter: grayscale(80%);
}
.pion-opt i { pointer-events: none; }

/* ── GAME LAYOUT ── */
#game {
  background: transparent;
  padding: 56px 10px 16px;
  justify-content: flex-start;
}
.game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 960px;
}
@media (min-width: 700px) {
  .game-wrap {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
  }
}

/* ── BOARD ── */
#boardWrap {
  width: 100%;
  max-width: 420px;
  flex-shrink: 0;
}
#board {
  position: relative;
  width: 100%;
  padding-top: 100%;
}
#boardInner { position: absolute; inset: 0; }

.cell {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  transition: transform .25s, box-shadow .25s;
  user-select: none;
}
.cell.hl {
  transform: scale(1.22);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--purple);
  z-index: 5;
}
.cell-treasure { font-size: 1rem; }

/* Pions */
.pion {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 10;
  transition: left .55s cubic-bezier(.4,0,.2,1), top .55s cubic-bezier(.4,0,.2,1);
}
.pion-icon { font-size: 1rem; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.pion-name {
  font-size: .42rem;
  background: rgba(255,255,255,.92);
  border-radius: 5px;
  padding: 1px 4px;
  margin-top: 1px;
  white-space: nowrap;
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #333;
}

/* ── GAME PANEL ── */
.game-panel {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 320px;
  flex-shrink: 0;
}
.cur-player-label {
  font-size: clamp(1rem, 3.5vw, 1.2rem);
  color: var(--purple);
  text-align: center;
  margin-bottom: 12px;
  padding: 8px;
  background: var(--purple-light);
  border-radius: 10px;
  line-height: 1.3;
}
.dice-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.dice-display {
  width: 68px; height: 68px;
  background: var(--purple-light);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(108,63,197,.2);
  cursor: pointer;
  transition: transform .12s;
}
.dice-display:hover  { transform: scale(1.06); }
.dice-display:active { transform: scale(0.94); }
#diceIcon { color: var(--purple); }
#diceIcon.rolling { animation: spinDice .09s linear infinite; }
@keyframes spinDice {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(180deg) scale(1.15); }
  100% { transform: rotate(360deg) scale(1); }
}
.dice-result {
  font-size: .88rem;
  color: #666;
  text-align: center;
  min-height: 20px;
  line-height: 1.3;
}

/* Challenge box */
#challengeBox {
  display: none;
  background: var(--purple-light);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  text-align: center;
  border: 2px solid #d8c4f8;
}
.challenge-heading {
  font-size: clamp(.85rem, 3vw, 1rem);
  color: #444;
  margin-bottom: 8px;
  line-height: 1.3;
}
.color-badge {
  display: inline-block;
  padding: 6px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: clamp(.95rem, 3.5vw, 1.05rem);
  margin-bottom: 8px;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  font-weight: 700;
}
.timer-label { font-size: .85rem; color: #555; margin-bottom: 5px; }
.timer-label span:first-of-type { font-size: 1.1rem; color: var(--purple); font-weight: 700; }
.timer-wrap {
  height: 16px;
  background: #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}
#timerBar { height: 100%; width: 100%; background: var(--green); transition: background .4s; }
.ch-btns { display: flex; gap: 8px; }

/* Suggestions box */
#suggestionsBox {
  display: none;
  background: #fffbeb;
  border: 2px solid #fde68a;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  text-align: center;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }
.suggest-title {
  font-size: .92rem;
  color: #92400e;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.suggest-title i { color: #f59e0b; }
.suggest-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.suggest-tag {
  background: #fff;
  border: 2px solid #fde68a;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .82rem;
  color: #78350f;
  transition: background .15s;
}
.suggest-tag:hover { background: #fef3c7; }

/* Confirm modal */
#confirmModal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#confirmModal.show { display: flex; }
.modal-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
  animation: popIn .3s ease;
}
.modal-text { font-size: 1.05rem; color: #444; margin-bottom: 16px; line-height: 1.4; }
.modal-btns { display: flex; gap: 10px; justify-content: center; }

/* Players bar */
.players-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pbadge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #f9fafb;
  border: 2px solid #eee;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: .78rem;
  transition: border .2s;
}
.pbadge.active { border-color: var(--purple); background: var(--purple-light); }

/* ── WIN ── */
#winScreen {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.68);
  z-index: 300;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 16px;
}
#winScreen.show { display: flex; }
.win-card {
  background: #fff;
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  animation: popIn .5s cubic-bezier(.34,1.56,.64,1);
  max-width: 400px;
  width: 100%;
}
@keyframes popIn { from{transform:scale(0) rotate(-4deg)} to{transform:scale(1) rotate(0)} }
.win-trophy { font-size: 3rem; color: #f59e0b; margin-bottom: 8px; }
.win-trophy i { animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from{transform:scale(1)} to{transform:scale(1.1)} }
.win-title { font-size: clamp(1.4rem, 5vw, 1.8rem); color: var(--purple); margin-bottom: 6px; }
.win-subtitle { font-size: .95rem; color: #555; }
.loser-gage {
  background: #fef3c7;
  border-radius: 10px;
  padding: 10px;
  font-size: .88rem;
  color: #92400e;
  line-height: 1.5;
  margin-top: 10px;
}

/* Confetti */
#confettiCanvas { position: fixed; inset: 0; pointer-events: none; z-index: 299; }
