:root {
  color-scheme: dark;
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --text-primary: #FDFCFB;
  --text-secondary: rgba(253, 252, 251, 0.75);
  --accent-primary: #00e5ff;
  --accent-secondary: #0099cc;
  --accent-glow: rgba(0, 229, 255, 0.4);
  --border-color: rgba(0, 229, 255, 0.2);
  --border-hover: rgba(0, 229, 255, 0.5);
  --glass-bg: rgba(253, 252, 251, 0.04);
  --glass-hover: rgba(253, 252, 251, 0.08);
  --card-bg: rgba(10, 10, 10, 0.6);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; color-scheme: dark; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  min-height: 100vh;
  color: var(--text-primary);
  overflow-x: hidden;
  line-height: 1.5;
  color-scheme: dark;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--bg-primary);
  filter: none;
  overflow: hidden;
}

.bg-gradient::before,
.bg-gradient::after {
  content: '';
  position: absolute;
  inset: 0;
  animation: gradientFloat 25s ease-in-out infinite;
}

.bg-gradient::before {
  background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 153, 204, 0.25) 0%, transparent 50%);
}

.bg-gradient::after {
  background:
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(0, 229, 255, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse 40% 30% at 10% 80%, rgba(0, 153, 204, 0.1) 0%, transparent 50%);
  animation-delay: -12.5s;
}

@keyframes gradientFloat {
  0%, 100% { opacity: 0.4; transform: translateY(0px) scale(1); }
  20% { opacity: 0.6; transform: translateY(-40px) scale(1.05); }
  40% { opacity: 0.5; transform: translateY(-80px) scale(1.1); }
  60% { opacity: 0.55; transform: translateY(-40px) scale(1.08); }
  80% { opacity: 0.45; transform: translateY(-20px) scale(1.02); }
}

.bg-noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  filter: none;
  mix-blend-mode: overlay;
}

.page-wrapper {
  min-height: 100vh;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(0.75rem, 3vw, 1.5rem);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.alerts-container {
  width: 100%;
  max-width: 600px;
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.page-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  transition: color 0.25s ease;
  position: relative;
}

.back-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 20px; /* Start after the arrow icon */
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.back-link:hover::after {
  transform: scaleX(1);
  transform-origin: left;
}

.back-link:hover { color: var(--accent-primary); }

.back-link svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  transition: transform 0.25s ease;
}

.back-link:hover svg {
  transform: translateX(-3px);
}

.page-header h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #00e5ff, #7c6bf5, #9146ff, #7c6bf5, #00e5ff);
  background-size: 300% 300%;
  animation: textShift 8s ease infinite;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.page-header p {
  font-size: clamp(0.85rem, 2.5vw, 0.95rem);
  color: var(--text-secondary);
}

/* Section header - unified glassmorphism style */
.section-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: clamp(0.65rem, 2vw, 0.7rem);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent-primary);
  margin: 2rem 0 0.75rem;
  padding: 0.75rem 1rem;
  font-weight: 600;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  position: sticky;
  top: 0.5rem;
  z-index: 10;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
}

.section-title:hover {
  border-color: var(--border-hover);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.1);
}

/* Tooltip for section notes */
.section-tooltip-wrapper {
  position: relative;
  margin-left: auto;
}

.section-tooltip-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.6rem;
  font-weight: 700;
  cursor: help;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.section-tooltip-trigger:hover,
.section-tooltip-trigger:focus {
  border-color: var(--border-hover);
  color: var(--accent-primary);
}

.section-tooltip-trigger:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.section-tooltip-trigger .tooltip-icon {
  font-size: 0.55rem;
  opacity: 0.7;
}

.section-tooltip {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: max-content;
  max-width: 280px;
  padding: 0.75rem 1rem;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-primary);
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
  z-index: 20;
  pointer-events: none;
}

/* Desktop: hover/focus */
@media (hover: hover) {
  .section-tooltip-trigger:hover + .section-tooltip,
  .section-tooltip-trigger:focus + .section-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

/* Mobile: toggle via JS class */
.section-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

/* Remove old section-note since it's now a tooltip */
.section-note {
  display: none;
}

/* Copied toast */
.copy-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px) scale(0.95);
  padding: 0.6rem 1.2rem;
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.15), rgba(145, 70, 255, 0.15));
  border: 1px solid rgba(0, 229, 255, 0.4);
  border-radius: 10px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}

