:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #21262D;
  --text-primary: #F0F6FC;
  --text-secondary: #8B949E;
  --text-muted: #484F58;
  --accent: #3B82F6;
  --border: #30363D;
  --btn-bg: #21262D;
  --btn-active: #30363D;
  --overlay-bg: rgba(0, 0, 0, 0.85);
  --board-bg: #0A0E14;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F6F8FA;
    --bg-tertiary: #E9ECF0;
    --text-primary: #1B1E28;
    --text-secondary: #57606A;
    --text-muted: #8C959F;
    --accent: #3182F6;
    --border: #D0D7DE;
    --btn-bg: #E9ECF0;
    --btn-active: #D0D7DE;
    --overlay-bg: rgba(255, 255, 255, 0.9);
    --board-bg: #F0F2F5;
  }
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── OVERLAY SCREENS ── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

/* ── TITLE GRADIENT ── */
.game-title {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, var(--accent) 0%, #7C3AED 50%, #EC4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ── STATS ROW ── */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-value.win { color: #22C55E; }
.stat-value.lose { color: #EF4444; }
.stat-value.streak { color: var(--accent); }

/* ── RESULT OVERLAY SPECIFICS ── */
.result-icon {
  font-size: 3.5rem;
  line-height: 1;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 800;
}

.result-title.win { color: #22C55E; }
.result-title.lose { color: #EF4444; }

.result-word {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.result-word span {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 28px;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 18px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
  background: #2563EB;
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.5);
}

.btn-secondary {
  background: var(--btn-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--btn-active);
  color: var(--text-primary);
}

/* ── MAIN GAME WRAPPER ── */
#app {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 8px;
  gap: 0;
  overflow: hidden;
}

/* ── HEADER ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  background: linear-gradient(135deg, var(--accent) 0%, #7C3AED 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-stats {
  display: flex;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.header-stats span {
  display: flex;
  align-items: center;
  gap: 3px;
}

.header-stats .hs-win { color: #22C55E; }
.header-stats .hs-lose { color: #EF4444; }
.header-stats .hs-streak { color: var(--accent); }

.header-stats strong {
  font-weight: 700;
  font-size: 0.9rem;
}

/* ── CANVAS AREA ── */
.canvas-section {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0 4px;
}

#hangmanCanvas {
  background: var(--board-bg);
  border-radius: 14px;
  border: 1px solid var(--border);
  display: block;
}

/* ── WRONG GUESS COUNTER ── */
.wrong-counter {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 2px 0;
}

.wrong-counter span {
  color: #EF4444;
  font-weight: 700;
}

/* ── CATEGORY + WORD DISPLAY ── */
.word-section {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 0 8px;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.category-badge .cat-icon {
  font-size: 0.9rem;
}

.word-display {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 8px;
}

.letter-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 22px;
}

.letter-tile .letter {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  transition: opacity 0.2s ease;
}

.letter-tile .letter.hidden-letter {
  color: transparent;
}

.letter-tile .underline {
  width: 100%;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
}

.letter-tile.revealed .underline {
  background: var(--accent);
}

/* ── KEYBOARD ── */
.keyboard-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 4px;
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, transform 0.08s ease, opacity 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.key-btn:hover:not(:disabled) {
  background: var(--btn-active);
  border-color: var(--accent);
}

.key-btn:active:not(:disabled) {
  transform: scale(0.9);
}

.key-btn.correct {
  background: rgba(34, 197, 94, 0.2);
  border-color: #22C55E;
  color: #22C55E;
  cursor: default;
}

.key-btn.wrong {
  background: rgba(239, 68, 68, 0.12);
  border-color: var(--text-muted);
  color: var(--text-muted);
  cursor: default;
  opacity: 0.5;
}

.key-btn:disabled {
  cursor: default;
}

/* ── RESPONSIVE TWEAKS ── */
@media (max-height: 700px) {
  .canvas-section { padding: 2px 0; }
  .word-section { padding: 4px 0 6px; gap: 6px; }
  .letter-tile .letter { font-size: 1.15rem; }
  .key-btn { width: 28px; height: 34px; font-size: 0.72rem; }
  .keyboard { gap: 4px; }
  .keyboard-row { gap: 4px; }
}

@media (max-height: 580px) {
  .key-btn { width: 25px; height: 30px; font-size: 0.68rem; border-radius: 6px; }
  .keyboard-row { gap: 3px; }
  .keyboard { gap: 3px; }
}
