/* ================================================================
   Vocabulary Rain — game.css
   Dark arcade theme with neon accents
   ================================================================ */

/* ---------- Variables ---------- */
:root {
  --bg:        #080d1a;
  --surface:   #0f1829;
  --surface2:  #162236;
  --border:    #1e2d42;
  --text:      #e2e8f0;
  --muted:     #4a6080;

  --blue:   #4f6ef7;
  --green:  #10b981;
  --red:    #ef4444;
  --yellow: #f59e0b;
  --purple: #8b5cf6;
  --pink:   #ec4899;
  --cyan:   #06b6d4;

  --hud-h:    58px;
  --type-h:   86px;
  --danger-h: 56px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Arial, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

button { cursor: pointer; font-family: inherit; border: none; }
a { text-decoration: none; }
kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: .78rem;
}

/* ---------- Screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ================================================================
   START SCREEN
   ================================================================ */

.start-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.back-link {
  color: var(--muted);
  font-size: .82rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
  transition: color .15s;
}
.back-link:hover { color: var(--text); }

/* Logo */
.game-logo { text-align: center; padding: 10px 0 4px; }

.logo-rain { font-size: 3.5rem; line-height: 1; margin-bottom: 10px; }

.game-logo h1 {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--blue) 0%, #818cf8 50%, var(--pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-logo p {
  color: var(--muted);
  font-size: .88rem;
  margin-top: 8px;
  line-height: 1.5;
}

/* Select blocks */
.select-block { display: flex; flex-direction: column; gap: 10px; }

.select-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

/* Mode grid — 2×2 for 4 modes */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.mode-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--text);
  transition: all .15s;
}

.mode-card .card-icon { font-size: 1.8rem; line-height: 1; }
.mode-card strong     { font-size: .9rem; font-weight: 700; }
.mode-card span:last-child {
  font-size: .68rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.mode-card:hover  { border-color: var(--blue); transform: translateY(-2px); }
.mode-card.active {
  border-color: var(--blue);
  background: rgba(79,110,247,.12);
  box-shadow: 0 0 20px rgba(79,110,247,.2);
}

/* Diff grid */
.diff-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.diff-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text);
  transition: all .15s;
}

.diff-btn strong { font-size: .88rem; font-weight: 700; }
.diff-btn span   { font-size: .65rem; color: var(--muted); text-align: center; line-height: 1.4; }

.diff-btn:hover  { border-color: var(--purple); }
.diff-btn.active {
  border-color: var(--purple);
  background: rgba(139,92,246,.12);
  box-shadow: 0 0 16px rgba(139,92,246,.18);
}

/* High score panel */
#highScorePanel h3 {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.hs-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  background: var(--surface);
  border-radius: 8px;
  font-size: .82rem;
  margin-bottom: 4px;
}

.hs-row span   { color: var(--muted); }
.hs-row strong { color: var(--blue); font-size: .9rem; }

/* Play button */
.btn-play {
  background: linear-gradient(135deg, var(--blue) 0%, #818cf8 100%);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 18px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: .5px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(79,110,247,.4);
  transition: all .15s;
}
.btn-play:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(79,110,247,.5);
}

.keyboard-tip {
  text-align: center;
  font-size: .75rem;
  color: var(--muted);
}

/* ================================================================
   GAME SCREEN
   ================================================================ */

