/* hangmango — styles v=008 */

/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --cream:   #FFF8F0;
  --mango:   #FF8C2A;
  --mint:    #03B863;
  --red:     #b01904;
  --yellow:  #FFD166;
  --charcoal:#2D2D2D;
  --white:   #FFFFFF;
  --shadow:  0 4px 24px rgba(0,0,0,0.10);
  --radius:  18px;
  --font-head: 'Fredoka One', cursive;
  --font-body: 'Nunito', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--charcoal);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ── Setup Screen ───────────────────────────────────────────────────── */
#setup-screen {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 40px;
}

.setup-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setup-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.logo-mango { font-size: 2.8rem; font-family: "Apple Color Emoji","Segoe UI Emoji",sans-serif; }

.setup-logo h1 {
  font-family: var(--font-head);
  font-size: 2.6rem;
  color: var(--charcoal);
  line-height: 1;
}

.setup-logo h1 span { color: var(--mango); }

.tagline {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--red);
}

.setup-section { display: flex; flex-direction: column; gap: 10px; }

.setup-label {
  font-family: var(--font-head);
  font-size: 1rem;
  color: var(--charcoal);
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Category grid */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.cat-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 6px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--cream);
  color: var(--charcoal);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.cat-btn:hover { background: #fff0e0; border-color: var(--mango); }

.cat-btn.active {
  background: var(--mango);
  color: var(--white);
  border-color: var(--mango);
}

/* Difficulty row */
.diff-row { display: flex; gap: 8px; }

.diff-btn {
  flex: 1;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 10px 0;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  background: var(--white);
  color: var(--charcoal);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.diff-btn:hover { border-color: var(--mint); }

.diff-btn.active {
  background: var(--red);
  color: var(--white);
  border-color: var(--red);
}

/* Primary / Secondary buttons */
.btn-primary {
  font-family: var(--font-head);
  font-size: 1.2rem;
  padding: 14px 28px;
  background: var(--mango);
  color: var(--white);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 14px rgba(255,140,42,0.35);
  width: 100%;
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(255,140,42,0.45); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 10px 20px;
  background: transparent;
  color: var(--red);
  border: 2px solid var(--red);
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover { background: var(--red); color: var(--white); }

/* Custom word section */
.custom-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #aaa;
  font-size: 0.85rem;
  font-weight: 700;
}

.custom-divider::before,
.custom-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e8e8e8;
}

.custom-input-row {
  display: flex;
  gap: 8px;
}

#custom-word-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  background: var(--cream);
  color: var(--charcoal);
  outline: none;
  transition: border-color 0.15s;
}

#custom-word-input:focus { border-color: var(--mint); }

.error-text {
  font-size: 0.82rem;
  color: var(--mango);
  font-weight: 700;
  min-height: 18px;
}

/* ── Pass Screen ────────────────────────────────────────────────────── */
#pass-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.pass-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.pass-icon {
  font-size: 4rem;
  font-family: "Apple Color Emoji","Segoe UI Emoji",sans-serif;
}

.pass-card h2 {
  font-family: var(--font-head);
  font-size: 2rem;
  color: var(--red);
}

.pass-card p {
  font-size: 1rem;
  font-weight: 600;
  color: #666;
  line-height: 1.5;
}

/* ── Game Screen ────────────────────────────────────────────────────── */
#game-screen {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 40px;
}

.game-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 24px 28px;
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#game-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-menu {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.875rem;
  padding: 7px 16px;
  background: var(--mango);
  color: var(--white);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.btn-menu:hover { opacity: 0.85; }

#game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

/* ── Mango panel ───────────────────────────── */
#mango-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Lives strip */
#lives-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#life-slots {
  display: flex;
  gap: 6px;
}

.life-slot {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Apple Color Emoji","Segoe UI Emoji",sans-serif;
  font-size: 1.25rem;
  transition: background 0.2s;
}

.life-slot.used {
  background: #f0f0f0;
  opacity: 0.35;
}

/* pop-off animation fires on the just-lost slot */
.life-slot.just-lost {
  animation: lifeLost 0.45s cubic-bezier(0.55,0,1,0.45) forwards;
}

@keyframes lifeLost {
  0%   { transform: scale(1) translateY(0); opacity: 1; }
  30%  { transform: scale(1.3) translateY(-5px); opacity: 1; }
  100% { transform: scale(0.5) translateY(10px); opacity: 0.3; }
}

#lives-label {
  font-family: var(--font-head);
  font-size: 0.95rem;
  color: var(--mint);
  transition: color 0.4s;
  min-height: 20px;
}

