/* ============================================
   Number Duel – Game Theme
   Dark neon arcade style with animations.
   Fully mobile responsive.
   ============================================ */

/* ── Reset & Base ── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0a0e1a;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
  overflow-x: hidden;
  position: relative;
}

/* ── Animated Background Particles ── */
#particles {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

#particles .particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: rgba(56, 189, 248, 0.3);
  border-radius: 50%;
  animation: float-up linear infinite;
}

@keyframes float-up {
  0%   { transform: translateY(100vh) scale(0); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}

/* ── Confetti Canvas ── */
#confetti-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* ── App Container ── */
#app {
  width: 100%;
  max-width: 500px;
  text-align: center;
  position: relative;
  z-index: 1;
}

/* ── Logo ── */
.logo {
  margin-bottom: 24px;
}

.logo-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 4px;
  animation: glow-pulse 2s ease-in-out infinite;
}

.logo h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #38bdf8, #a78bfa, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.tagline {
  color: #64748b;
  font-size: 0.9rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* ── Screens ── */
.screen {
  background: linear-gradient(145deg, #1a1f35, #141827);
  border: 1px solid rgba(56, 189, 248, 0.15);
  border-radius: 16px;
  padding: 32px 24px;
  margin-bottom: 16px;
  box-shadow:
    0 4px 30px rgba(0, 0, 0, 0.4),
    0 0 60px rgba(56, 189, 248, 0.05);
  animation: screen-enter 0.4s ease-out;
}

@keyframes screen-enter {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.screen h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #f1f5f9;
}

.screen-desc {
  color: #94a3b8;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

/* ── Form Stack (vertical form layout) ── */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

/* ── Inputs ── */
input[type="text"],
input[type="number"] {
  background: #0f1629;
  border: 2px solid #2a3050;
  border-radius: 12px;
  color: #e2e8f0;
  padding: 14px 18px;
  font-size: 1rem;
  width: 100%;
  max-width: 300px;
  outline: none;
  transition: all 0.3s ease;
  text-align: center;
}

input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.2);
}

input::placeholder {
  color: #475569;
}

