/* ── MadGorilla Design System ── */
/* Ported from the React/Next.js globals.css to Django templates */

/* ── Design Tokens ── */
:root {
  --mg-black: #080808;
  --mg-black-light: #101010;
  --mg-black-mid: #181818;
  --mg-black-soft: #222222;
  --mg-black-border: #2a2a2a;
  --mg-white: #f5f0eb;
  --mg-white-muted: #a09890;
  --mg-white-dim: #4a4540;
  --mg-red: #e63946;
  --mg-red-bright: #ff3b4a;
  --mg-red-dark: #b82d38;
  --mg-red-wash: rgba(230,57,70,0.08);
  --mg-red-glow: rgba(230,57,70,0.3);
}

/* ── Base Styles ── */
html, body {
  overflow-x: hidden;
  background: var(--mg-black);
  color: var(--mg-white);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  background-image: url("/static/core/characters/background_texture.e82f144a63e3.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--mg-black-border); border-radius: 3px; }

* {
  scrollbar-width: thin;
  scrollbar-color: var(--mg-black-border) transparent;
}

/* ── Keyframes ── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-6px); opacity: 1; }
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

@keyframes redPulse {
  0%, 100% { box-shadow: 0 0 24px rgba(230,57,70,0.3); }
  50% { box-shadow: 0 0 36px rgba(230,57,70,0.3), 0 0 48px rgba(230,57,70,0.12); }
}

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

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

.message-appear {
  animation: fadeSlideIn 0.3s ease-out;
}

.typing-dot {
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

/* ── Grain Texture Overlay ── */
.mg-grain {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  background-repeat: repeat;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.6;
  mix-blend-mode: overlay;
}

/* ── Typography Utilities ── */
.font-space { font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif; }

/* ── Background Gradient Overlay ── */
.mg-bg-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(to bottom, rgba(8,8,8,0.95), rgba(8,8,8,0.85), var(--mg-black));
  pointer-events: none;
}

/* ── Colour Utilities ── */
.mg-text     { color: var(--mg-white); }
.mg-text-muted { color: var(--mg-white-muted); }
.mg-text-dim { color: var(--mg-white-dim); }
.mg-text-red { color: var(--mg-red); }

.mg-bg       { background: var(--mg-black); }
.mg-bg-light { background: var(--mg-black-light); }
.mg-bg-mid   { background: var(--mg-black-mid); }
.mg-bg-soft  { background: var(--mg-black-soft); }

.mg-border   { border-color: var(--mg-black-border); }

/* ── Button Utilities ── */
.mg-btn-red {
  background: var(--mg-red);
  color: #ffffff;
  transition: all 0.2s;
}
.mg-btn-red:hover {
  background: var(--mg-red-bright);
  box-shadow: 0 0 24px var(--mg-red-glow);
}
.mg-btn-red:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.mg-btn-gradient {
  background: linear-gradient(135deg, var(--mg-red), var(--mg-red-dark));
  color: #ffffff;
  box-shadow: 0 4px 20px var(--mg-red-glow);
  transition: all 0.2s;
}
.mg-btn-gradient:hover {
  transform: scale(1.02);
}
.mg-btn-gradient:active {
  transform: scale(0.98);
}

/* ── Card Utilities ── */
.mg-card {
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s;
}
.mg-card:hover {
  box-shadow: inset 0 0 30px rgba(230,57,70,0.15);
}

/* ── Section Card ── */
.mg-section-card {
  background: rgba(24, 24, 24, 0.6);
  border: 1px solid var(--mg-black-border);
  border-radius: 12px;
  padding: 1rem;
}

/* ── Input Styles ── */
.mg-input {
  width: 100%;
  border-radius: 12px;
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  color: var(--mg-white);
  outline: none;
  transition: border-color 0.2s;
}
.mg-input::placeholder {
  color: var(--mg-white-dim);
}
.mg-input:focus {
  border-color: var(--mg-red);
}

.mg-select {
  border-radius: 12px;
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  color: var(--mg-white);
  outline: none;
  transition: border-color 0.2s;
  appearance: none;
}
.mg-select:focus {
  border-color: var(--mg-red);
}

/* ── Label Styles ── */
.mg-label {
  display: block;
  font-size: 0.75rem;
  color: var(--mg-white-dim);
  margin-bottom: 0.25rem;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ── Section Header ── */
.mg-section-header {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--mg-red);
  text-align: center;
}

/* ── Chat Bubble Styles ── */
.mg-bubble-user {
  background: var(--mg-red);
  color: #ffffff;
  border-radius: 20px 20px 4px 20px;
  padding: 0.6875rem 1rem;
  box-shadow: 0 4px 24px rgba(230,57,70,0.2);
  max-width: 78%;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.mg-bubble-assistant {
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
  border-radius: 20px 20px 20px 4px;
  padding: 0.6875rem 1rem;
  color: var(--mg-white);
  max-width: 78%;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ── Chat Input Bar ── */
.mg-chat-input-bar {
  background: var(--mg-black-light);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ── Rage Meter Segments ── */
.mg-rage-segment {
  flex: 1;
  border-radius: 2px;
  height: 4px;
  transition: all 0.4s ease;
}
.mg-rage-segment--filled {
  background: var(--mg-red);
}
.mg-rage-segment--empty {
  background: rgba(42, 42, 42, 0.3);
}
.mg-rage-segment--glow {
  height: 6px;
  box-shadow: 0 0 8px var(--mg-red-glow);
}

/* ── Rage Meter Pulse at 100% ── */
.rage-meter-pulse {
  animation: ragePulse 1s ease-in-out infinite;
}
@keyframes ragePulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.5) drop-shadow(0 0 6px rgba(230,57,70,0.6)); }
}

/* ── Rage Art Banner ── */
.rage-art-banner {
  animation: rageArtIn 0.3s ease-out forwards, rageArtOut 0.4s ease-in 1.5s forwards;
}
@keyframes rageArtIn {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes rageArtOut {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05); }
}