.copy-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}


.copy-toast code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: rgba(0, 229, 255, 0.12);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-left: 0.3rem;
}

/* Alert list */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

.alert-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  /* Scroll entrance: start hidden */
  opacity: 0;
  transform: translateY(16px);
}

/* Only promote to compositor layer during interaction */
.alert-item:hover {
  will-change: transform;
}

.alert-item.visible {
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 0.45s ease-out,
    transform 0.15s ease-out,
    background 0.2s ease,
    border-color 0.2s ease;
}

.alert-item:hover:not(.multistack) {
  background: rgba(30, 30, 30, 0.9);
  border-color: var(--border-hover);
}

/* Touch press feedback (applied via JS) */
.alert-item.pressing {
  transform: scale(0.97) !important;
  transition: transform 0.1s ease-out;
}

/* Brief flash on copy */
.alert-item.copied {
  border-color: rgba(0, 229, 255, 0.6);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.15);
}

/* Checkmark icon on copy (non-multistack only, multistack uses ::before for glow) */
.alert-item:not(.multistack)::before {
  content: '✓';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%) scale(0);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-primary);
  opacity: 0;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  z-index: 3;
  pointer-events: none;
}

.alert-item:not(.multistack).copied::before {
  transform: translateY(-50%) scale(1);
  opacity: 1;
}

.alert-amount {
  font-weight: 700;
  font-size: clamp(0.875rem, 2.5vw, 0.95rem);
  color: var(--accent-primary);
  min-width: clamp(2.5rem, 8vw, 3.5rem);
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.alert-separator {
  width: 1px;
  height: 1.25rem;
  background: var(--border-color);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.alert-name {
  font-size: clamp(0.825rem, 2.5vw, 0.9rem);
  font-weight: 500;
  color: var(--text-primary);
  position: relative;
  z-index: 2;
}

/* ========== MULTISTACK PALETTE ========== */
/* Twitch purple: #9146ff  |  DesertIce cyan: #00e5ff */

/* ========== MULTISTACK ROW ========== */
.alert-item.multistack {
  border-color: transparent;
  background:
    linear-gradient(var(--bg-primary), var(--bg-primary)) padding-box,
    linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff) border-box;
  background-size: 100% 100%, 400% 400%;
  animation: borderShift 8s linear infinite;
  position: relative;
}

/* Outer glow behind the row */
.alert-item.multistack::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 12px;
  background: linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff);
  background-size: 400% 400%;
  animation: borderShift 8s linear infinite;
  opacity: 0.2;
  filter: blur(12px);
  z-index: -1;
  transition: opacity 0.35s ease, filter 0.35s ease;
}

/* Mouse-tracking spotlight (positioned via JS custom properties) */
.alert-item.multistack::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: radial-gradient(
    circle 120px at var(--mouse-x, 50%) var(--mouse-y, 50%),
    rgba(0, 229, 255, 0.12) 0%,
    rgba(145, 70, 255, 0.06) 40%,
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 1;
}

.alert-item.multistack:hover::after {
  opacity: 1;
}

.alert-item.multistack:hover {
  background:
    linear-gradient(var(--bg-secondary), var(--bg-secondary)) padding-box,
    linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff) border-box;
  background-size: 100% 100%, 400% 400%;
  border-color: transparent;
  box-shadow: none;
}

.alert-item.multistack:hover::before {
  opacity: 0.5;
  filter: blur(18px);
}

