/* =========================================================
   Hangman – Style Sheet
   Dark theme: #0F1117 bg, #1A1D27 surface, #305CDE accent
   ========================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0F1117;
  --surface: #1A1D27;
  --surface2: #22263a;
  --accent: #305CDE;
  --accent-h: #4a73f5;
  --text: #e8eaf6;
  --text-dim: #8890b0;
  --green: #69f0ae;
  --red: #ef5350;
  --yellow: #f9a825;
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  width: 100%;
  height: 100%;
}

/* ── Screens ── */
.screen { display: none; width: 100%; height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Start Screen ── */
#start-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #1e2540 0%, var(--bg) 70%);
  padding: 24px;
}
.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  max-width: 420px;
  width: 100%;
}
.game-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.game-logo h1 {
  font-size: clamp(36px, 10vw, 56px);
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--accent-h) 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 15px; text-align: center; }

/* Streak display */
.streak-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 50px;
  padding: 10px 24px;
}
.streak-icon { font-size: 22px; }
.streak-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--yellow);
  line-height: 1;
}
.streak-label { color: var(--text-dim); font-size: 13px; }

.category-prompt {
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  align-self: flex-start;
}

.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.cat-btn {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 18px 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .12s;
  text-align: center;
}
.cat-btn:nth-child(5) { grid-column: 1 / -1; }
.cat-btn:hover {
  background: var(--surface2);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.cat-btn:active { transform: scale(.96); }
.cat-btn.selected {
  background: rgba(48,92,222,.2);
  border-color: var(--accent-h);
  color: var(--accent-h);
}

/* ── Buttons ── */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 50px;
  padding: 14px 36px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(48,92,222,.4);
  transition: transform .15s, box-shadow .15s;
  min-width: 140px;
}
.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(48,92,222,.6); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50px;
  padding: 13px 28px;
  cursor: pointer;
  transition: background .15s, color .15s;
  min-width: 140px;
}
.btn-secondary:hover { background: rgba(255,255,255,.06); color: var(--text); }

/* ── Game Screen ── */
#game-screen {
  align-items: stretch;
  max-height: 100vh;
  overflow: hidden;
}

/* Top Bar */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,.06);
  padding: 8px 12px;
  flex-shrink: 0;
  gap: 8px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.1);
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,.07); color: var(--text); }
.game-info-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.cat-pill {
  background: rgba(48,92,222,.2);
  color: var(--accent-h);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px 10px;
  border-radius: 50px;
}
.wrong-label { font-size: 12px; color: var(--text-dim); }
.streak-mini {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--yellow);
}
#current-streak { font-size: 18px; }

/* Hangman SVG */
#hangman-area {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 8px 0 0;
}
#hangman-svg {
  width: min(220px, 45vw);
  height: auto;
}
.hm-part { transition: opacity .3s ease; }
.hm-part.hidden { opacity: 0; }
.hm-part.visible { opacity: 1; }
.hm-face { transition: opacity .3s ease; }
.hm-face.hidden { opacity: 0; }
.hm-face.visible { opacity: 1; }

/* Wrong shake animation */
@keyframes wrong-shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
#hangman-area.shake { animation: wrong-shake .4s ease; }