#lives-label.warn-mid    { color: var(--yellow); }
#lives-label.warn-high   { color: var(--mango); }
#lives-label.warn-danger {
  color: #E53935;
  animation: labelPulse 0.65s ease infinite alternate;
}

@keyframes labelPulse {
  from { opacity: 1; }
  to   { opacity: 0.45; }
}

/* ── Mango Scene ──────────────────────────── */
#mango-scene {
  position: relative;
  width: 180px;
  height: 220px;
  user-select: none;
  border-radius: 16px;
  transition: filter 0.5s ease;
}

/* Progressive danger glow */
#mango-scene[data-state="3"] { filter: drop-shadow(0 0 5px rgba(255,213,0,0.45)); }
#mango-scene[data-state="4"] { filter: drop-shadow(0 0 9px rgba(255,140,42,0.55)); }
#mango-scene[data-state="5"] { animation: dangerFilter 0.7s ease infinite alternate; }
#mango-scene[data-state="6"] { filter: drop-shadow(0 0 14px rgba(229,57,53,0.5)); }

@keyframes dangerFilter {
  from { filter: drop-shadow(0 0 6px rgba(229,57,53,0.3)); }
  to   { filter: drop-shadow(0 0 16px rgba(229,57,53,0.75)); }
}

/* ── Tree ─────────────────────────────────── */
.tree-wrap {
  position: absolute;
  bottom: 14px;
  left: 30px; /* (180 - 120) / 2 */
  width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: bottom center;
}

