/* ==========================================================================
   Discount Balls - Stylesheet (Cartoony Theme, Configurator & Physics Engine)
   ========================================================================== */

/* ── Design Tokens ─────────────────────────────────────── */
:root {
  --bg-primary: #0b0e17;
  --bg-secondary: #121624;
  --bg-tertiary: #191f33;
  --bg-card: #151928;
  --bg-card-hover: #1c2236;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.2);

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

  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-indigo: #6366f1;
  --accent-rose: #ef4444;

  --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.db-header {
  height: 60px;
  padding: 0 28px;
  background: var(--bg-secondary);
  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);
}

.db-title {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Dashboard Container ──────────────────────────────── */
.db-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;
}

.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-amber);
  color: #0f172a;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
  transition: all 0.15s ease;
}

.btn-create-game:hover {
  background: #d97706;
  color: #ffffff;
  transform: translateY(-1px);
}

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

.db-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.15s ease;
}

.db-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}

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

.db-balls-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  min-height: 54px;
  align-items: center;
}

.ball-tag-pill {
  flex: 1 1 calc(50% - 8px);
  min-width: 80px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 800;
  color: #ffffff;
  border: 2px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  text-align: center;
  white-space: nowrap;
}

.db-card-actions {
  display: flex;
  align-items: center;
  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-amber);
  color: #0f172a;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-play:hover {
  background: #d97706;
  color: #ffffff;
}

.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;
}

.btn-edit-card:hover { color: var(--accent-amber); border-color: var(--accent-amber); }
.btn-delete-card:hover { color: var(--accent-rose); border-color: var(--accent-rose); }

/* ── Modal Controls ───────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  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: 720px;
  max-width: 95vw;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

#ballsContainer::-webkit-scrollbar {
  width: 6px;
}
#ballsContainer::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 4px;
}
#ballsContainer::-webkit-scrollbar-thumb {
  background: rgba(245, 158, 11, 0.4);
  border-radius: 4px;
}
#ballsContainer::-webkit-scrollbar-thumb:hover {
  background: rgba(245, 158, 11, 0.7);
}

.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; }

.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;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-secondary); }
.form-input { width: 100%; padding: 9px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: #ffffff; font-size: 13px; outline: none; }

/* Hide number input spinners */
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* Frameless Color Swatch Picker */
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  padding: 0;
  overflow: hidden;
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 6px;
}
input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

#ballsContainer {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-amber);
}

.ball-config-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.ball-config-row input[type="text"] {
  flex: 1;
}

.ball-size-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.ball-color-picker {
  width: 28px;
  height: 28px;
  border: 2px solid #0f172a;
  border-radius: 50%;
  cursor: pointer;
  outline: none;
  padding: 0;
  background: none !important;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.ball-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 50%;
  background: none;
}

.ball-color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.ball-color-picker::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

.btn-remove-row {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: none;
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-rose);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── GAMEPLAY WORKSPACE ───────────────────────────────── */
.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: stretch;
  justify-content: stretch;
  padding: 0;
  overflow: hidden;
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ── CARTOONY BOUNCING BALLS ──────────────────────────── */
.db-play-area {
  position: relative;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.01);
  border: none;
  border-radius: 0;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.cartoony-ball {
  position: absolute;
  border-radius: 50%;
  border: 6px solid #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6), inset 0 -12px 0 rgba(0, 0, 0, 0.25), inset 0 6px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.08s ease;
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.9);
  text-align: center;
  padding: 6px;
  box-sizing: border-box;
}

.cartoony-ball:active {
  transform: scale(0.92);
}

/* ── SIDEBAR ─────────────────────────────────────────── */
.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(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.1);
}

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

.discount-won-badge {
  font-size: 14px;
  font-weight: 900;
  color: var(--accent-amber);
}

/* ── OVERLAYS ─────────────────────────────────────────── */
.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 14, 23, 0.93);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 500;
}

.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%, #38bdf8 50%, #0284c7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 15px 35px rgba(56, 189, 248, 0.7)) drop-shadow(0 8px 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: 20px;
  font-weight: 800;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
}

/* 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; }