@keyframes borderShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Separator picks up the gradient */
.alert-item.multistack .alert-separator {
  background: linear-gradient(180deg, #00e5ff, #9146ff);
  opacity: 0.6;
  width: 2px;
  border-radius: 1px;
}

/* ========== SHARED STACK ICON ========== */
.stack-icon {
  display: inline-flex;
  flex-shrink: 0;
  position: relative;
}

.stack-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.stack-icon .layer-top {
  animation: layerFloat 2.8s ease-in-out infinite;
  transition: transform 0.3s ease;
}

.stack-icon .layer-mid {
  animation: layerFloat 2.8s ease-in-out 0.2s infinite;
  transition: transform 0.3s ease;
}

.stack-icon .layer-bot {
  transition: transform 0.3s ease;
}

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

/* Layers fan out on row hover */
.alert-item.multistack:hover .stack-icon .layer-top {
  animation: none;
  transform: translateY(-2px);
}

.alert-item.multistack:hover .stack-icon .layer-mid {
  animation: none;
  transform: translateY(-0.5px);
}

.alert-item.multistack:hover .stack-icon .layer-bot {
  transform: translateY(1.5px);
}

/* ========== SHARED BADGE BASE ========== */
.multi-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(rgba(14, 14, 14, 0.92), rgba(14, 14, 14, 0.92)) padding-box,
    linear-gradient(135deg, #00e5ff, #9146ff) border-box;
  border: 1px solid transparent;
}

/* Shimmer sweep */
.multi-badge::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -100%;
  width: 60%;
  height: 200%;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgba(145, 70, 255, 0.08) 42%,
    rgba(255, 255, 255, 0.18) 50%,
    rgba(0, 229, 255, 0.08) 58%,
    transparent 65%
  );
  animation: shimmerSweep 3.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes shimmerSweep {
  0%   { transform: translateX(-50%) rotate(18deg); }
  100% { transform: translateX(300%) rotate(18deg); }
}

/* Gradient text */
.multi-badge .badge-text {
  font-weight: 800;
  text-transform: uppercase;
  background: linear-gradient(135deg, #00e5ff, #7c6bf5, #9146ff);
  background-size: 200% 200%;
  animation: textShift 5s ease infinite;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
  z-index: 1;
}

@keyframes textShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ========== ROW BADGE (right-aligned in alert rows) ========== */
.multistack-badge {
  margin-left: auto;
  padding: 0.25rem 0.6rem;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.multistack-badge .stack-icon {
  width: 14px;
  height: 14px;
}

.multistack-badge .badge-text {
  font-size: 0.58rem;
  letter-spacing: 0.1em;
}

/* Hover intensifies */
.alert-item.multistack:hover .multistack-badge {
  background:
    linear-gradient(rgba(14, 14, 14, 0.8), rgba(14, 14, 14, 0.8)) padding-box,
    linear-gradient(135deg, #00e5ff, #9146ff) border-box;
  box-shadow:
    0 0 10px rgba(145, 70, 255, 0.2),
    0 0 20px rgba(0, 229, 255, 0.1);
}

/* ========== LEGEND BADGE (inline in section note) ========== */
.legend-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  vertical-align: middle;
}

.legend-badge .stack-icon {
  width: 12px;
  height: 12px;
}

.legend-badge .badge-text {
  font-size: 0.55rem;
  letter-spacing: 0.1em;
}

/* Footer */
.footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  position: relative;
  text-align: center;
}

/* Gradient border separator */
.footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 60%);
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    rgba(0, 229, 255, 0.3) 20%,
    rgba(145, 70, 255, 0.3) 50%,
    rgba(0, 229, 255, 0.3) 80%,
    transparent
  );
}

.footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.25s ease, text-shadow 0.25s ease;
  padding: 0.5rem 1rem;
  display: inline-block;
  position: relative;
}

.footer a:hover {
  color: var(--accent-primary);
  text-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
}

/* Responsive */
@media (max-width: 480px) {
  .alert-item {
    padding: 0.75rem 0.875rem;
    gap: 0.625rem;
    min-height: 48px;
  }

  .multistack-badge {
    padding: 0.2rem 0.45rem;
    gap: 0.25rem;
  }

  .multistack-badge .stack-icon {
    width: 12px;
    height: 12px;
  }

  .multistack-badge .badge-text {
    font-size: 0.5rem;
  }

  .section-title {
    padding: 0.6rem 0.875rem;
  }

  .section-tooltip-trigger {
    padding: 0.2rem 0.4rem;
  }

  .section-tooltip-trigger .stack-icon {
    width: 10px;
    height: 10px;
  }

  .section-tooltip {
    max-width: 240px;
    font-size: 0.8rem;
    /* Position from left on mobile to avoid edge cutoff */
    right: auto;
    left: 0;
  }
}

