/* 1. RESET & BASE */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --bq-text-scale-factor: 1;
}

html { font-size: calc(100% * var(--bq-text-scale-factor)); }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text-main);
  background: var(--bg-app);
  background-image: var(--texture-overlay);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.1;
}

a { color: inherit; text-decoration: none; }

.bq-muted { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Bootstrap-compat utilities (project-owned)
   These exist because templates historically used Bootstrap classes, but
   Bootstrap itself is not shipped.
   -------------------------------------------------------------------------- */
.is-hidden,
.d-none {
  display: none !important;
}

.d-flex { display: flex !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-end { justify-content: flex-end !important; }
.align-items-center { align-items: center !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-baseline { align-items: baseline !important; }
.align-items-end { align-items: flex-end !important; }
.align-self-end { align-self: flex-end !important; }

.text-center { text-align: center !important; }
.text-uppercase { text-transform: uppercase !important; letter-spacing: 0.06em; }
.small { font-size: 0.875rem !important; }
.fw-bold { font-weight: 700 !important; }
.fw-semibold { font-weight: 600 !important; }
.fs-5 { font-size: 1.25rem !important; }
.font-monospace { font-family: var(--font-hud, ui-monospace, SFMono-Regular, Menlo, monospace) !important; }

.text-muted { color: var(--text-muted) !important; }
.text-primary { color: var(--color-primary) !important; }
.text-danger { color: var(--color-danger) !important; }
.text-success { color: var(--color-success) !important; }
.text-warning { color: var(--neon-orange, #ff9d00) !important; }
.text-info { color: var(--color-primary) !important; }
.text-white { color: #fff !important; }
.text-dark { color: var(--text-invert) !important; }

.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.me-1 { margin-right: 0.25rem !important; }
.me-2 { margin-right: 0.5rem !important; }
.ms-1 { margin-left: 0.25rem !important; }
.ms-3 { margin-left: 1rem !important; }

.p-3 { padding: 1rem !important; }
.p-4 { padding: 1.5rem !important; }
.px-3 { padding-left: 1rem !important; padding-right: 1rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-5 { padding-top: 3rem !important; padding-bottom: 3rem !important; }

/* Responsive padding helpers used by templates */
@media (min-width: 768px) {
  .p-md-5 { padding: 3rem !important; }
}

.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }
.gap-4 { gap: 1.5rem !important; }

.position-relative { position: relative !important; }
.position-absolute { position: absolute !important; }
.top-0 { top: 0 !important; }
.end-0 { right: 0 !important; }
.translate-middle { transform: translate(50%, -50%) !important; }
.rounded-circle { border-radius: 9999px !important; }
.rounded { border-radius: var(--radius-lg) !important; }
.rounded-pill { border-radius: 9999px !important; }

.shadow-sm { box-shadow: var(--shadow-card) !important; }

.shadow-lg { box-shadow: var(--shadow-card) !important; }

.border { border: 1px solid var(--border-subtle) !important; }
.border-danger { border-color: rgba(239, 68, 68, 0.45) !important; }

.img-fluid { max-width: 100%; height: auto; }
.list-unstyled { list-style: none; padding-left: 0; margin: 0; }

.text-end { text-align: end !important; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.d-inline { display: inline !important; }

/* Typography helpers */
.lead { font-size: 1.125rem !important; line-height: 1.5 !important; }
.display-4 { font-size: 2.25rem !important; line-height: 1.05 !important; }
@media (min-width: 768px) {
  .display-4 { font-size: 3rem !important; }
}

/* Radius helpers */
.rounded-4 { border-radius: var(--radius-xl, 1.25rem) !important; }

/* Button sizing */
.btn-lg { padding: 0.75rem 1.15rem !important; border-radius: var(--radius-lg) !important; font-weight: 700 !important; }

.bg-primary { background: rgba(0, 243, 255, 0.16) !important; }
.bg-danger { background: rgba(239, 68, 68, 0.18) !important; }
.bg-success { background: rgba(34, 197, 94, 0.18) !important; }
.bg-warning { background: rgba(255, 157, 0, 0.18) !important; }
.bg-info { background: rgba(0, 243, 255, 0.16) !important; }
.bg-secondary { background: rgba(255, 255, 255, 0.1) !important; }
.bg-dark { background: rgba(0, 0, 0, 0.35) !important; }

.bg-opacity-10 { --bq-bg-opacity: 0.10; }
.bg-opacity-25 { --bq-bg-opacity: 0.25; }
.bg-opacity-50 { --bq-bg-opacity: 0.50; }
.bg-opacity-75 { --bq-bg-opacity: 0.75; }

.bg-light { background: rgba(255, 255, 255, var(--bq-bg-opacity, 0.08)) !important; }
.bg-light-subtle { background: rgba(255, 255, 255, 0.06) !important; }
.bg-primary-subtle { background: rgba(0, 243, 255, 0.10) !important; }
.bg-danger-subtle { background: rgba(239, 68, 68, 0.10) !important; }
.bg-secondary-subtle { background: rgba(255, 255, 255, 0.06) !important; }

/* list-group (minimal) */
.list-group { display: flex; flex-direction: column; padding-left: 0; margin: 0; border-radius: var(--radius-lg); }
.list-group-item {
  list-style: none;
  padding: 0.75rem 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.03);
}
.list-group-item:first-child { border-top: 0; }
.list-group-flush { border-radius: 0; }
.list-group-flush .list-group-item { border-radius: 0; }

.btn-sm { padding: 0.35rem 0.7rem !important; border-radius: var(--radius-md) !important; }
.btn-outline-light {
  background: transparent !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  color: rgba(255, 255, 255, 0.92) !important;
}
.btn-outline-light:hover {
  border-color: rgba(0, 243, 255, 0.42) !important;
  box-shadow: 0 0 0 1px rgba(0, 243, 255, 0.18);
}

.btn-outline-primary {
  background: transparent !important;
  border: 1px solid rgba(0, 243, 255, 0.35) !important;
  color: rgba(0, 243, 255, 0.92) !important;
}
.btn-outline-primary:hover {
  border-color: rgba(0, 243, 255, 0.65) !important;
  box-shadow: 0 0 0 1px rgba(0, 243, 255, 0.18);
}

.btn-outline-danger {
  background: transparent !important;
  border: 1px solid rgba(239, 68, 68, 0.45) !important;
  color: rgba(239, 68, 68, 0.92) !important;
}
.btn-outline-danger:hover {
  border-color: rgba(239, 68, 68, 0.75) !important;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.18);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.10) !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  color: rgba(255, 255, 255, 0.92) !important;
}
.btn-danger {
  background: rgba(239, 68, 68, 0.85) !important;
  border: 1px solid rgba(239, 68, 68, 0.55) !important;
  color: #fff !important;
}

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text-main);
}
.form-control-sm { padding: 0.4rem 0.65rem; font-size: 0.875rem; }

.form-label {
  display: inline-block;
  font-weight: 600;
}

.progress {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: rgba(0, 243, 255, 0.55);
}

/* --------------------------------------------------------------------------
   Bootstrap-compat layout (project-owned)
   Enough for the game dashboard templates without shipping Bootstrap.
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.row {
  --bs-gutter-x: 1rem;
  --bs-gutter-y: 1rem;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--bs-gutter-x);
  row-gap: var(--bs-gutter-y);
}

.g-2 { --bs-gutter-x: 0.5rem; --bs-gutter-y: 0.5rem; }
.g-3 { --bs-gutter-x: 1rem; --bs-gutter-y: 1rem; }
.g-4 { --bs-gutter-x: 1.5rem; --bs-gutter-y: 1.5rem; }

.col-12 { grid-column: span 12; }

.col-lg-4,
.col-lg-8,
.col-md-4,
.col-md-6,
.col-md-8,
.col-xl-4 {
  grid-column: span 12;
}

@media (min-width: 768px) {
  .col-md-4 { grid-column: span 4; }
  .col-md-6 { grid-column: span 6; }
  .col-md-8 { grid-column: span 8; }
}

@media (min-width: 992px) {
  .col-lg-4 { grid-column: span 4; }
  .col-lg-8 { grid-column: span 8; }
}

@media (min-width: 1200px) {
  .col-xl-4 { grid-column: span 4; }
}

.table-responsive { width: 100%; overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.table thead th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.table-striped tbody tr:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

.align-middle th,
.align-middle td {
  vertical-align: middle;
}

/* Shared inline SVG sizing for UI icons */
.ui-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex: 0 0 auto;
}

/* 2. LAYOUT UTILITIES */
.bq-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

.bq-grid {
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .bq-grid--2 { grid-template-columns: repeat(2, 1fr); }
  .bq-grid--4 { grid-template-columns: repeat(4, 1fr); }
}

/* 2b. PAGE: GAME DASHBOARD */
body.page-dashboard .dashboard-container {
  padding-bottom: 100px;
}

/* 3. COMPONENT: CARDS */
.card, .bq-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

/* 4. COMPONENT: BUTTONS */
.btn, .bq-btn, .bq-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform var(--ease-spring), box-shadow 0.2s;
  background: var(--bg-surface-alt);
  color: var(--text-main);
}