#gameScreen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* HUD */
.hud {
  height: var(--hud-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  z-index: 10;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.hud-right { justify-content: flex-end; }
.hud-center { text-align: center; flex-shrink: 0; }

.lives { font-size: 1.05rem; letter-spacing: 1px; }
.hud-label { font-size: .65rem; color: var(--muted); }

.score-num { font-size: 1.7rem; font-weight: 900; color: #fff; line-height: 1; }
.score-label { font-size: .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* Combo display */
.combo-wrap {
  text-align: center;
  animation: comboPop .3s ease;
}

.combo-val {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--yellow);
  line-height: 1;
}

.combo-lab {
  font-size: .55rem;
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.combo-fire .combo-val { color: #f97316; text-shadow: 0 0 12px rgba(249,115,22,.7); }

/* Accuracy display */
.acc-wrap { text-align: center; }
.acc-val  { font-size: 1rem; font-weight: 700; color: var(--green); line-height: 1; }
.acc-lab  { font-size: .55rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* Pause button */
.hud-pause-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: .85rem;
  transition: all .15s;
}
.hud-pause-btn:hover { border-color: var(--muted); color: var(--text); }

/* ---- Game Field ---- */
.field {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(79,110,247,.07) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(139,92,246,.06) 0%, transparent 60%),
    var(--bg);
}

/* Subtle dot grid */
.field::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(79,110,247,.09) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

/* Danger zone at bottom */
.field-danger {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--danger-h);
  border-top: 1px solid rgba(239,68,68,.35);
  background: linear-gradient(transparent, rgba(239,68,68,.05));
  pointer-events: none;
}

/* ---- Falling Words ---- */
.fw {
  position: absolute;
  top: 0;
  min-width: 110px;
  max-width: 220px;
  background: rgba(8,13,26,.88);
  border: 1.5px solid var(--fw-color, #4f6ef7);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  backdrop-filter: blur(6px);
  box-shadow:
    0 0 0 1px rgba(var(--fw-rgb, 79,110,247),.12),
    0 4px 16px rgba(0,0,0,.5);
  will-change: transform;
}

.fw-vi {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.3;
}

.fw-cat {
  font-size: .58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--fw-color, #4f6ef7);
  opacity: .75;
}

/* English answer — hidden while falling, revealed on miss */
.fw-en {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--red);
  letter-spacing: .5px;
  line-height: 1.2;
  max-width: 200px;
  text-align: center;
  /* Hidden by default — only shown when .fw-en-show is added */
  display: none;
  opacity: 0;
}

.fw-en.fw-en-show {
  display: block;
  animation: enPop .25s ease forwards;
}

@keyframes enPop {
  from { opacity: 0; transform: scale(.8); }
  to   { opacity: 1; transform: scale(1); }
}

.fw-hint {
  font-size: .72rem;
  color: var(--green);
  font-weight: 600;
  min-height: 14px;
  letter-spacing: .5px;
}

/* Highlighted (partial match) */
.fw.fw-hl {
  border-color: var(--green) !important;
  box-shadow:
    0 0 20px rgba(16,185,129,.35),
    0 4px 16px rgba(0,0,0,.5);
}

/* Danger zone — near bottom */
.fw.fw-danger {
  border-color: var(--red) !important;
  animation: dangerPulse .55s ease infinite alternate;
}

@keyframes dangerPulse {
  from { box-shadow: 0 0 8px  rgba(239,68,68,.3), 0 4px 16px rgba(0,0,0,.5); }
  to   { box-shadow: 0 0 28px rgba(239,68,68,.7), 0 4px 16px rgba(0,0,0,.5); }
}

/* Correct — scale-pop + fade */
.fw.fw-correct {
  border-color: var(--green) !important;
  background: rgba(16,185,129,.15) !important;
  animation: wordPop .38s ease forwards;
  pointer-events: none;
}

@keyframes wordPop {
  0%   { transform: scale(1);    opacity: 1; }
  55%  { transform: scale(1.18); opacity: .85; }
  100% { transform: scale(1.32); opacity: 0; }
}

/* Reveal on miss — card slides up into view, shows answer, holds, then fades */
.fw.fw-reveal {
  border-color: var(--red) !important;
  background: rgba(239, 68, 68, .14) !important;
  box-shadow:
    0 0 0 2px rgba(239,68,68,.25),
    0 0 28px rgba(239,68,68,.4),
    0 4px 20px rgba(0,0,0,.6) !important;
  /* Smooth slide-up when JS adjusts 'top' via requestAnimationFrame */
  transition: top 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  /* Opacity-only fade so it doesn't fight the top transition */
  animation: revealFade 2.3s ease forwards;
  pointer-events: none;
  /* Ensure card renders above the danger zone gradient */
  z-index: 5;
}

/* Small "📖 đáp án" suffix on the category line */
.fw.fw-reveal .fw-cat::after {
  content: ' · 📖 đáp án';
  color: var(--red);
  opacity: .85;
}

@keyframes revealFade {
  /* Hold fully visible, then fade out at the end */
  0%,  72% { opacity: 1; }
  100%     { opacity: 0; }
}

/* Field flash on miss */
@keyframes fieldFlash {
  0%, 100% { background-color: transparent; }
  50%       { background-color: rgba(239,68,68,.07); }
}

.field.flash { animation: fieldFlash .4s ease; }

/* ---- Learn mode word card ---- */
.fw.fw-learn {
  max-width: 300px;
  min-width: 160px;
}

.fw.fw-learn .fw-vi { font-size: 1.05rem; }

/* Learn mode reveal — green instead of red */
.fw.fw-learn-reveal {
  border-color: var(--green) !important;
  background: rgba(16,185,129,.13) !important;
  box-shadow:
    0 0 0 2px rgba(16,185,129,.25),
    0 0 28px rgba(16,185,129,.4),
    0 4px 20px rgba(0,0,0,.6) !important;
  transition: top 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  z-index: 5;
}

.fw.fw-learn-reveal .fw-en {
  color: var(--green) !important;
  font-size: 1.25rem !important;
}

.fw.fw-learn-reveal .fw-cat::after {
  content: ' · 🔊';
  color: var(--green);
  opacity: .9;
}

/* ---- Learn mode bottom bar ---- */
.learn-bar {
  height: var(--type-h);
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  z-index: 10;
}

.learn-status {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  transition: color .3s;
  text-align: center;
}

.learn-counter {
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .3px;
}

/* Show/hide based on learn-mode class on #gameScreen */
#gameScreen:not(.learn-mode) .learn-bar { display: none !important; }
#gameScreen.learn-mode .type-area       { display: none !important; }
#gameScreen.learn-mode .combo-wrap      { display: none !important; }
#gameScreen.learn-mode .acc-wrap        { display: none !important; }

/* ---- Typing Area ---- */
.type-area {
  height: var(--type-h);
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 10;
}

.type-hint {
  font-size: .73rem;
  color: var(--muted);
  transition: color .2s;
}

.game-input {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .5px;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}

.game-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79,110,247,.18);
}

.game-input::placeholder { color: #2a3d56; }

/* ---- Overlay (Pause) ---- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 260px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: boxIn .2s ease;
}

.overlay-icon { font-size: 2.5rem; }
.overlay-box h2 { font-size: 1.4rem; font-weight: 800; }

.overlay-btns { display: flex; gap: 10px; width: 100%; }

/* ---- Shared overlay buttons ---- */
.obtn {
  flex: 1;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 700;
  border: none;
  transition: all .15s;
}

.obtn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 16px rgba(79,110,247,.3);
}
.obtn-primary:hover { background: #3d5af1; }

.obtn-ghost {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.obtn-ghost:hover { color: var(--text); border-color: var(--muted); }

/* ================================================================
   GAME OVER SCREEN
   ================================================================ */

#overScreen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.over-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 28px;
  max-width: 380px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  animation: boxIn .3s ease;
}

@keyframes boxIn {
  from { opacity: 0; transform: scale(.92) translateY(12px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

.over-icon  { font-size: 3.2rem; }
.over-title { font-size: 1.7rem; font-weight: 900; }

.over-stats { width: 100%; display: flex; flex-direction: column; gap: 7px; }

.over-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  background: rgba(255,255,255,.04);
  border-radius: 10px;
  font-size: .9rem;
}

.over-stat span   { color: var(--muted); }
.over-stat strong { color: #fff; font-size: .98rem; font-weight: 700; }

.new-record {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--yellow);
  text-shadow: 0 0 16px rgba(245,158,11,.5);
  animation: glow 1.2s ease infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 8px  rgba(245,158,11,.4); }
  to   { text-shadow: 0 0 24px rgba(245,158,11,.8); }
}

.over-btns { display: flex; gap: 10px; width: 100%; }

/* ================================================================
   FLOATING SCORE TEXT
   ================================================================ */

.float-score {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  font-size: 1rem;
  font-weight: 900;
  color: var(--green);
  text-shadow: 0 0 12px rgba(16,185,129,.6);
  transform: translateX(-50%);
  animation: floatUp .9s ease forwards;
}

@keyframes floatUp {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-55px); }
}

/* ================================================================
   COMBO ANIMATIONS
   ================================================================ */

@keyframes comboPop {
  0%   { transform: scale(1);    }
  40%  { transform: scale(1.22); }
  100% { transform: scale(1);    }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 520px) {
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
  .diff-grid { grid-template-columns: repeat(2, 1fr); }
  .game-input { font-size: 1.05rem; }
  .score-num  { font-size: 1.4rem; }
  .fw-vi { font-size: .9rem; }
  .hud { padding: 0 10px; gap: 8px; }
  .lives { font-size: .9rem; }
}

@media (max-width: 360px) {
  .hud-label { display: none; }
  .acc-lab, .combo-lab { display: none; }
}
