/* Wordhaven — bright, chunky, kid-friendly. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  /* Opt out of browser forced/auto dark mode — the game is a deliberately light design,
     and auto-darkening turns the skin tones and sky into muddy browns. */
  color-scheme: only light;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', 'Arial Rounded MT Bold', -apple-system, sans-serif;
  background: linear-gradient(#8fd8ff 0%, #bfe9ff 55%, #d8f4ff 100%);
  color: #234;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; border: none; cursor: pointer; color: inherit; }
input {
  font-family: inherit;
  font-size: 18px;
  padding: 10px 12px;
  border: 3px solid #bcd8ea;
  border-radius: 14px;
  outline: none;
  width: 100%;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  overflow: hidden;
}

/* ---------- Coins ---------- */
.coin-pill {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 16px;
  z-index: 50;
  background: #fff;
  border: 3px solid #ffd75e;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 4px 0 #e0b840;
}
.coin-pill.pop { animation: pop 0.4s; }
.coin-pill.shake { animation: shake 0.5s; }

/* ---------- Welcome ---------- */
.welcome { justify-content: center; gap: 14px; }
.logo {
  font-size: clamp(44px, 9vw, 84px);
  font-weight: 700;
  margin: 0;
  color: #fff;
  text-shadow: 0 4px 0 #4da3d8, 0 8px 18px rgba(0, 60, 120, 0.25);
  letter-spacing: 1px;
  animation: floaty 3s ease-in-out infinite;
}
.tagline { font-size: clamp(18px, 3vw, 26px); margin: 0; color: #2b6a99; font-weight: 600; }

.sun {
  position: absolute; top: 6%; left: 7%;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff4b8, #ffd75e);
  box-shadow: 0 0 60px 22px rgba(255, 215, 94, 0.55);
}
.cloud {
  position: absolute;
  background: #fff; border-radius: 999px; opacity: 0.9;
  animation: drift 40s linear infinite;
}
.cloud::before, .cloud::after {
  content: ''; position: absolute; background: #fff; border-radius: 50%;
}
.c1 { width: 130px; height: 44px; top: 10%; left: 60%; }
.c1::before { width: 60px; height: 60px; top: -26px; left: 20px; }
.c1::after { width: 44px; height: 44px; top: -18px; left: 66px; }
.c2 { width: 100px; height: 36px; top: 24%; left: 15%; animation-delay: -18s; }
.c2::before { width: 48px; height: 48px; top: -22px; left: 16px; }
.c2::after { width: 34px; height: 34px; top: -14px; left: 52px; }
.c3 { width: 150px; height: 48px; top: 5%; left: 30%; animation-delay: -30s; }
.c3::before { width: 66px; height: 66px; top: -30px; left: 26px; }
.c3::after { width: 48px; height: 48px; top: -20px; left: 80px; }

.avatar-box { width: clamp(150px, 22vh, 240px); }
.avatar-box svg { width: 100%; height: auto; display: block; }

.btn-big {
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 700;
  padding: 16px 44px;
  border-radius: 999px;
  background: linear-gradient(#6ecb63, #4aad3f);
  color: #fff;
  box-shadow: 0 6px 0 #35812c, 0 10px 18px rgba(0, 60, 0, 0.25);
  transition: transform 0.1s;
}
.btn-big:active { transform: translateY(4px); box-shadow: 0 2px 0 #35812c; }
.btn-big.alt { background: linear-gradient(#66b8f2, #3f92d6); box-shadow: 0 6px 0 #2c6da3; font-size: clamp(18px, 3vw, 24px); padding: 12px 28px; }
.btn-big.alt:active { box-shadow: 0 2px 0 #2c6da3; }

/* ---------- Top bar ---------- */
.topbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding-right: 112px; /* keep clear of the fixed coin pill */
}
.btn-icon {
  font-size: 30px;
  width: 58px; height: 58px;
  flex: 0 0 58px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 0 #c9dfee;
  display: flex; align-items: center; justify-content: center;
}
.btn-icon:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9dfee; }
.btn-icon.spacer { visibility: hidden; }
.hello { font-size: clamp(20px, 3.4vw, 30px); font-weight: 700; color: #1d5c8f; flex: 1; }
.game-title { font-size: clamp(20px, 3.4vw, 30px); font-weight: 700; color: #1d5c8f; flex: 1; text-align: center; }
.avatar-mini { width: 52px; }
.avatar-mini svg { width: 100%; height: auto; display: block; }

/* ---------- Town ---------- */
.town {
  flex: 1;
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(12px, 2.5vw, 24px);
  align-content: center;
  padding: 8px 0 70px;
  z-index: 2;
}
@media (orientation: landscape) and (min-width: 700px) {
  .town { grid-template-columns: repeat(4, 1fr); }
}
.building {
  position: relative;
  background: #fff;
  border-radius: 22px;
  padding: clamp(26px, 4vh, 44px) 10px clamp(16px, 2.5vh, 26px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 0 rgba(80, 120, 150, 0.25), 0 12px 20px rgba(30, 80, 120, 0.15);
  transition: transform 0.12s;
  overflow: visible;
  margin-top: 18px;
}
.building:active { transform: scale(0.96); }
.roof {
  position: absolute;
  top: -16px; left: 50%;
  transform: translateX(-50%);
  width: 86%; height: 26px;
  border-radius: 12px 12px 4px 4px;
}
.roof-red { background: #e94f4f; box-shadow: 0 3px 0 #b83a3a; }
.roof-blue { background: #4f7fe9; box-shadow: 0 3px 0 #3a5fb8; }
.roof-purple { background: #9b6dd6; box-shadow: 0 3px 0 #7a4fb0; }
.roof-pink { background: #f47fb8; box-shadow: 0 3px 0 #d15f96; }
.b-emoji { font-size: clamp(40px, 7vh, 64px); line-height: 1; }
.b-name { font-size: clamp(17px, 2.6vw, 24px); font-weight: 700; color: #2b5876; }

.grass {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  background: linear-gradient(#79d06a, #58b54a);
  border-radius: 100% 100% 0 0 / 40px 40px 0 0;
  z-index: 1;
}

/* ---------- Game stage ---------- */
.dots { display: flex; gap: 8px; padding: 6px 0 2px; }
.dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #cde7f5; border: 2px solid #a9cfe4;
}
.dot.done { background: #ffd75e; border-color: #e0b840; }
.dot.now { background: #fff; border-color: #4f9fd6; transform: scale(1.25); }

#game-stage {
  flex: 1;
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3.5vh, 36px);
}

.prompt-row { display: flex; align-items: center; gap: 18px; }
.hint-emoji {
  font-size: clamp(56px, 11vh, 96px);
  background: #fff;
  border-radius: 26px;
  padding: 10px 18px;
  box-shadow: 0 5px 0 #c9dfee;
  line-height: 1.15;
}
.hint-emoji:active { transform: scale(0.94); }
.prompt-text {
  font-size: clamp(20px, 3.2vw, 30px);
  font-weight: 600;
  color: #1d5c8f;
  max-width: 320px;
}

.choice-row {
  display: flex;
  gap: clamp(12px, 2.5vw, 26px);
  flex-wrap: nowrap;
  justify-content: center;
}
.choice-row.wrap { flex-wrap: wrap; max-width: 700px; }

.tile {
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 6px 0 #c9dfee, 0 10px 16px rgba(30, 80, 120, 0.12);
  font-weight: 700;
  color: #234;
  transition: transform 0.1s;
}
.tile:active { transform: translateY(3px); }
.letter-tile {
  font-size: clamp(52px, 10vh, 88px);
  width: clamp(96px, 17vh, 150px);
  height: clamp(96px, 17vh, 150px);
}
.letter-tile.small {
  font-size: clamp(34px, 6.5vh, 56px);
  width: clamp(64px, 11vh, 96px);
  height: clamp(64px, 11vh, 96px);
}
.word-tile {
  font-size: clamp(30px, 5.5vh, 52px);
  padding: clamp(14px, 3vh, 26px) clamp(22px, 4vw, 44px);
}
.tile.right { background: #d8f5cf; box-shadow: 0 6px 0 #7fc46f; animation: pop 0.45s; }
.tile.dim { opacity: 0.45; }
.tile.used { opacity: 0.25; pointer-events: none; }
.tile.shake { animation: shake 0.5s; }

.slot-row { display: flex; gap: 14px; }
.slot {
  width: clamp(70px, 12vh, 110px);
  height: clamp(70px, 12vh, 110px);
  border-radius: 20px;
  border: 4px dashed #8fc3e2;
  background: rgba(255, 255, 255, 0.55);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(44px, 8vh, 72px);
  font-weight: 700;
  color: #234;
}
.slot.filled { border-style: solid; border-color: #7fc46f; background: #eafbe3; animation: pop 0.35s; }

/* ---------- Session end ---------- */
.session-end { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.big-stars { font-size: clamp(54px, 10vh, 90px); animation: pop 0.6s; }
.end-line { font-size: clamp(20px, 3.4vw, 30px); font-weight: 600; color: #1d5c8f; }
.end-bonus { font-size: clamp(24px, 4vw, 36px); font-weight: 700; color: #c98a12; }
.end-levelup { font-size: clamp(20px, 3.4vw, 28px); font-weight: 700; color: #7a4fb0; }
.end-btns { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

/* ---------- Boutique ---------- */
.shop-layout {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  display: flex;
  gap: 16px;
  min-height: 0;
  padding-bottom: 6px;
}
.shop-left { flex: 0 0 34%; display: flex; align-items: center; justify-content: center; }
.shop-preview {
  width: 100%;
  max-width: 260px;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 26px;
  padding: 14px;
  box-shadow: 0 5px 0 #c9dfee;
}
.shop-right { flex: 1; display: flex; flex-direction: column; min-height: 0; gap: 10px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; flex: 0 0 auto; -webkit-overflow-scrolling: touch; }
.tab {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center;
  font-size: 24px;
  background: #fff;
  border-radius: 16px;
  padding: 8px 14px;
  box-shadow: 0 3px 0 #c9dfee;
  opacity: 0.75;
}
.tab span { font-size: 13px; font-weight: 600; }
.tab.active { opacity: 1; background: #ffe9a8; box-shadow: 0 3px 0 #e0b840; }
.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 12px;
  align-content: start;
  padding: 2px 2px 12px;
  -webkit-overflow-scrolling: touch;
}
.shop-card {
  background: #fff;
  border-radius: 18px;
  padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: 0 4px 0 #c9dfee;
  border: 3px solid transparent;
}
.shop-card:active { transform: scale(0.95); }
.shop-card.equipped { border-color: #6ecb63; background: #f0fbe9; }
.card-preview { width: 84px; height: 74px; }
.card-preview svg { width: 100%; height: 100%; }
.card-name { font-size: 15px; font-weight: 700; color: #2b5876; text-align: center; }
.card-price { font-size: 14px; font-weight: 600; color: #c98a12; }
.shop-card.equipped .card-price { color: #4aad3f; }

.grid-label { grid-column: 1 / -1; font-size: 18px; font-weight: 700; color: #1d5c8f; margin-top: 4px; }
.swatch-row { grid-column: 1 / -1; display: flex; gap: 12px; flex-wrap: wrap; }
.swatch {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 3px 0 rgba(80, 120, 150, 0.35);
}
.swatch.active { border-color: #ffd75e; transform: scale(1.12); }

@media (orientation: portrait) {
  .shop-layout { flex-direction: column; }
  .shop-left { flex: 0 0 auto; }
  .shop-preview { max-width: 170px; }
}

/* ---------- Settings overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 50, 80, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.panel {
  background: #fff;
  border-radius: 24px;
  padding: 22px;
  width: min(420px, 100%);
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 30, 60, 0.35);
}
.panel h2 { margin: 0; color: #1d5c8f; }
.panel label { font-weight: 600; display: flex; flex-direction: column; gap: 6px; font-size: 16px; }
.set-row { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.set-row.spread { justify-content: space-between; margin-top: 6px; }
.set-hint { margin: 0; font-size: 14px; color: #567; }
.btn-small {
  font-size: 17px; font-weight: 700;
  padding: 10px 18px;
  border-radius: 14px;
  background: #e8f1f8;
  box-shadow: 0 3px 0 #c9dfee;
}
.btn-small.primary { background: #6ecb63; color: #fff; box-shadow: 0 3px 0 #35812c; }
.btn-small.danger { background: #fde5e5; color: #b83a3a; box-shadow: 0 3px 0 #e0b0b0; }

/* ---------- Confetti ---------- */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.confetti {
  position: absolute;
  top: -14px;
  width: 12px; height: 12px;
  border-radius: 3px;
  animation: fall var(--dur, 1.2s) ease-in forwards;
}
@keyframes fall {
  to { transform: translate(var(--dx, 0), 105vh) rotate(var(--rot, 360deg)); opacity: 0.9; }
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-9px); }
  40%, 80% { transform: translateX(9px); }
}
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(-60vw); }
}