.canopy {
  width: 120px;
  height: 90px;
  background: linear-gradient(150deg, #56C05A 0%, #237a2b 100%);
  border-radius: 55% 55% 45% 45% / 60% 60% 40% 40%;
  box-shadow: inset -10px -14px 22px rgba(0,0,0,0.15),
              inset 6px 8px 16px rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 12px;
}

.mango-in-tree {
  font-size: 2.4rem;
  line-height: 1;
  font-family: "Apple Color Emoji","Segoe UI Emoji",sans-serif;
  transition: opacity 0.15s ease;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}

.trunk {
  width: 22px;
  height: 68px;
  background: linear-gradient(180deg, #8B6340 0%, #6B4A2A 100%);
  border-radius: 4px 4px 2px 2px;
}

/* Hide canopy mango once it falls */
[data-state="6"] .mango-in-tree { opacity: 0; }

/* ── Tree wobble — JS adds class matching wrong count ── */
.tree-wrap.wobble-1 { animation: treeWobble1 0.55s ease; }
.tree-wrap.wobble-2 { animation: treeWobble2 0.60s ease; }
.tree-wrap.wobble-3 { animation: treeWobble3 0.65s ease; }
.tree-wrap.wobble-4 { animation: treeWobble4 0.70s ease; }
.tree-wrap.wobble-5 { animation: treeWobble5 0.75s ease; }

@keyframes treeWobble1 {
  0%,100% { transform: rotate(0deg); }
  20%  { transform: rotate(-3deg); }
  55%  { transform: rotate(2.5deg); }
  80%  { transform: rotate(-1deg); }
}
@keyframes treeWobble2 {
  0%,100% { transform: rotate(0deg); }
  20%  { transform: rotate(-5deg); }
  55%  { transform: rotate(4deg); }
  80%  { transform: rotate(-2deg); }
}
@keyframes treeWobble3 {
  0%,100% { transform: rotate(0deg); }
  20%  { transform: rotate(-8deg); }
  55%  { transform: rotate(6deg); }
  80%  { transform: rotate(-3deg); }
}
@keyframes treeWobble4 {
  0%,100% { transform: rotate(0deg); }
  20%  { transform: rotate(-11deg); }
  55%  { transform: rotate(8.5deg); }
  80%  { transform: rotate(-4deg); }
}
@keyframes treeWobble5 {
  0%,100% { transform: rotate(0deg); }
  20%  { transform: rotate(-15deg); }
  55%  { transform: rotate(12deg); }
  80%  { transform: rotate(-5deg); }
}

/* ── Falling mango (state 6) ──────────────── */
/* Hidden until state 6; positioned to match the mango-in-tree */
.mango-fruit {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.4rem;
  line-height: 1;
  font-family: "Apple Color Emoji","Segoe UI Emoji",sans-serif;
  opacity: 0;
  pointer-events: none;
}

[data-state="6"] .mango-fruit {
  animation: mangoFall 0.7s cubic-bezier(0.42,0,1,1) forwards;
}

@keyframes mangoFall {
  0%   { opacity: 1; top: 50px;  transform: translateX(-50%) rotate(0deg); }
  70%  { opacity: 1; top: 158px; transform: translateX(-50%) rotate(210deg); }
  82%  { top: 150px; transform: translateX(calc(-50% - 5px)) rotate(195deg) scaleY(0.55) scaleX(1.4); }
  100% { opacity: 0; top: 155px; transform: translateX(calc(-50% - 5px)) rotate(200deg); }
}

/* ── Ground ──────────────────────────────── */
.ground-line {
  position: absolute;
  bottom: 8px;
  left: 0; right: 0;
  height: 6px;
  background: linear-gradient(90deg, var(--mint), #02a357);
  border-radius: 3px;
}

/* ── Splat ───────────────────────────────── */
.splat-emoji {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 50%;
  font-size: 2.8rem;
  font-family: "Apple Color Emoji","Segoe UI Emoji",sans-serif;
}

[data-state="6"] .splat-emoji {
  display: block;
  animation: splatIn 0.4s cubic-bezier(0.34,1.56,0.64,1) 0.58s both;
}

@keyframes splatIn {
  0%   { transform: translateX(-50%) scale(0); opacity: 0; }
  60%  { transform: translateX(-50%) scale(1.3); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ── Word Panel ──────────────────────────────────────────────────────── */
#word-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

/* Category hint badge */
#category-hint {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--red);
  background: rgba(176,25,4,0.1);
  padding: 5px 14px;
  border-radius: 50px;
  white-space: nowrap;
}

/* Word display — letter tiles */
#word-display {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 0 8px;
}

.letter-tile {
  width: 36px;
  height: 42px;
  border-bottom: 3px solid var(--charcoal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  font-family: var(--font-head);
  font-size: 1.4rem;
  color: var(--charcoal);
  transition: color 0.2s, border-color 0.2s;
}

.letter-tile.revealed {
  color: var(--red);
  border-color: var(--red);
  animation: popIn 0.25s cubic-bezier(0.34,1.56,0.64,1);
}

.letter-tile.missed {
  color: var(--mango);
  border-color: var(--mango);
}

.word-space { width: 20px; }

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

/* ── Keyboard ────────────────────────────────────────────────────────── */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  width: 100%;
}

.kb-row {
  display: flex;
  gap: 4px;
  width: 100%;
  max-width: 380px;
}

.key {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.85rem;
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: var(--white);
  color: var(--charcoal);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.key:hover:not(:disabled) {
  background: var(--cream);
  border-color: var(--red);
  transform: translateY(-1px);
}

.key:active:not(:disabled) { transform: translateY(0); }

.key:disabled { cursor: default; }

.key.key-correct {
  background: var(--mint);
  border-color: var(--mint);
  color: var(--white);
}

.key.key-wrong {
  background: #eee;
  border-color: #ccc;
  color: #aaa;
}

/* ── Result Modal ────────────────────────────────────────────────────── */
#result-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 380px;
  overflow: hidden;
  animation: modalIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes modalIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#modal-header {
  padding: 24px 24px 20px;
  text-align: center;
}

#modal-header.won-header { background: linear-gradient(135deg, var(--mango), var(--yellow)); }
#modal-header.lost-header { background: linear-gradient(135deg, var(--red), #e04030); }

#modal-title {
  font-family: var(--font-head);
  font-size: 2rem;
  color: var(--white);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
}

#modal-word-reveal {
  font-family: var(--font-head);
  font-size: 1.1rem;
  color: var(--charcoal);
}

/* ── Confetti ────────────────────────────────────────────────────────── */
.confetti-piece {
  position: fixed;
  top: -20px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  pointer-events: none;
  z-index: 200;
}

@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ── Footer ─────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 20px 16px;
  font-size: 0.82rem;
  color: #999;
}

footer a { color: #999; text-decoration: none; }
footer a:hover { color: var(--red); }

/* ── How to Play (SEO) ───────────────────────────────────────────────── */
#how-to-play {
  padding: 0 16px 32px;
  max-width: 680px;
  margin: 0 auto;
  opacity: 0.35;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--charcoal);
}

#how-to-play h2 { font-size: 0.85rem; margin-bottom: 6px; font-family: var(--font-head); }
#how-to-play h3 { font-size: 0.78rem; margin: 10px 0 4px; font-weight: 700; }

/* ── Desktop: slightly larger keys on wide screens ───────────────────── */
@media (min-width: 560px) {
  .game-card {
    max-width: 480px;
  }

  .kb-row {
    max-width: 420px;
  }

  .key {
    height: 44px;
    font-size: 0.9rem;
  }
}