/* Touch devices: disable hover glow, rely on press feedback */
@media (hover: none) {
  .alert-item:hover {
    background: var(--glass-bg);
    border-color: var(--border-color);
  }

  .alert-item.multistack:hover {
    background:
      linear-gradient(var(--bg-primary), var(--bg-primary)) padding-box,
      linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff) border-box;
    background-size: 100% 100%, 400% 400%;
  }

  .alert-item.multistack:hover::before {
    opacity: 0.2;
    filter: blur(12px);
  }

  .alert-item.multistack:hover::after { opacity: 0; }

  .alert-item.multistack:hover .multistack-badge {
    box-shadow: none;
  }

  /* Active press state for touch */
  .alert-item:active {
    transform: scale(0.97);
    transition: transform 0.08s ease-out;
  }

  .alert-item.multistack:active::before {
    opacity: 0.45;
    filter: blur(16px);
  }
}

/* Accessibility */
a:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }

/* Skip link - visible only on focus */
.skip-link {
  position: fixed;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.5rem;
  background: var(--bg-primary);
  border: 2px solid var(--accent-primary);
  border-radius: 8px;
  color: var(--accent-primary);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  z-index: 1000;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 1rem;
  outline: none;
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles for alert items */
.alert-item:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
  transform: scale(1.02);
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.2);
  z-index: 5;
}

.alert-item.multistack:focus-visible {
  outline-offset: 4px;
}

/* Focus styles for other interactive elements */
.back-link:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 4px;
}

.footer a:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 4px;
}

