/* ==========================================================================
   Reaction Darts - Stylesheet (Dashboard, Configurator & Gameplay Engine)
   ========================================================================== */

/* ── Design Tokens ─────────────────────────────────────── */
:root {
  --bg-primary: #0a0c14;
  --bg-secondary: #101422;
  --bg-tertiary: #171d30;
  --bg-card: #121626;
  --bg-card-hover: #191f36;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(99, 102, 241, 0.45);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-indigo: #6366f1;
  --accent-indigo-hover: #4f46e5;
  --accent-emerald: #22c55e;
  --accent-rose: #ef4444;
  --accent-amber: #f59e0b;

  --target-red: #dc2626;
  --target-red-glow: rgba(220, 38, 38, 0.4);
  --target-green: #22c55e;
  --target-green-glow: rgba(34, 197, 94, 0.75);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────── */
header.rd-header {
  height: 60px;
  padding: 0 28px;
  background: rgba(16, 20, 34, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-back-hub {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.btn-back-hub:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.rd-title {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Dashboard Container ──────────────────────────────── */
.rd-dashboard-container {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 28px;
  flex: 1;
}

.dashboard-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.header-text h1 {
  font-size: 26px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.header-text p {
  font-size: 13.5px;
  color: var(--text-muted);
}

.btn-create-game {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--accent-indigo);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  transition: all 0.15s ease;
}

.btn-create-game:hover {
  background: var(--accent-indigo-hover);
  transform: translateY(-1px);
}

/* ── Dashboard Games Grid ─────────────────────────────── */
.rd-grid {
  padding-top: 6px;
  padding-bottom: 6px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.rd-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all 0.2s ease;
  position: relative;
}

.rd-card:hover {
  border-color: var(--border-active);
  transform: none;
  box-shadow: 0 16px 36px -10px rgba(99, 102, 241, 0.2);
}

.rd-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rd-card-title {
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
}

.rd-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.rd-card-specs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.spec-item {
  display: flex;
  flex-direction: column;
}

.spec-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.spec-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.rd-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.btn-play {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--accent-emerald);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-play:hover {
  background: #16a34a;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.4);
}

.btn-edit-card,
.btn-delete-card {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-edit-card:hover {
  color: var(--accent-indigo);
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-indigo);
}

.btn-delete-card:hover {
  color: var(--accent-rose);
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-rose);
}

/* ── Modals & Editor Controls ─────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 440px;
  max-width: 95vw;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
  overflow-y: auto !important;
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(88vh - 130px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-body::-webkit-scrollbar {
  width: 6px;
}
.modal-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}
.modal-body::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

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

.form-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-input, select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.form-input:focus, select:focus {
  border-color: var(--accent-indigo);
}

.pill-group {
  display: flex;
  gap: 6px;
}

.pill-option {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.pill-option:hover {
  color: var(--text-primary);
}

.pill-option.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-indigo);
  color: #818cf8;
}

/* ── GAMEPLAY WINDOW LAYOUT ───────────────────────────── */
.game-workspace {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.game-main-area {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-image: 
    radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

.game-sidebar-right {
  width: 320px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-shrink: 0;
}

.attempts-counter-box {
  display: none;
}

/* ── PLAYER TURN & ATTEMPTS SHADING TRACKER ──────────────────── */
.player-turns-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-attempt-card {
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px 14px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: all 0.25s ease;
}

.player-attempt-card.active-turn {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(15, 23, 42, 0.85);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.15), inset 0 0 12px rgba(56, 189, 248, 0.05);
}

.player-turn-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.player-turn-label {
  font-size: 15px;
  font-weight: 800;
  color: #38bdf8;
  font-family: 'Inter', -apple-system, sans-serif;
  letter-spacing: 0.02em;
  text-transform: capitalize;
}

.player-attempt-card:not(.active-turn) .player-turn-label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.turn-badge {
  font-size: 9.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.turn-badge.active {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.turn-badge.done {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.turn-badge.waiting {
  background: rgba(249, 115, 22, 0.1);
  color: #f97316;
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.attempt-boxes-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
}

.attempt-box {
  flex: 1;
  height: 62px;
  min-width: 48px;
  max-width: 80px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  transition: all 0.3s ease;
}

/* 1. GREEN SHADING FOR HIT */
.attempt-box.attempt-box-hit {
  background: repeating-linear-gradient(
    45deg,
    rgba(34, 197, 94, 0.18),
    rgba(34, 197, 94, 0.18) 7px,
    rgba(34, 197, 94, 0.65) 7px,
    rgba(34, 197, 94, 0.65) 14px
  );
  border: 2px solid #22c55e;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.4), inset 0 0 8px rgba(34, 197, 94, 0.2);
}

/* 2. 3-DOT ANIMATION FOR ONGOING (one by one in green) */
.attempt-box.attempt-box-ongoing {
  background: rgba(34, 197, 94, 0.08);
  border: 2px solid #22c55e;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.45), inset 0 0 10px rgba(34, 197, 94, 0.15);
  animation: ongoingBoxPulse 1.8s infinite ease-in-out;
}

@keyframes ongoingBoxPulse {
  0%, 100% {
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.35), inset 0 0 6px rgba(34, 197, 94, 0.1);
    border-color: #22c55e;
  }
  50% {
    box-shadow: 0 0 22px rgba(34, 197, 94, 0.65), inset 0 0 14px rgba(34, 197, 94, 0.25);
    border-color: #4ade80;
  }
}

.ongoing-dots-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  height: 100%;
}

.ongoing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #166534;
  opacity: 0.2;
  transform: scale(0.7);
  animation: dotSequencePulse 1.2s infinite ease-in-out both;
}

.ongoing-dot:nth-child(1) {
  animation-delay: 0s;
}

.ongoing-dot:nth-child(2) {
  animation-delay: 0.25s;
}

.ongoing-dot:nth-child(3) {
  animation-delay: 0.5s;
}

@keyframes dotSequencePulse {
  0%, 100% {
    opacity: 0.2;
    transform: scale(0.7);
    background: #166534;
    box-shadow: none;
  }
  40% {
    opacity: 1;
    transform: scale(1.35);
    background: #22c55e;
    box-shadow: 0 0 10px #22c55e, 0 0 16px rgba(34, 197, 94, 0.9);
  }
}

/* 3. RED SHADING LINES FOR MISS */
.attempt-box.attempt-box-miss {
  background: repeating-linear-gradient(
    45deg,
    rgba(239, 68, 68, 0.18),
    rgba(239, 68, 68, 0.18) 7px,
    rgba(239, 68, 68, 0.65) 7px,
    rgba(239, 68, 68, 0.65) 14px
  );
  border: 2px solid #ef4444;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.35), inset 0 0 8px rgba(239, 68, 68, 0.2);
}

/* 4. UPCOMING ORANGE SHADING */
.attempt-box.attempt-box-upcoming {
  background: repeating-linear-gradient(
    45deg,
    rgba(249, 115, 22, 0.08),
    rgba(249, 115, 22, 0.08) 7px,
    rgba(249, 115, 22, 0.3) 7px,
    rgba(249, 115, 22, 0.3) 14px
  );
  border: 2px solid rgba(249, 115, 22, 0.7);
  box-shadow: 0 0 8px rgba(249, 115, 22, 0.15);
}

.attempts-log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
}

.attempt-log-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.attempt-log-card.success {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}

.attempt-log-card.miss {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.reaction-ms-badge {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-emerald);
}

/* ── 16:9 WIDESCREEN TARGET GRID ──────────────────────── */
.target-grid-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  gap: 8px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  align-items: stretch;
  justify-items: stretch;
}

.target-grid-container.grid-2 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.target-grid-container.grid-3 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.target-grid-container.grid-4 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }

.target-square {
  background: #dc2626;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  box-shadow: none;
  position: relative;
  user-select: none;
  width: 100%;
  height: 100%;
}

.target-grid-container.moving-mode {
  display: block !important;
}

.target-square.moving-square {
  position: absolute !important;
  transition: none !important; /* smooth manual physics animation */
}

.target-square:active {
  transform: scale(0.96);
}

.target-square.active-target {
  background: #22c55e !important;
  box-shadow: none !important;
  border: none !important;
  animation: none !important;
}

@keyframes pulseTarget {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

/* ── FULL-SCREEN COUNTDOWN OVERLAYS ────────────────────── */
.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 20, 0.92);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 500;
  animation: fadeIn 0.2s ease;
}

.countdown-number {
  font-size: clamp(140px, 22vw, 260px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: #38bdf8;
  background: linear-gradient(180deg, #ffffff 0%, #6366f1 50%, #312e81 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 15px 35px rgba(99, 102, 241, 0.6)) drop-shadow(0 6px 0 #0f172a);
  user-select: none;
}

.countdown-number.pop {
  animation: numPopOnce 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes numPopOnce {
  0% { transform: scale(0.6); opacity: 0.3; }
  100% { transform: scale(1); opacity: 1; }
}

.countdown-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Status Banner ────────────────────────────────────── */
.rd-status-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  color: var(--text-primary);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.rd-status-banner.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* Universal Modal & Input Full-Height Fix */
.modal-content {
  max-height: 90vh !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

.modal-body {
  overflow-y: auto !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
}

.form-input {
  box-sizing: border-box !important;
  height: 44px !important;
  line-height: normal !important;
  font-family: inherit !important;
}


/* ========================================================================== */
/* FLAWLESS FULL-HEIGHT SCROLLABLE MODAL SYSTEM                               */
/* ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 13, 0.85);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px 16px;
}

.modal-content {
  background: #0f1424;
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  margin: auto;
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: #0f1424;
}

.modal-body {
  padding: 22px 24px;
  overflow-y: auto !important;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(90vh - 130px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
  background: rgba(10, 14, 26, 0.8);
}

/* Custom Scrollbar on Modal Body */
.modal-body::-webkit-scrollbar {
  width: 7px;
}
.modal-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
}
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 6px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.7);
}

/* Ensure all inner item lists expand naturally without internal nested cutoff */
#balloonsContainer, .bal-sections-wrapper,
#discountsContainer, #discountsList,
#fishesContainer, #fishesList,
#recipesContainer, #recipesList,
#ingredientsContainer, #ingredientsList,
#normalBalloonsList, #specialBalloonsList, #bombBalloonsList {
  max-height: none !important;
  overflow: visible !important;
  height: auto !important;
}

.form-input, input[type="text"].form-input, input[type="number"].form-input {
  box-sizing: border-box;
  height: 44px;
  line-height: normal;
  font-family: inherit;
}

.modal-body > * { flex-shrink: 0; }
