/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1729;
  --bg-light: #1a2340;
  --gold: #EF9F27;
  --gold-dim: rgba(239,159,39,0.25);
  --teal: #1D9E75;
  --red: #E24B4A;
  --text: #f0f0f0;
  --text-sec: rgba(255,255,255,0.6);
  --text-ter: rgba(255,255,255,0.35);
  --card-bg: rgba(255,255,255,0.08);
  --card-border: rgba(255,255,255,0.15);
  --radius: 10px;
  --radius-sm: 6px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font-family: inherit; border: none; background: none; color: inherit; touch-action: manipulation; }
input { font-family: inherit; }
a { color: var(--text-sec); text-decoration: none; }
a:hover { color: var(--text); }

/* ===== SCREENS ===== */
#app { position: relative; min-height: 100dvh; }
.screen { display: none; flex-direction: column; min-height: 100dvh; overflow-y: auto; }
.screen.active { display: flex; }

/* ===== START SCREEN ===== */
.start-content {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1.5rem; text-align: center;
}
.title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(3rem, 10vw, 4.5rem);
  color: var(--gold);
  letter-spacing: 0.04em;
  line-height: 1.1;
  margin-bottom: 0.5rem;
}
.subtitle { color: var(--text-sec); font-size: 1.05rem; margin-bottom: 1.5rem; }
.puzzle-number { color: var(--text-ter); font-size: 0.9rem; margin-bottom: 0.25rem; }
.streak-info { color: var(--gold); font-size: 1rem; margin-bottom: 0.15rem; min-height: 1.4em; }
.stats-info { color: var(--text-ter); font-size: 0.85rem; margin-bottom: 2rem; min-height: 1.2em; }

.btn-play {
  background: var(--gold);
  color: #1a1400;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  padding: 1rem 3.5rem;
  border-radius: 50px;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 20px rgba(239,159,39,0.35);
}
.btn-play:hover { transform: scale(1.04); box-shadow: 0 6px 28px rgba(239,159,39,0.5); }
.btn-play:active { transform: scale(0.97); }

.btn-how {
  margin-top: 1.25rem;
  color: var(--text-sec);
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.start-footer {
  padding: 1.25rem; text-align: center; display: flex;
  flex-direction: column; gap: 0.35rem;
}
.start-footer a { font-size: 0.78rem; color: var(--text-ter); }

/* ===== GAME SCREEN ===== */
.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem 0.5rem;
}
.btn-back {
  width: 36px; height: 36px; font-size: 1.2rem;
  border-radius: 50%; background: var(--card-bg);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.btn-back:hover { background: rgba(255,255,255,0.15); }
.topbar-center { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; }
.topbar-spacer { width: 36px; }
.word-counter { font-size: 0.95rem; font-weight: 600; }
.category-pill {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em;
  background: var(--card-bg); border: 1px solid var(--card-border);
  padding: 0.2rem 0.75rem; border-radius: 50px; color: var(--text-sec);
}

.progress-dots {
  display: flex; justify-content: center; gap: 0.6rem;
  padding: 0.4rem 0 0.75rem;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--text-ter);
  background: transparent; transition: all 0.3s;
}
.dot.current { border-color: var(--gold); animation: dotpulse 1.5s infinite; }
.dot.solved { background: var(--teal); border-color: var(--teal); animation: dotPop 0.3s ease-out; }
.dot.failed { background: var(--red); border-color: var(--red); animation: dotPop 0.3s ease-out; }

@keyframes dotPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

@keyframes dotpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,159,39,0.4); }
  50% { box-shadow: 0 0 0 4px rgba(239,159,39,0); }
}

.game-body {
  flex: 1; display: flex; flex-direction: column;
  justify-content: space-between; padding: 0 1rem 1rem;
  max-width: 540px; margin: 0 auto; width: 100%;
  gap: 0.75rem;
}

/* Word transition animation */
.word-area.fade-enter {
  animation: wordFadeIn 0.25s ease-out;
}
@keyframes wordFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Word Area */
.word-area { display: flex; flex-direction: column; align-items: center; }

.letter-blanks {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 6px; margin-bottom: 1.25rem; min-height: 52px;
}
.letter-tile {
  width: 44px; height: 44px; border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; font-weight: 700; text-transform: uppercase;
  background: transparent; transition: all 0.3s;
}
.letter-tile.revealed {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.35);
  animation: letterReveal 0.35s ease-out;
}
.letter-tile.solved { border-color: var(--teal); background: rgba(29,158,117,0.15); }