/* Primary Action */
.btn-primary, .bq-cta {
  background: var(--color-primary);
  color: var(--text-invert);
  box-shadow: 0 4px 14px var(--color-primary-glow);
}

.btn-primary:hover, .bq-cta:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-subtle);
}

/* 5. COMPONENT: NAVIGATION (Consolidated) */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  padding: var(--space-sm) 0;
}

.app-nav ul {
  display: flex;
  gap: var(--space-md);
  list-style: none;
  padding: 0;
  margin: 0;
}

.app-nav a:hover {
  color: var(--color-primary);
}

/* 6. GAME SPECIFIC (HUD) */
/* Retaining specific game HUD layouts but using variables */
.bq-main-nav--hud {
  background: var(--bg-surface-alt);
  border-bottom: 2px solid var(--color-primary);
  padding: var(--space-xs);
}

/* 7. UTILITIES (Toasts, Spinners) */
.bq-toast {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  border-left: 4px solid var(--color-primary);
}

/* 8. MODALS (Settings / Generic) */
.bq-hidden { display: none !important; }

.bq-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.bq-modal {
  width: min(560px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-lg);
  max-height: min(86vh, 820px);
  overflow: auto;
}

.bq-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.bq-modal__title {
  margin: 0;
}

.bq-modal__row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 0.5rem 0;
}