/* ── Buttons ── */
.btn-primary {
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.btn-primary:hover::before {
  left: 100%;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(56, 189, 248, 0.35);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: #2a3050;
  cursor: not-allowed;
  color: #475569;
  box-shadow: none;
  transform: none;
}

.btn-primary:disabled::before {
  display: none;
}

.btn-icon {
  font-size: 1.1rem;
}

/* ── Mute Toggle ── */
.btn-mute {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(26, 31, 53, 0.8);
  border: 1px solid #2a3050;
  color: #94a3b8;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

.btn-mute:hover {
  border-color: #38bdf8;
  color: #38bdf8;
}

.btn-mute.muted {
  color: #475569;
}

/* ── How to Play Button ── */
.btn-rules {
  background: transparent;
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
  transition: all 0.3s ease;
  letter-spacing: 0.5px;
}

.btn-rules:hover {
  background: rgba(56, 189, 248, 0.1);
  border-color: #38bdf8;
}

/* ── Rules Modal ── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-content {
  background: linear-gradient(145deg, #1a1f35, #141827);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  animation: screen-enter 0.3s ease;
}

.modal-close {
  position: absolute;
  top: 12px; right: 16px;
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #e2e8f0;
}

.modal-content h2 {
  text-align: center;
  font-size: 1.3rem;
  color: #38bdf8;
  margin-bottom: 20px;
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rule-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.rule-num {
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.rule-item strong {
  color: #e2e8f0;
  font-size: 0.9rem;
  display: block;
  margin-bottom: 2px;
}

.rule-item p {
  color: #94a3b8;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* ── Error text ── */
.error {
  color: #f87171;
  margin-top: 8px;
  font-size: 0.85rem;
  min-height: 1.2em;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* ── Waiting Screen ── */
.waiting-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.highlight {
  color: #38bdf8;
  font-size: 1.1rem;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #2a3050;
  border-top-color: #38bdf8;
  border-right-color: #a78bfa;
  border-radius: 50%;
  margin: 20px auto 0;
  animation: spin 0.8s linear infinite;
}

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

/* ── Pick Screen ── */
.pick-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.status-text {
  margin-top: 12px;
  color: #94a3b8;
  font-size: 0.9rem;
  min-height: 1.2em;
}

/* ── Scoreboard ── */
.scoreboard {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.score-card {
  background: linear-gradient(145deg, #131830, #0f1225);
  border: 1px solid #2a3050;
  border-radius: 14px;
  padding: 16px 14px 12px;
  flex: 1;
  max-width: 160px;
  transition: all 0.3s ease;
}

.score-card.you {
  border-color: rgba(74, 222, 128, 0.3);
}

.score-card.opponent {
  border-color: rgba(251, 146, 60, 0.3);
}

.score-avatar {
  font-size: 2rem;
  margin-bottom: 4px;
}

.score-card .label {
  display: block;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-card .points {
  display: block;
  font-size: 2.2rem;
  font-weight: 800;
}

.score-card.you .points {
  color: #4ade80;
  text-shadow: 0 0 20px rgba(74, 222, 128, 0.4);
}

.score-card.opponent .points {
  color: #fb923c;
  text-shadow: 0 0 20px rgba(251, 146, 60, 0.4);
}

/* Points health bar */
.points-bar {
  height: 6px;
  background: #1a1f35;
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}

.points-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.you-fill {
  background: linear-gradient(90deg, #4ade80, #22c55e);
}

.opp-fill {
  background: linear-gradient(90deg, #fb923c, #f97316);
}

/* VS badge */
.vs-badge {
  font-size: 1rem;
  font-weight: 800;
  color: #475569;
  background: #1a1f35;
  border: 2px solid #2a3050;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Hint Display (Higher / Lower) ── */
.hint-display {
  font-size: 1.3rem;
  font-weight: 800;
  padding: 12px 20px;
  border-radius: 12px;
  margin-bottom: 16px;
  animation: hint-pop 0.4s ease;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.hint-display.hint-higher {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(56, 189, 248, 0.05));
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.hint-display.hint-lower {
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.15), rgba(251, 146, 60, 0.05));
  color: #fb923c;
  border: 1px solid rgba(251, 146, 60, 0.3);
}

@keyframes hint-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Turn Indicator ── */
#turn-indicator {
  font-size: 1rem;
  margin-bottom: 16px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
}

#turn-indicator.your-turn {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.2);
  animation: glow-pulse 2s ease-in-out infinite;
}

#turn-indicator.waiting-turn {
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.05);
}

@keyframes glow-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

/* ── Guess Feedback ── */
#guess-feedback {
  margin-top: 12px;
  font-size: 0.95rem;
  min-height: 1.2em;
  font-weight: 600;
}

/* ── Guess Log ── */
#guess-log {
  margin-top: 16px;
  max-height: 200px;
  overflow-y: auto;
  text-align: left;
  padding: 0;
}

#guess-log::-webkit-scrollbar {
  width: 4px;
}

#guess-log::-webkit-scrollbar-thumb {
  background: #2a3050;
  border-radius: 2px;
}

#guess-log .log-entry {
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #94a3b8;
  border-radius: 8px;
  margin-bottom: 4px;
  animation: slide-in 0.3s ease;
}

#guess-log .log-entry.my-guess {
  background: rgba(74, 222, 128, 0.05);
  border-left: 3px solid #4ade80;
}

#guess-log .log-entry.opp-guess {
  background: rgba(251, 146, 60, 0.05);
  border-left: 3px solid #fb923c;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Game Over Screen ── */
.gameover-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: trophy-bounce 0.6s ease;
}

@keyframes trophy-bounce {
  0%   { transform: scale(0) rotate(-15deg); }
  60%  { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

#screen-gameover h2 {
  font-size: 2rem;
  font-weight: 800;
}

#screen-gameover .win {
  color: #4ade80;
  text-shadow: 0 0 30px rgba(74, 222, 128, 0.5);
}

#screen-gameover .lose {
  color: #f87171;
  text-shadow: 0 0 30px rgba(248, 113, 113, 0.5);
}

#result-detail {
  margin: 8px 0 16px;
  color: #94a3b8;
  font-size: 0.95rem;
}

#revealed-numbers {
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: #94a3b8;
  background: rgba(255,255,255,0.03);
  padding: 16px;
  border-radius: 10px;
  text-align: left;
}