/* Word Display */
#word-display-area {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
}
#word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
}
.letter-blank {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.blank-letter {
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 800;
  min-width: 24px;
  text-align: center;
  height: clamp(28px, 6vw, 36px);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: all .2s cubic-bezier(.34,1.56,.64,1);
}
.blank-letter.reveal {
  color: var(--green);
  transform: scale(1.2);
}
.blank-letter.hint-reveal {
  color: var(--yellow);
  transform: scale(1.15);
}
.blank-line {
  width: clamp(20px, 5vw, 28px);
  height: 3px;
  background: var(--text-dim);
  border-radius: 2px;
}
.letter-blank.space-char .blank-line { background: transparent; }

/* Hint Button */
#hint-area { display: flex; align-items: center; gap: 10px; }
.hint-btn {
  background: transparent;
  border: 1px solid rgba(249,168,37,.4);
  color: var(--yellow);
  font-size: 13px;
  font-weight: 600;
  border-radius: 50px;
  padding: 7px 18px;
  cursor: pointer;
  transition: background .15s, transform .12s;
}
.hint-btn:hover { background: rgba(249,168,37,.1); }
.hint-btn:active { transform: scale(.95); }
.hint-btn:disabled { opacity: .35; cursor: not-allowed; }
.hint-used { color: var(--text-dim); font-size: 13px; }
.hint-used.hidden { display: none; }

/* ── Letter Grid (Keyboard) ── */
#keyboard-area {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6px 8px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#keyboard-area::-webkit-scrollbar { display: none; }

#letter-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 400px;
  width: 100%;
}

.letter-btn {
  width: clamp(36px, 9vw, 46px);
  height: clamp(42px, 10.5vw, 52px);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12);
  background: var(--surface);
  color: var(--text);
  font-size: clamp(14px, 3.5vw, 18px);
  font-weight: 700;
  cursor: pointer;
  transition: background .12s, color .12s, transform .1s, border-color .12s;
  flex-shrink: 0;
}
.letter-btn:hover:not(:disabled) {
  background: var(--surface2);
  border-color: rgba(255,255,255,.3);
  transform: translateY(-2px);
}
.letter-btn:active:not(:disabled) { transform: scale(.92); }
.letter-btn:disabled { cursor: not-allowed; }
.letter-btn.correct {
  background: rgba(105,240,174,.15);
  border-color: var(--green);
  color: var(--green);
}
.letter-btn.wrong {
  background: rgba(239,83,80,.12);
  border-color: rgba(239,83,80,.3);
  color: rgba(239,83,80,.5);
}

/* ── Game Over Overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.overlay-box {
  background: var(--surface);
  border-radius: 24px;
  padding: 36px 28px;
  max-width: 360px;
  width: 90%;
  border: 1px solid rgba(255,255,255,.1);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: overlay-in .3s cubic-bezier(.34,1.3,.64,1) both;
}
@keyframes overlay-in {
  from { transform: scale(.85) translateY(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.go-emoji { font-size: 64px; line-height: 1; }
.go-title {
  font-size: clamp(28px, 7vw, 40px);
  font-weight: 900;
  text-align: center;
}
.go-title.win  { color: var(--green); }
.go-title.lose { color: var(--red); }
.go-word {
  font-size: 15px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}
.go-word strong { color: var(--text); font-size: 18px; letter-spacing: 2px; }
.go-streak { font-size: 14px; color: var(--yellow); font-weight: 600; }
.go-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ── Win animation: reveal letters bounce ── */
@keyframes bounce-in {
  0%   { transform: scale(0) rotate(-10deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(3deg); }
  80%  { transform: scale(.95); }
  100% { transform: scale(1); opacity: 1; }
}
.blank-letter.win-anim {
  animation: bounce-in .4s cubic-bezier(.34,1.56,.64,1) both;
}

/* Wrong flash on hangman area */
@keyframes flash-red {
  0%,100% { filter: none; }
  50%      { filter: drop-shadow(0 0 12px rgba(239,83,80,.7)); }
}
#hangman-svg.flash { animation: flash-red .4s ease; }

/* ── Responsive ── */
@media (max-width: 360px) {
  .letter-btn { width: 33px; height: 39px; font-size: 13px; }
  #letter-grid { gap: 4px; }
  .blank-letter { font-size: 16px; }
}
@media (max-height: 680px) {
  #hangman-svg { width: min(160px, 38vw); }
  #word-display-area { padding: 4px 12px; gap: 6px; }
  #keyboard-area { padding: 4px 8px 8px; }
  .letter-btn { height: clamp(38px, 9.5vw, 46px); }
}
@media (max-height: 560px) {
  #hangman-svg { width: min(130px, 30vw); }
}