.bq-modal__row label { font-weight: 600; }

.bq-modal__hint {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.bq-modal__control {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 180px;
  justify-content: flex-end;
}

.bq-modal__value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 6px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  font-weight: 700;
}

.bq-modal__row-inline {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.bq-modal__toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.bq-modal input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
}

.bq-modal--settings .bq-modal__header {
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  padding: 0 0 var(--space-md) 0;
  z-index: 1;
}

.bq-modal__footer--sticky {
  position: sticky;
  bottom: 0;
  background: var(--bg-surface);
  padding-top: var(--space-md);
}

.bq-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.bq-settings-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 14px 0;
}

.bq-settings-section__title {
  margin: 0 0 6px 0;
  font-size: 1rem;
  font-weight: 800;
}

.bq-settings-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: flex-end;
}

.bq-settings-form__row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 280px;
}

.bq-settings-form__label {
  font-weight: 700;
}

.bq-settings-form__input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  color: var(--text-main);
}

.bq-settings-form__input:disabled {
  opacity: 0.6;
}

/* Small info button used to open stage/help modals. */
.bq-info-btn {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  color: var(--text-main);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.bq-info-btn:hover {
  filter: brightness(0.98);
}

.bq-info-btn:focus-visible {
  outline: 3px solid rgba(0, 220, 255, 0.55);
  outline-offset: 2px;
}

.bq-stage-info-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bq-stage-info-item__title {
  font-weight: 800;
}

.bq-stage-info-item__desc {
  margin-top: 4px;
}

.bq-account-meta {
  padding: 10px 0 14px 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 14px;
}

.bq-account-meta__avatar {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  margin-bottom: 10px;
}

.bq-account-meta__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bq-account-meta__name {
  font-weight: 800;
}

.bq-account-meta__email {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.bq-account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* 9. ACCESSIBILITY */
.bq-text-large { font-size: 112.5%; }
html[data-text-scale="120"] { font-size: 120%; }
html[data-text-scale="135"] { font-size: 135%; }

.bq-high-contrast body,
.bq-high-contrast .card,
.bq-high-contrast .bq-card,
.bq-high-contrast .btn,
.bq-high-contrast .bq-cta,
.bq-high-contrast .bq-nav-btn--hud {
  filter: none;
  background-color: #0c0c0c;
  color: #fdfdfd;
  border-color: #ffffff;
  box-shadow: 0 0 0 2px #ffffff, 0 12px 22px rgba(0, 0, 0, 0.45);
}

.bq-high-contrast a:focus-visible,
.bq-high-contrast button:focus-visible,
.bq-high-contrast .btn:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: 2px;
}

html[data-color-profile="protan"] {
  --color-primary: #5e9bff;
  --color-primary-glow: rgba(94, 155, 255, 0.35);
  --color-danger: #7c3aed;
  --color-success: #3cbf8a;
  --neon-blue: #5e9bff;
  --neon-orange: #f59e0b;
}

html[data-color-profile="deutan"] {
  --color-primary: #4fd1c5;
  --color-primary-glow: rgba(79, 209, 197, 0.35);
  --color-danger: #9f7aea;
  --color-success: #2dd4bf;
  --neon-blue: #4fd1c5;
  --neon-orange: #f59e0b;
}

html[data-color-profile="tritan"] {
  --color-primary: #f472b6;
  --color-primary-glow: rgba(244, 114, 182, 0.35);
  --color-danger: #0ea5e9;
  --color-success: #10b981;
  --neon-blue: #0ea5e9;
  --neon-orange: #fbbf24;
}

html[data-color-profile] .progress-fill,
html[data-color-profile] .status-effect__bar span {
  background-image: linear-gradient(135deg, var(--color-primary), var(--color-danger));
  background-size: 16px 16px, auto;
  background-repeat: repeat, no-repeat;
  mask-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.9) 0,
    rgba(255, 255, 255, 0.9) 8px,
    rgba(255, 255, 255, 0.5) 8px,
    rgba(255, 255, 255, 0.5) 16px
  );
  -webkit-mask-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.9) 0,
    rgba(255, 255, 255, 0.9) 8px,
    rgba(255, 255, 255, 0.5) 8px,
    rgba(255, 255, 255, 0.5) 16px
  );
}

html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation-duration: 0s !important;
  transition-duration: 0s !important;
  scroll-behavior: auto !important;
}

html[data-reduce-motion="true"] body.bq-screen-shake,
html[data-reduce-motion="true"] body.bq-hit-stop {
  animation: none !important;
}

html[data-reduce-motion="true"] .bq-nav-btn__icon,
html[data-reduce-motion="true"] .bq-nav-btn--hud,
html[data-reduce-motion="true"] .bq-card {
  filter: none !important;
  box-shadow: none !important;
}


.spinner {
  width: 1em; height: 1em;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