/* Pause animations when off-screen for performance */
.alert-item.animation-paused,
.alert-item.animation-paused::before,
.alert-item.animation-paused::after,
.alert-item.animation-paused .multi-badge::after,
.alert-item.animation-paused .stack-icon .layer {
  animation-play-state: paused !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  /* Ensure items are visible even without entrance animation */
  .alert-item {
    opacity: 1 !important;
    transform: none !important;
  }

  /* Disable focus scale */
  .alert-item:focus-visible {
    transform: none !important;
  }

  /* Disable slide-in animations */
  .twitch-section.is-live,
  .alerts-container:has(.twitch-section.is-live) .alerts-section {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

.bg-gradient, .bg-noise { isolation: isolate; }

/* ========== CONTENT LAYOUT (WIDESCREEN) ========== */
.content-layout {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Widescreen: side-by-side layout only when live */
@media (min-width: 1024px) {
  /* Use :has() to detect if twitch section is visible */
  .alerts-container:has(.twitch-section.is-live) {
    max-width: 1400px;
  }

  .alerts-container:has(.twitch-section.is-live) .content-layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 2rem;
  }

  .twitch-section.is-live {
    position: sticky;
    top: 1.5rem;
    flex: 1 1 600px;
    max-width: 700px;
    /* Slide in from left */
    animation: slideInLeft 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .alerts-container:has(.twitch-section.is-live) .alerts-section {
    flex: 0 0 340px;
    min-width: 280px;
    /* Slide in from right with delay */
    animation: slideInRight 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.15s both;
  }

  /* Remove top margin on first section title so alerts align with twitch header */
  .alerts-container:has(.twitch-section.is-live) .alerts-section section:first-child .section-title {
    margin-top: 0;
  }

  @keyframes slideInLeft {
    from {
      opacity: 0;
      transform: translateX(-30px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  @keyframes slideInRight {
    from {
      opacity: 0;
      transform: translateX(30px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }
}

@media (min-width: 1400px) {
  .alerts-container:has(.twitch-section.is-live) {
    max-width: 1600px;
  }

  .twitch-section.is-live {
    flex: 1 1 800px;
    max-width: 900px;
  }

  .alerts-container:has(.twitch-section.is-live) .alerts-section {
    flex: 0 0 400px;
  }

  .alerts-container:has(.twitch-section.is-live) .alerts-section section:first-child .section-title {
    margin-top: 0;
  }
}

/* ========== TWITCH EMBED SECTION ========== */
/* Hide entire section when offline */
.twitch-section {
  display: none;
  margin-bottom: 0;
}

.twitch-section.is-live {
  display: block;
}

.twitch-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-bottom: 0.75rem;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  position: relative;
}

.twitch-header:hover {
  border-color: var(--border-hover);
}

.twitch-header:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Collapse toggle icon - mobile only by default */
.twitch-collapse-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-left: auto;
  color: var(--text-secondary);
  transition: transform 0.3s ease;
}

.twitch-collapse-icon svg {
  width: 20px;
  height: 20px;
}

.twitch-header[aria-expanded="false"] .twitch-collapse-icon {
  transform: rotate(-90deg);
}

/* Collapsed state with smooth animation */
.twitch-embed-wrapper {
  transition: grid-template-rows 0.3s ease, opacity 0.3s ease;
  display: grid;
  grid-template-rows: 1fr;
}

.twitch-embed-wrapper > * {
  overflow: hidden;
}

.twitch-embed-wrapper.collapsed {
  grid-template-rows: 0fr;
  opacity: 0;
}

/* Hide collapse icon on widescreen - always show embed */
@media (min-width: 1024px) {
  .twitch-collapse-icon {
    display: none;
  }

  .twitch-header {
    cursor: default;
  }

  /* Preserve gradient on hover when live */
  .twitch-section:not(.is-live) .twitch-header:hover {
    border-color: var(--border-color);
  }

  /* Always show embed on widescreen regardless of collapsed state */
  .twitch-section.is-live .twitch-embed-wrapper.collapsed {
    grid-template-rows: 1fr;
    opacity: 1;
  }
}

.twitch-header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(145, 70, 255, 0.15);
  border-radius: 10px;
  flex-shrink: 0;
}

.twitch-icon {
  width: 20px;
  height: 20px;
  fill: #9146ff;
}

.twitch-header-text {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.twitch-channel-name {
  font-weight: 600;
  font-size: 0.95rem;
}

/* Live indicator */
.twitch-live-indicator {
  display: none;
  align-items: center;
  gap: 0.35rem;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ef4444;
  position: relative;
}

.twitch-live-indicator.is-live {
  display: inline-flex;
}

/* Animated red glow behind live badge */
.twitch-live-indicator.is-live::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 6px;
  background: #ef4444;
  opacity: 0.35;
  filter: blur(8px);
  z-index: -1;
  animation: liveGlow 2s ease-in-out infinite;
}

@keyframes liveGlow {
  0%, 100% { opacity: 0.25; filter: blur(8px); }
  50% { opacity: 0.45; filter: blur(12px); }
}

.live-dot {
  width: 6px;
  height: 6px;
  background: #ef4444;
  border-radius: 50%;
  animation: pulse-live 1.5s ease-in-out infinite;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.twitch-offline-text {
  display: inline;
  font-size: 0.8rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

.twitch-offline-text.hidden {
  display: none;
}

/* Embed wrapper - hidden when offline */
.twitch-section:not(.is-live) .twitch-embed-wrapper {
  display: none;
}

/* Aspect ratio container for video + chat embed */
.twitch-embed-container {
  position: relative;
  width: 100%;
  /* Default: tall ratio for stacked video + chat */
  padding-bottom: 100%;
  background: rgba(10, 10, 10, 0.8);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
}

/* Widescreen layout kicks in at 1024px+ */
@media (min-width: 1024px) {
  /* Wide screens (16:10 and wider): chat docks right */
  @media (min-aspect-ratio: 16/10) {
    .twitch-embed-container {
      padding-bottom: 56.25%; /* 16:9 - chat on right */
    }
  }

  /* Squarer screens (between 4:3 and 16:10): chat below */
  @media (max-aspect-ratio: 16/10) {
    .twitch-embed-container {
      padding-bottom: 85%; /* Taller - chat stacks below */
    }
  }

  /* Very square/tall screens (4:3 and narrower): even taller */
  @media (max-aspect-ratio: 4/3) {
    .twitch-embed-container {
      padding-bottom: 100%; /* Square - more chat room */
    }
  }
}

#twitch-embed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.4s ease;
}

#twitch-embed.ready {
  opacity: 1;
}

#twitch-embed iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 11px;
}

/* Loading placeholder while embed initializes */
.twitch-embed-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    var(--bg-primary) 0%,
    rgba(20, 20, 20, 1) 50%,
    var(--bg-primary) 100%
  );
  background-size: 200% 200%;
  animation: embedLoadingPulse 2s ease-in-out infinite;
  border-radius: 11px;
  z-index: 1;
  opacity: 1;
  transition: opacity 0.4s ease;
}

@keyframes embedLoadingPulse {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.twitch-embed-container:has(#twitch-embed.ready)::before {
  opacity: 0;
  pointer-events: none;
}

/* Animated gradient border when live - matches multistack style */
.twitch-section.is-live .twitch-embed-container {
  border-color: transparent;
  background:
    linear-gradient(rgba(10, 10, 10, 0.8), rgba(10, 10, 10, 0.8)) padding-box,
    linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff) border-box;
  background-size: 100% 100%, 400% 400%;
  animation: borderShift 8s linear infinite;
}

/* Outer glow behind embed */
.twitch-section.is-live .twitch-embed-container::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 12px;
  background: linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff);
  background-size: 400% 400%;
  animation: borderShift 8s linear infinite;
  opacity: 0.25;
  filter: blur(16px);
  z-index: -1;
  transition: opacity 0.35s ease, filter 0.35s ease;
}