.reveal-row {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.reveal-row:last-of-type {
  border-bottom: none;
}

.reveal-payout {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(56, 189, 248, 0.2);
  text-align: center;
  color: #fbbf24;
  font-size: 1rem;
}

/* ── Performance Section ── */
.perf-section {
  margin-top: 20px;
  text-align: left;
}

.perf-title {
  text-align: center;
  font-size: 1.1rem;
  color: #38bdf8;
  margin-bottom: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.perf-cards {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.perf-card {
  flex: 1;
  background: linear-gradient(145deg, #131830, #0f1225);
  border: 1px solid #2a3050;
  border-radius: 12px;
  padding: 14px 12px;
}

.perf-card.winner-card {
  border-color: rgba(74, 222, 128, 0.3);
}

.perf-card.loser-card {
  border-color: rgba(248, 113, 113, 0.3);
}

.perf-card .perf-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.perf-card.winner-card .perf-name {
  color: #4ade80;
}

.perf-card.loser-card .perf-name {
  color: #f87171;
}

.perf-stat {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 0.8rem;
  color: #94a3b8;
}

.perf-stat .stat-val {
  color: #e2e8f0;
  font-weight: 600;
}

.perf-subtitle {
  text-align: center;
  font-size: 0.9rem;
  color: #64748b;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.perf-guesses {
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 12px;
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  animation: slide-in 0.3s ease;
}

.timeline-row:last-child {
  border-bottom: none;
}

.timeline-num {
  color: #475569;
  font-size: 0.7rem;
  min-width: 18px;
}

.timeline-name {
  font-weight: 600;
  min-width: 60px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-name.p1-color { color: #4ade80; }
.timeline-name.p2-color { color: #fb923c; }

.timeline-guess {
  color: #e2e8f0;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
}

.timeline-dist {
  color: #64748b;
  font-size: 0.75rem;
}

.timeline-correct {
  color: #4ade80;
  font-weight: 700;
}

/* ── Score Change Animation ── */
.score-bump {
  animation: bump 0.4s ease;
}

@keyframes bump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── Shake animation for wrong guess ── */
.shake-card {
  animation: shake-card 0.5s ease;
}

@keyframes shake-card {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-6px) rotate(-1deg); }
  30%      { transform: translateX(6px) rotate(1deg); }
  45%      { transform: translateX(-4px); }
  60%      { transform: translateX(4px); }
  75%      { transform: translateX(-2px); }
}

/* ── Pulse animation ── */
.pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

/* ── Bounce animation ── */
.bounce {
  animation: bounce 1.5s ease infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

/* ══════════════════════════════════════
   Mobile Responsive
   ══════════════════════════════════════ */

@media (max-width: 520px) {
  body {
    padding: 16px 12px;
  }

  .logo h1 {
    font-size: 1.8rem;
    letter-spacing: 2px;
  }

  .logo-icon {
    font-size: 2.4rem;
  }

  .screen {
    padding: 24px 16px;
    border-radius: 14px;
  }

  .screen h2 {
    font-size: 1.2rem;
  }

  input[type="text"],
  input[type="number"] {
    padding: 12px 14px;
    font-size: 1rem;
    max-width: 100%;
  }

  .btn-primary {
    padding: 14px 24px;
    font-size: 0.95rem;
    max-width: 100%;
  }

  /* Scoreboard stacks better on small screens */
  .scoreboard {
    gap: 8px;
  }

  .score-card {
    padding: 12px 10px 10px;
  }

  .score-avatar {
    font-size: 1.6rem;
  }

  .score-card .points {
    font-size: 1.8rem;
  }

  .vs-badge {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .hint-display {
    font-size: 1.1rem;
    padding: 10px 16px;
  }

  #turn-indicator {
    font-size: 0.9rem;
  }

  .gameover-icon {
    font-size: 3rem;
  }

  #screen-gameover h2 {
    font-size: 1.6rem;
  }
}

/* Very small screens (below 360px) */
@media (max-width: 360px) {
  .logo h1 {
    font-size: 1.5rem;
  }

  .score-card .points {
    font-size: 1.5rem;
  }

  .score-card .label {
    font-size: 0.7rem;
  }
}
