/* Scripture Hangman — shared-screen layout, readable from across a room. */

:root {
  --bg1: #f6f2ea;
  --bg2: #e8e0d0;
  --accent: #b08a4f;
  --ink: #3f3628;
  --paper: #fffdf7;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  /* Soft watercolor backdrop under a translucent palette gradient (keeps UI readable).
     Falls back to the plain gradient when --bg-image is unset. */
  background:
    linear-gradient(170deg,
      color-mix(in srgb, var(--bg1) 42%, transparent) 0%,
      color-mix(in srgb, var(--bg2) 48%, transparent) 100%),
    var(--bg-image, linear-gradient(170deg, var(--bg1) 0%, var(--bg2) 100%)) center / cover fixed;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background 600ms ease;
  overflow-x: hidden;
}

/* ---------- Top bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
}

.badge {
  background: var(--accent);
  color: var(--paper);
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

#tracker {
  display: flex;
  gap: 0.3rem;
  font-size: 1.3rem;
  user-select: none;
}

#tracker .star { opacity: 0.28; transition: opacity 300ms, transform 300ms; }
#tracker .star.won { opacity: 1; }
#tracker .star.lit-now { animation: starPop 700ms ease; }
#tracker .star.lost { opacity: 0.45; filter: grayscale(1); }
#tracker .star.current { opacity: 0.6; transform: scale(1.2); }

@keyframes starPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.8) rotate(18deg); }
  100% { transform: scale(1); }
}

#sound-btn {
  font-size: 1.4rem;
  background: var(--paper);
  border: 2px solid var(--accent);
  border-radius: 999px;
  width: 2.6rem;
  height: 2.6rem;
  cursor: pointer;
  line-height: 1;
  transition: transform 150ms;
}
#sound-btn:hover { transform: scale(1.1); }

/* ---------- Layout ---------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  gap: 0.6rem;
  padding: 0 1rem 1rem;
}

/* ---------- Scene ---------- */

#scene-card {
  background: var(--paper);
  border-radius: 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  padding: 0.6rem 0.6rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#scene {
  width: min(58vw, 52vh, 560px);
  height: auto;
  aspect-ratio: 4 / 3;
  display: block;
}

/* Newly drawn stage: fades and grows in; stroked paths sweep in. */
.stage-enter { animation: stageIn 700ms ease-out backwards; transform-origin: center; }
@keyframes stageIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}
.stage-enter .sk {
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: sketch 900ms ease-out forwards;
}
@keyframes sketch { to { stroke-dashoffset: 0; } }

.scene-win { animation: happyBounce 900ms ease; transform-origin: center bottom; }
@keyframes happyBounce {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.04) translateY(-6px); }
  60% { transform: scale(0.99) translateY(0); }
}

#wrong-dots { display: flex; gap: 0.45rem; padding: 0.35rem 0 0.2rem; }
#wrong-dots .dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  transition: background 250ms;
}
#wrong-dots .dot.used { background: var(--accent); animation: dotPulse 450ms ease; }
@keyframes dotPulse { 40% { transform: scale(1.6); } }

/* ---------- Blanks ---------- */

#blanks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.4rem;
  max-width: 94vw;
}

.word { display: flex; gap: 0.35rem; }

.tile {
  width: clamp(1.6rem, 3.4vw, 2.6rem);
  height: clamp(2.1rem, 4.4vw, 3.4rem);
  border-bottom: 4px solid var(--accent);
  border-radius: 4px 4px 0 0;
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.3rem, 2.8vw, 2.2rem);
  font-weight: bold;
  color: transparent;
}

.tile.hit { color: var(--ink); animation: tilePop 450ms ease; }
@keyframes tilePop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.tile.reveal-miss { color: var(--accent); animation: tileFade 800ms ease; }
@keyframes tileFade { from { color: transparent; } }

/* ---------- Keyboard ---------- */

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
}

.kb-row { display: flex; gap: 0.4rem; }

.key {
  width: clamp(2.2rem, 4.6vw, 3.4rem);
  height: clamp(2.2rem, 4.6vw, 3.2rem);
  font-size: clamp(1.05rem, 2vw, 1.5rem);
  font-family: inherit;
  font-weight: bold;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid color-mix(in srgb, var(--accent) 55%, var(--paper));
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 45%, var(--paper));
  transition: transform 120ms, opacity 300ms;
}
.key:hover:not(:disabled) { transform: translateY(-2px); }
.key:disabled { cursor: default; opacity: 0.35; box-shadow: none; }
.key.good { background: color-mix(in srgb, var(--accent) 30%, var(--paper)); }
.key.bad { animation: keyShake 400ms ease; }
@keyframes keyShake {
  20% { transform: translateX(-4px) rotate(-4deg); }
  50% { transform: translateX(4px) rotate(4deg); }
  80% { transform: translateX(-2px); }
}

/* ---------- Banner (win / kind loss / session end) ---------- */

#banner {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 18, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
#banner.hidden { display: none; }

#banner-card {
  background: var(--paper);
  border-radius: 22px;
  padding: 1.6rem 2.4rem;
  max-width: min(88vw, 34rem);
  text-align: center;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.3);
  animation: cardIn 450ms ease backwards;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

#banner-emoji { font-size: 2.6rem; }
#banner-title { margin: 0.3rem 0 0.6rem; font-size: 1.7rem; }
#banner-answer { font-size: 1.5rem; letter-spacing: 0.12em; font-weight: bold; margin: 0.2rem 0; }
#banner-ref { font-style: italic; opacity: 0.85; margin: 0.2rem 0 1rem; }

#next-btn {
  font-family: inherit;
  font-size: 1.2rem;
  background: var(--accent);
  color: var(--paper);
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.8rem;
  cursor: pointer;
  transition: transform 150ms;
}
#next-btn:hover { transform: scale(1.06); }

/* ---------- Catalog chooser ---------- */

.badge-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: transform 150ms;
}
.badge-btn:hover { transform: scale(1.05); }

#chooser {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 18, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
#chooser.hidden { display: none; }

#chooser-card {
  background: var(--paper);
  border-radius: 22px;
  padding: 1.6rem 2.2rem 2rem;
  text-align: center;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.3);
  animation: cardIn 450ms ease backwards;
}
#chooser-card h2 { margin: 0 0 1.1rem; }

.catalog-btn {
  display: block;
  width: min(80vw, 22rem);
  margin: 0.6rem auto;
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: bold;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 14%, var(--paper));
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: transform 150ms, background 150ms;
}
.catalog-btn:hover { transform: scale(1.04); background: color-mix(in srgb, var(--accent) 26%, var(--paper)); }
.catalog-btn span { display: block; font-size: 0.85rem; font-weight: normal; opacity: 0.75; margin-top: 0.2rem; }

/* Teen loss: keep the finished scene visible above a low banner card. */
#banner.low {
  align-items: flex-end;
  background: rgba(40, 32, 18, 0.12);
  padding-bottom: 4vh;
}

/* ---------- Confetti ---------- */

#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 15;
}

.confetti {
  position: absolute;
  top: -3vh;
  width: 0.55rem;
  height: 0.9rem;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(108vh) rotate(720deg); opacity: 0.7; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .tile.hit { color: var(--ink); }
  .confetti { display: none; }
}
