/* ===========================
   CSS Custom Properties
   =========================== */
:root {
  --bg-0: #d4edda;   /* pastel green  (0 wrong) */
  --bg-1: #c9e8c9;
  --bg-2: #e8e8c0;
  --bg-3: #f5e6b0;
  --bg-4: #f5d4a0;
  --bg-5: #f5c0a0;
  --bg-6: #f5a898;
  --bg-7: #f5857a;   /* pastel red    (7 wrong) */

  --text-primary: #2c2c3a;
  --text-muted: #6b6b80;
  --text-light: #9999aa;

  --tile-bg: rgba(255,255,255,0.55);
  --tile-border: rgba(255,255,255,0.85);
  --tile-shadow: rgba(0,0,0,0.06);

  --key-default: rgba(255,255,255,0.70);
  --key-correct: #7bcf8a;
  --key-wrong: #c0849a;
  --key-text: #2c2c3a;

  --dot-inactive: rgba(0,0,0,0.15);
  --dot-active: #d05e6e;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.35s ease;

  --current-bg: var(--bg-0);
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  min-height: 100dvh;
  background-color: var(--current-bg);
  transition: background-color 0.7s ease;
  color: var(--text-primary);
  overflow-x: hidden;
  position: relative;
}

/* ===========================
   Background image (win reveal)
   =========================== */
#bg-image {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 1.6s ease;
  z-index: 0;
  pointer-events: none;
}

#bg-image.visible { opacity: 0.18; }

#bg-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* ===========================
   Layout
   =========================== */
#app {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 32px;
  gap: 0;
}

/* ===========================
   Header
   =========================== */
header {
  text-align: center;
  margin-bottom: 16px;
}

header h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1;
}

.tagline {
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
}

/* ===========================
   Loading
   =========================== */
#loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 80px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(0,0,0,0.12);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===========================
   Game Screen
   =========================== */
#game-screen {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* ===========================
   Clue Bar
   =========================== */
#clue-bar {
  background: var(--tile-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--tile-border);
  border-radius: 100px;
  padding: 8px 24px;
  box-shadow: 0 2px 12px var(--tile-shadow);
}

#clue-text {
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

/* ===========================
   Lives Bar
   =========================== */
#lives-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

#lives-dots {
  display: flex;
  gap: 5px;
}

.life-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot-inactive);
  transition: background 0.3s ease, transform 0.2s ease;
}

.life-dot.used {
  background: var(--dot-active);
  transform: scale(1.1);
}

#lives-count {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.82rem;
}

/* ===========================
   Title Display
   =========================== */
#title-display-wrapper {
  width: 100%;
  background: var(--tile-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: 0 4px 20px var(--tile-shadow);
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#title-display {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
}

/* Each word stays on one line */
.title-word {
  display: inline-flex;
  gap: 4px;
  white-space: nowrap;
  align-items: flex-end;
}

/* Each character uses a 2-row grid:
   Row 1 — fixed letter area (always the same height, revealed or not)
   Row 2 — fixed underline area (always the same height, always at the bottom)
   This guarantees every underline sits on exactly the same baseline. */
.title-char {
  display: inline-grid;
  grid-template-rows: clamp(36px, 7vw, 48px) 8px;
  align-items: end;
  justify-items: center;
  min-width: clamp(14px, 3vw, 20px);
}

/* The letter — lives in grid row 1 */
.char-letter {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.3rem, 3.8vw, 1.9rem);
  line-height: 1;
  color: var(--text-primary);
  min-width: 0.55em;
  text-align: center;
  display: block;
  grid-row: 1;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.char-letter.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* The underline — lives in grid row 2, always same position */
.char-line {
  grid-row: 2;
  display: block;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: rgba(0,0,0,0.28);
  align-self: start;
  margin-top: 3px;
}

/* Special chars (digits, punctuation) — letter shown immediately, no underline */
.title-char.special {
  align-items: end;
}