.twitch-section.is-live .twitch-embed-container:hover::after {
  opacity: 0.4;
  filter: blur(20px);
}

/* Animated gradient header when live */
.twitch-section.is-live .twitch-header {
  border-color: transparent;
  background:
    linear-gradient(rgba(20, 20, 20, 0.85), rgba(20, 20, 20, 0.85)) padding-box,
    linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff) border-box;
  background-size: 100% 100%, 400% 400%;
  animation: borderShift 8s linear infinite;
}

/* Subtle glow behind header when live */
.twitch-section.is-live .twitch-header::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 12px;
  background: linear-gradient(135deg, #00e5ff, #6e5aed, #9146ff, #6e5aed, #00e5ff);
  background-size: 400% 400%;
  animation: borderShift 8s linear infinite;
  opacity: 0.15;
  filter: blur(12px);
  z-index: -1;
}

/* Fallback link */
.twitch-fallback-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  transition: color 0.2s ease;
}

.twitch-fallback-link:hover {
  color: var(--text-primary);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .twitch-header {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .twitch-header-icon {
    width: 32px;
    height: 32px;
  }

  .twitch-icon {
    width: 18px;
    height: 18px;
  }

  .twitch-channel-name {
    font-size: 0.9rem;
  }

  .twitch-embed-container {
    /* Taller on mobile for chat readability */
    padding-bottom: 120%;
  }
}

/* Very narrow screens - hide embed, show link */
@media (max-width: 380px) {
  .twitch-embed-wrapper {
    display: none;
  }

  .twitch-header::after {
    content: '→ Watch';
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
  }

  .twitch-header {
    cursor: pointer;
  }
}

/* Loading shimmer state */
.twitch-header.loading .twitch-channel-name,
.twitch-header.loading .twitch-offline-text {
  background: linear-gradient(90deg,
    var(--text-secondary) 0%,
    var(--text-primary) 50%,
    var(--text-secondary) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmerText 1.5s ease-in-out infinite;
}

@keyframes shimmerText {
  0% { background-position: 100% 50%; }
  100% { background-position: -100% 50%; }
}

.twitch-header.loading .twitch-header-icon {
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* Twitch section reduced motion */
@media (prefers-reduced-motion: reduce) {
  .live-dot {
    animation: none;
  }

  .twitch-live-indicator.is-live::before {
    animation: none;
  }

  .twitch-header.loading .twitch-channel-name,
  .twitch-header.loading .twitch-offline-text,
  .twitch-header.loading .twitch-header-icon {
    animation: none;
  }

  .twitch-embed-container::before {
    animation: none;
  }

  .twitch-section.is-live .twitch-embed-container,
  .twitch-section.is-live .twitch-embed-container::after,
  .twitch-section.is-live .twitch-header,
  .twitch-section.is-live .twitch-header::before {
    animation: none;
  }
}