@keyframes letterReveal {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* Clue Area */
.clue-area {
  width: 100%; min-height: 2rem; margin-bottom: 1rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.clue-item {
  display: flex; align-items: center; gap: 0.5rem;
  animation: clueSlideIn 0.25s ease-out;
}
.clue-item.previous { opacity: 0.5; font-size: 0.85rem; }
.clue-item .clue-flag { font-size: 1.3rem; }
.clue-item.previous .clue-flag { font-size: 1rem; }
.clue-item .clue-word { font-size: 1.35rem; font-weight: 700; }
.clue-item.previous .clue-word { font-size: 0.95rem; font-weight: 600; }
.clue-item .clue-ipa { font-size: 0.8rem; color: var(--text-ter); font-style: italic; }
.clue-item.previous .clue-ipa { font-size: 0.72rem; }
.clue-btn-speak {
  font-size: 1rem; padding: 0.15rem; cursor: pointer; opacity: 0.6;
  transition: opacity 0.15s;
}
.clue-btn-speak:hover { opacity: 1; }

@keyframes clueSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Guess Row */
.guess-row {
  display: flex; gap: 0.5rem; width: 100%; max-width: 360px; margin-bottom: 1rem;
}
.guess-input {
  flex: 1; min-height: 48px; padding: 0 1rem;
  border-radius: var(--radius); border: 2px solid var(--card-border);
  background: var(--card-bg); color: var(--text);
  font-size: 1.05rem; outline: none;
  transition: border-color 0.2s;
}
.guess-input:focus { border-color: var(--gold); }
.guess-input.shake { animation: shake 0.3s ease-out; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.btn-guess {
  min-height: 48px; padding: 0 1.25rem;
  background: var(--gold); color: #1a1400;
  font-weight: 700; font-size: 0.95rem;
  border-radius: var(--radius);
  transition: transform 0.1s;
}
.btn-guess:active { transform: scale(0.95); }

/* Score Float */
.score-float {
  position: absolute; font-size: 1.5rem; font-weight: 700;
  color: var(--teal); pointer-events: none;
  animation: scoreFloat 0.8s ease-out forwards;
}
@keyframes scoreFloat {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-30px); }
}

/* Confetti (CSS only) */
.confetti-container {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 100; overflow: hidden;
}
.confetti-piece {
  position: absolute; width: 8px; height: 8px;
  top: -10px; border-radius: 2px;
  animation: confettiFall 1.2s ease-out forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== LANGUAGE POOL ===== */
.lang-pool-wrapper { margin-top: auto; }
.lang-pool-label {
  text-align: center; font-size: 0.78rem;
  color: var(--text-ter); margin-bottom: 0.5rem;
}
.lang-pool {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
@media (min-width: 481px) {
  .lang-pool { grid-template-columns: repeat(4, 1fr); }
}

.lang-btn {
  display: flex; align-items: center; justify-content: center;
  gap: 0.35rem; padding: 0.6rem 0.3rem;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  font-size: 0.82rem; font-weight: 500;
  transition: transform 0.1s, opacity 0.2s, background 0.2s;
  min-height: 44px; position: relative;
}
.lang-btn .lang-flag { font-size: 1.15rem; }
.lang-btn .lang-name { white-space: nowrap; }

/* Difficulty borders */
.lang-btn.diff-easy { border-color: rgba(29,158,117,0.35); }
.lang-btn.diff-medium { border-color: rgba(239,159,39,0.3); }
.lang-btn.diff-hard { border-color: rgba(226,75,74,0.3); }

.lang-btn:hover:not(.spent):not(.used) { background: rgba(255,255,255,0.12); }
.lang-btn:active:not(.spent):not(.used) { transform: scale(0.95); }

.lang-btn.used {
  opacity: 0.4; pointer-events: none;
  background: rgba(255,255,255,0.04);
}
.lang-btn.spent {
  opacity: 0.3; pointer-events: none;
  background: rgba(255,255,255,0.02);
  text-decoration: line-through;
}
.lang-btn .spent-badge {
  position: absolute; top: -4px; right: -4px;
  font-size: 0.55rem; font-weight: 700;
  background: var(--text-ter); color: var(--bg);
  border-radius: 50%; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
}

/* ===== RESULTS SCREEN ===== */
.results-content {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; padding: 2.5rem 1.5rem 1.5rem;
  text-align: center;
}
.results-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem; color: var(--gold); margin-bottom: 1rem;
}
.results-score { font-size: 2.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.results-stars { font-size: 1.6rem; margin-bottom: 0.5rem; }
.results-streak { color: var(--gold); font-size: 1rem; margin-bottom: 1.25rem; }

.share-grid {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 0.85rem 1.25rem;
  margin-bottom: 1.25rem; text-align: left;
  font-size: 0.95rem; line-height: 1.7; min-width: 220px;
}

.btn-share {
  background: var(--gold); color: #1a1400;
  font-weight: 700; font-size: 1rem;
  padding: 0.85rem 2.5rem; border-radius: 50px;
  transition: transform 0.15s;
  margin-bottom: 0.5rem;
}
.btn-share:active { transform: scale(0.95); }

.copied-msg {
  color: var(--teal); font-size: 0.85rem;
  opacity: 0; transition: opacity 0.3s;
  margin-bottom: 1rem; min-height: 1.2em;
}
.copied-msg.visible { opacity: 1; }

.next-puzzle { color: var(--text-sec); font-size: 0.9rem; margin-bottom: 1.5rem; }

.btn-expand-words {
  color: var(--gold); font-size: 0.95rem;
  text-decoration: underline; text-underline-offset: 3px;
  margin-bottom: 1rem;
}

/* Words Panel */
.words-panel {
  display: none; width: 100%; max-width: 500px;
  text-align: left;
}
.words-panel.open { display: block; }

.wp-word {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 1rem;
  margin-bottom: 0.75rem;
}
.wp-word-title {
  font-size: 1.15rem; font-weight: 700; margin-bottom: 0.15rem;
  text-transform: capitalize;
}
.wp-word-cat { font-size: 0.75rem; color: var(--text-ter); margin-bottom: 0.6rem; }
.wp-etymology {
  font-size: 0.8rem; color: var(--text-sec);
  line-height: 1.45; margin-bottom: 0.75rem;
  padding: 0.5rem; background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
}
.wp-trans-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}
.wp-trans-item {
  display: flex; align-items: center; gap: 0.3rem;
  font-size: 0.82rem; line-height: 1.4;
}
.wp-trans-item .wp-flag { font-size: 1rem; }
.wp-trans-item .wp-tw { font-weight: 600; }
.wp-trans-item .wp-ipa { color: var(--text-ter); font-style: italic; font-size: 0.72rem; }
.wp-trans-item .wp-speak {
  font-size: 0.8rem; cursor: pointer; opacity: 0.5;
  transition: opacity 0.15s; margin-left: auto;
}
.wp-trans-item .wp-speak:hover { opacity: 1; }

/* ===== OVERLAYS ===== */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); z-index: 200;
  align-items: center; justify-content: center;
  padding: 1.5rem;
}
.overlay.active { display: flex; }