/* ── Modal Overlay ── */
.mg-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: rage-fade-in 0.5s ease;
}

.mg-modal-content {
  max-width: 20rem;
  padding: 1.5rem;
  border-radius: 1.5rem;
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
}

/* ── Character Card ── */
.mg-character-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s;
  border-radius: 16px;
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
}
.mg-character-card:hover {
  box-shadow: inset 0 0 30px rgba(230,57,70,0.15);
}

.mg-character-card .mg-card-image {
  height: 12rem;
  background: var(--mg-black);
  position: relative;
  overflow: hidden;
}
.mg-character-card .mg-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  transition: transform 0.5s;
}
.mg-character-card:hover .mg-card-image img {
  transform: scale(1.1);
}
.mg-character-card .mg-card-image::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 40px 15px rgba(0,0,0,0.6);
  background: linear-gradient(to top, var(--mg-black-mid), transparent);
  pointer-events: none;
}
.mg-character-card:hover .mg-card-image::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(230,57,70,0.1);
  z-index: 1;
  pointer-events: none;
}

.mg-character-card .mg-card-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.mg-character-card .mg-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--mg-white);
}
.mg-character-card .mg-card-desc {
  font-size: 0.875rem;
  color: var(--mg-white-muted);
}

.mg-character-card .mg-card-cta {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  color: var(--mg-red);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.3s;
}
.mg-character-card:hover .mg-card-cta {
  opacity: 1;
  transform: translateY(0);
}

/* ── Legal page prose overrides ── */
.mg-prose h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--mg-white);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}
.mg-prose h3 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--mg-white);
  margin-top: 1rem;
  margin-bottom: 0.375rem;
}
.mg-prose p {
  color: var(--mg-white-muted);
  font-size: 0.875rem;
  line-height: 1.7;
}
.mg-prose a {
  color: var(--mg-red);
  text-decoration: none;
}
.mg-prose a:hover {
  text-decoration: underline;
}
.mg-prose ul {
  color: var(--mg-white-muted);
  font-size: 0.875rem;
  line-height: 1.7;
  padding-left: 1.25rem;
}
.mg-prose li {
  margin-bottom: 0.25rem;
}
.mg-prose strong {
  color: var(--mg-white);
}
.mg-prose table {
  font-size: 0.875rem;
  width: 100%;
  border-collapse: collapse;
}
.mg-prose th {
  text-align: left;
  color: var(--mg-white-dim);
  padding: 0.5rem 1rem 0.5rem 0;
  border-bottom: 1px solid var(--mg-black-border);
  font-weight: 500;
}
.mg-prose td {
  color: var(--mg-white-muted);
  padding: 0.5rem 1rem 0.5rem 0;
  border-bottom: 1px solid rgba(42,42,42,0.3);
}