.title-char.special .char-letter {
  opacity: 1;
  transform: translateY(0);
  color: var(--text-muted);
}

.title-char.special .char-line {
  display: none;
}

/* ===========================
   Result Message
   =========================== */
#result-message {
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(12px);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  padding: 18px 28px;
  text-align: center;
  box-shadow: 0 4px 20px var(--tile-shadow);
  animation: slideUp 0.4s ease forwards;
}

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

#result-text {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 900;
  color: var(--text-primary);
}

#result-title-reveal {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ===========================
   Keyboard
   =========================== */
#keyboard-wrapper {
  width: 100%;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  width: 100%;
}

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

.key {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(0.75rem, 2.2vw, 0.9rem);
  width: clamp(28px, 8.5vw, 44px);
  height: clamp(36px, 9vw, 50px);
  border-radius: var(--radius-sm);
  border: none;
  background: var(--key-default);
  color: var(--key-text);
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.08);
  transition: background 0.25s ease, transform 0.1s ease, opacity 0.3s ease;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.8);
  text-transform: uppercase;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.key:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.1);
}

.key:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.12);
}

.key.correct {
  background: var(--key-correct);
  border-color: rgba(255,255,255,0.6);
  opacity: 0.7;
  cursor: default;
}

.key.wrong {
  background: var(--key-wrong);
  border-color: rgba(255,255,255,0.4);
  opacity: 0.55;
  cursor: default;
}

.key:disabled {
  cursor: default;
}

/* ===========================
   New Game Button
   =========================== */
#new-game-wrapper {
  display: flex;
  justify-content: center;
  padding-top: 4px;
}

#new-game-btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 14px 36px;
  border: none;
  border-radius: 100px;
  background: var(--text-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 0.02em;
}

#new-game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

#new-game-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ===========================
   Utilities
   =========================== */
.hidden { display: none !important; }

/* ===========================
   Shake animation (wrong guess)
   =========================== */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

.shake { animation: shake 0.4s ease; }

/* ===========================
   Responsive tweaks
   =========================== */
@media (max-width: 400px) {
  .key { gap: 4px; }
  #title-display-wrapper { padding: 18px 12px; }
}

/* ===========================
   Scoreboard Modal
   =========================== */
#scoreboard-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  z-index: 100;
  animation: fadeIn 0.25s ease;
}

#scoreboard-modal {
  position: fixed;
  inset: 0;
  z-index: 101;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
}

#scoreboard-modal:not(.hidden) {
  pointer-events: auto;
}

#scoreboard-inner {
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

#scoreboard-inner h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}

#score-grid {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
}

.score-section {
  flex: 1;
  min-width: 0;
}

.score-section h3 {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.score-divider {
  width: 1px;
  background: rgba(0,0,0,0.08);
  margin: 0 20px;
  flex-shrink: 0;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
}

.score-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.score-value {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.score-value.correct   { color: #3a9a58; }
.score-value.incorrect { color: #c0394a; }

.total-row {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid rgba(0,0,0,0.08);
}

.total-row .score-value { font-size: 1.1rem; }

.score-bar-track {
  height: 6px;
  background: rgba(0,0,0,0.08);
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #7bcf8a, #3a9a58);
  width: 0%;
  transition: width 0.7s cubic-bezier(0.34, 1.1, 0.64, 1);
}

#scoreboard-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#play-again-btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 14px 36px;
  border: none;
  border-radius: 100px;
  background: var(--text-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 0.02em;
  width: 100%;
}

#play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

#play-again-btn:active { transform: translateY(1px); }

.btn-reset {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 10px 20px;
  border: 1.5px solid rgba(0,0,0,0.15);
  border-radius: 100px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
  width: 100%;
  letter-spacing: 0.02em;
}

.btn-reset:hover {
  border-color: #c0394a;
  color: #c0394a;
  background: rgba(192,57,74,0.05);
}