.overlay-box {
  background: var(--bg-light); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 2rem 1.75rem;
  max-width: 380px; width: 100%; position: relative;
}
.overlay-close {
  position: absolute; top: 0.75rem; right: 0.75rem;
  font-size: 1.5rem; color: var(--text-sec); width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.overlay-box h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem; color: var(--gold); margin-bottom: 1.25rem;
  text-align: center;
}
.how-item {
  display: flex; align-items: flex-start; gap: 0.75rem;
  margin-bottom: 1rem;
}
.how-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 0.1rem; }
.how-item p { font-size: 0.9rem; color: var(--text-sec); line-height: 1.45; }

.overlay-confirm-box { text-align: center; }
.overlay-confirm-box p { color: var(--text-sec); margin-bottom: 1.25rem; font-size: 1rem; }
.confirm-btns { display: flex; gap: 0.75rem; justify-content: center; }
.btn-confirm-cancel {
  padding: 0.7rem 1.5rem; border-radius: 50px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text); font-weight: 600; font-size: 0.9rem;
}
.btn-confirm-exit {
  padding: 0.7rem 1.5rem; border-radius: 50px;
  background: var(--red); color: white; font-weight: 600; font-size: 0.9rem;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== RESPONSIVE TWEAKS ===== */
@media (max-width: 380px) {
  .letter-tile { width: 38px; height: 38px; font-size: 1.15rem; }
  .lang-btn { font-size: 0.75rem; padding: 0.5rem 0.2rem; }
}
@media (min-width: 600px) {
  .game-body { max-width: 580px; }
  .letter-tile { width: 48px; height: 48px; }
}