/* ── Error Pages ── */
.mg-error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
}
.mg-error-code {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 5rem;
  font-weight: 900;
  color: var(--mg-red);
  line-height: 1;
}
.mg-error-text {
  font-size: 1.125rem;
  color: var(--mg-white-muted);
  margin: 1rem 0 2rem;
}
.mg-error-link {
  color: var(--mg-red);
  text-decoration: none;
  font-weight: 600;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--mg-red);
  border-radius: 12px;
  transition: all 0.2s;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.75rem;
}
.mg-error-link:hover {
  background: var(--mg-red-wash);
  box-shadow: 0 0 20px var(--mg-red-glow);
}

/* ── Red Pulse Animation ── */
.mg-red-pulse {
  animation: redPulse 2.5s infinite;
}

/* ── Loading Spinner ── */
.mg-spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--mg-black-border);
  border-top-color: var(--mg-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Skeleton Pulse ── */
.mg-skeleton {
  background: rgba(24, 24, 24, 0.5);
  border-radius: 8px;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Character Grid (unified card layout) ── */
.mg-character-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.mg-grid-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-height: 240px;
  padding: 20px 12px 16px;
  border-radius: 16px;
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.mg-grid-card:hover {
  transform: scale(1.03);
  box-shadow: inset 0 0 30px rgba(230,57,70,0.15);
}

.mg-grid-avatar-wrap {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  background: #000000;
  border: 2px solid #2a2a2a;
  flex-shrink: 0;
  margin-bottom: 12px;
  background: #000000;
  border: 2px solid #2a2a2a;
}

.mg-grid-avatar-img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  object-position: center;
  border-radius: 50%;
  display: block;
}

.mg-grid-avatar-fallback {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e63946, #181818);
  color: #ffffff;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
}

.mg-grid-avatar-random {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e63946, #b82d38);
  color: #ffffff;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 48px;
  font-weight: 800;
  line-height: 1;
}

.mg-grid-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--mg-white);
  margin-bottom: 4px;
  line-height: 1.3;
}

.mg-grid-card-desc {
  font-size: 13px;
  color: #a09890;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Theme Tabs ── */
.mg-theme-tabs-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mg-theme-tabs-wrap::-webkit-scrollbar {
  display: none;
}
.mg-theme-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  min-width: max-content;
}
.mg-theme-tab {
  padding: 8px 20px;
  border-radius: 8px;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mg-white-muted);
  background: var(--mg-black-mid);
  border: 1px solid var(--mg-black-border);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.mg-theme-tab:hover {
  color: var(--mg-white);
  border-color: var(--mg-white-dim);
}
.mg-theme-tab--active {
  color: #ffffff;
  background: var(--mg-red);
  border-color: var(--mg-red);
}
.mg-theme-tab--active:hover {
  color: #ffffff;
  background: var(--mg-red-bright);
  border-color: var(--mg-red-bright);
}

/* ── Theme Badge on Cards ── */
.mg-grid-card-theme {
  margin-top: auto;
  padding-top: 8px;
  font-size: 10px;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mg-white-dim);
}

/* ── Responsive Helpers ── */
@media (max-width: 640px) {
  .mg-modal-content {
    margin: 0 1rem;
  }
  .mg-character-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Background texture */
.mg-brick-bg {
  background-color: #080808;
  background-image: url("../images/background_texture.e82f144a63e3.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
}
.mg-brick-bg::after {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 8, 0.85);
  pointer-events: none;
  z-index: 0;
}
.mg-brick-bg > * {
  position: relative;
  z-index: 1;
}
