/**
 * Kahu Word Rain Game Stylesheet (Mưa chữ Kahu)
 * Optimized for hardware-accelerated animations (transform translate3d, requestAnimationFrame),
 * high contrast readability (font-size >= 24px), accessibility, and responsive viewports.
 */

/* ==========================================================================
   Game Container & Setup Screen
   ========================================================================== */
.rain-wrapper {
  max-width: 1040px;
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
}

/* Settings Setup Card */
.rain-setup-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2.25rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

.rain-setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1.75rem;
  margin: 1.5rem 0 2rem;
}

.setup-group {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.setup-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.setup-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: -0.2rem;
}

/* Option Chips / Buttons */
.option-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-btn:hover {
  border-color: var(--kahu-blue, #1d4ed8);
  color: var(--kahu-blue, #1d4ed8);
  background: #eff6ff;
}

.chip-btn.active {
  background: var(--kahu-blue, #1d4ed8);
  color: #ffffff !important;
  border-color: #1e40af;
  box-shadow: 0 2px 4px rgba(29, 78, 216, 0.25);
}

.chip-btn:focus-visible,
.speed-slider:focus-visible,
.setup-toggle-row input:focus-visible,
#inputCustomDuration:focus-visible,
#btnStartGame:focus-visible,
#rainInput:focus-visible {
  outline: 2.5px solid var(--kahu-blue, #1d4ed8);
  outline-offset: 2px;
}

/* Speed Slider Styling */
.speed-slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.35rem;
}

.speed-slider {
  flex: 1;
  height: 8px;
  border-radius: var(--radius-full);
  background: #e2e8f0;
  accent-color: var(--kahu-blue, #1d4ed8);
  cursor: pointer;
}

.speed-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--kahu-blue, #1d4ed8);
  background: #eff6ff;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  min-width: 80px;
  text-align: center;
}

/* Checkbox Toggles */
.setup-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  cursor: pointer;
  user-select: none;
}

.setup-toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #7c3aed;
  cursor: pointer;
}

/* ==========================================================================
   Live Game Arena
   ========================================================================== */
.rain-game-area {
  display: none;
  flex-direction: column;
  gap: 0.85rem;
}

/* Live HUD Ribbon */
.rain-hud-ribbon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.hud-stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-stat-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.hud-stat-lbl {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.combo-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #fef3c7;
  color: #b45309;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid #fde68a;
  transition: transform 0.15s ease;
}

.combo-pill.active {
  transform: scale(1.08);
  background: #fef08a;
  color: #854d0e;
  border-color: #facc15;
}

.combo-pill.fire {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.lives-container {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 1.25rem;
  line-height: 1;
}

/* Time Progress Bar */
.rain-timer-bar-wrap {
  height: 6px;
  background: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.rain-timer-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7c3aed, #0d9488);
  border-radius: var(--radius-full);
  transition: width 0.25s linear;
}

/* Game Canvas Arena */
.rain-arena {
  position: relative;
  width: 100%;
  height: 520px;
  background: linear-gradient(180deg, #f8fafc 0%, #ede9fe 60%, #fae8ff 100%);
  border: 2px solid #ddd6fe;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(124, 58, 237, 0.08);
}

@media (max-width: 768px) {
  .rain-arena {
    height: 420px;
  }
}

/* Danger Line */
.danger-line {
  position: absolute;
  bottom: 60px;
  left: 0;
  right: 0;
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    #ef4444 0,
    #ef4444 15px,
    #fee2e2 15px,
    #fee2e2 30px
  );
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.45);
  z-index: 5;
}

.danger-line-label {
  position: absolute;
  right: 1rem;
  bottom: 66px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #dc2626;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(254, 242, 242, 0.9);
  padding: 1px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid #fca5a5;
  z-index: 6;
  pointer-events: none;
}

/* Falling Objects (Rain Items) */
.rain-item {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-lg);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-weight: 800;
  font-size: 24px;
  line-height: 1.1;
  background: #ffffff;
  color: #1e1b4b;
  border: 2px solid #8b5cf6;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.22);
  user-select: none;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  will-change: transform;
}

.rain-item.char-single {
  font-size: 28px;
  min-width: 48px;
  min-height: 48px;
  padding: 0.2rem 0.65rem;
}

/* Distinct Types */
.rain-item[data-type="char_upper"] {
  border-color: #2563eb;
  color: #1e3a8a;
  background: #eff6ff;
}

.rain-item[data-type="digit"] {
  border-color: #059669;
  color: #064e3b;
  background: #ecfdf5;
}

.rain-item[data-type="word"] {
  border-color: #7c3aed;
  color: #3b0764;
  background: #ffffff;
}

/* Matching Prefix Highlight */
.rain-item .prefix-matched {
  color: #059669;
  text-decoration: underline wavy #10b981;
}

/* Hit & Destroy Animation */
.rain-item.is-hit {
  background: #10b981 !important;
  color: #ffffff !important;
  border-color: #059669 !important;
  transform: scale(1.15) !important;
  opacity: 0;
  transition: transform 0.22s ease-out, opacity 0.22s ease-out;
}

/* Miss / Passed Line Animation */
.rain-item.is-missed {
  background: #ef4444 !important;
  color: #ffffff !important;
  border-color: #dc2626 !important;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .rain-item.is-hit,
  .rain-item.is-missed {
    transition: none !important;
  }
}

/* Level Up Toast in Arena */
.rain-levelup-toast {
  position: absolute;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #7c3aed, #0d9488);
  color: #ffffff;
  padding: 0.45rem 1.25rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
  z-index: 30;
  display: none;
  animation: levelPop 0.3s ease-out;
}

@keyframes levelPop {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Pause Overlay */
.rain-pause-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  z-index: 40;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  color: #ffffff;
}

.rain-pause-badge {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Input Console at Bottom */
.rain-input-console {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.rain-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.rain-text-input {
  width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 1.35rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 2px solid #c4b5fd;
  background: #fdfcff;
  color: var(--text-main);
  outline: none;
  box-shadow: 0 2px 4px rgba(124, 58, 237, 0.1);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.rain-text-input:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.rain-text-input.input-shake {
  animation: inputShake 0.25s ease-in-out;
  border-color: #ef4444;
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.rain-controls-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ==========================================================================
   Results & Summary Card
   ========================================================================== */
.rain-summary-card {
  display: none;
  background: var(--surface);
  border: 2px solid #7c3aed;
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: summaryPop 0.25s ease-out;
}

.rain-score-hero {
  font-size: 3.8rem;
  font-weight: 800;
  color: #7c3aed;
  line-height: 1;
  margin-bottom: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.rain-high-score-tag {
  display: inline-block;
  background: #fef08a;
  color: #854d0e;
  border: 1px solid #facc15;
  padding: 0.2rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
}

.rain-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1.25rem;
  background: var(--surface-alt);
  border-radius: var(--radius-lg);
}

@media (max-width: 640px) {
  .rain-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.rain-metric-val {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
}

.rain-metric-lbl {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* In-game Confirm Modal */
.rain-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.rain-modal-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2rem;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border);
  text-align: center;
}

@media (max-width: 640px) {
  .rain-setup-card {
    padding: 1.25rem 0.85rem;
    border-radius: var(--radius-lg);
  }
  .rain-setup-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
  .setup-toggle-row {
    padding: 0.65rem 0.75rem;
  }
  .option-chips-row {
    gap: 0.35rem;
  }
  .chip-btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
  }
  .rain-hud-ribbon {
    padding: 0.5rem 0.65rem;
    gap: 0.4rem;
  }
  .hud-stat-val {
    font-size: 1.2rem;
  }
}
