 :root {
      --bg-gradient: linear-gradient(135deg, #090814 0%, #170d2b 50%, #0d061a 100%);
      --glass-bg: rgba(24, 20, 36, 0.65);
      --glass-bg-hover: rgba(35, 29, 54, 0.8);
      --glass-border: rgba(145, 70, 255, 0.25);
      --glass-border-light: rgba(255, 255, 255, 0.12);
      --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
      --accent-purple: #9146ff;
      --accent-glow: rgba(145, 70, 255, 0.5);
      --live-red: #eb0400;
      --live-glow: rgba(235, 4, 0, 0.6);
      --text-main: #f0f0f5;
      --text-muted: #adadb8;
      --danger-color: #ff4f4f;
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
      background: var(--bg-gradient);
      background-attachment: fixed;
      color: var(--text-main);
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      overflow-x: hidden;
    }

    /* Header Bar */
    header {
      background: var(--glass-bg);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      border-bottom: 1px solid var(--glass-border);
      box-shadow: var(--glass-shadow);
      padding: 10px 24px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      z-index: 10;
      flex-wrap: wrap;
      gap: 12px;
    }

    .brand {
      font-size: 16px;
      font-weight: 700;
      letter-spacing: 0.5px;
      background: linear-gradient(135deg, #ffffff 0%, #c4a1ff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .header-actions {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }

    .glass-btn {
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid var(--glass-border-light);
      color: var(--text-main);
      padding: 8px 16px;
      border-radius: 20px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 6px;
      transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
      backdrop-filter: blur(8px);
      white-space: nowrap;
    }

    .glass-btn:hover {
      background: var(--accent-purple);
      border-color: var(--accent-purple);
      box-shadow: 0 0 15px var(--accent-glow);
      transform: translateY(-1px);
    }

    .glass-btn.btn-active {
      background: var(--accent-purple);
      border-color: var(--accent-purple);
      box-shadow: 0 0 12px var(--accent-glow);
    }

    /* Toggle Switch */
    .view-toggle {
      display: flex;
      align-items: center;
      background: rgba(0, 0, 0, 0.3);
      border: 1px solid var(--glass-border-light);
      border-radius: 20px;
      padding: 3px;
    }

    .toggle-option {
      padding: 5px 14px;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-muted);
      cursor: pointer;
      border-radius: 16px;
      transition: all 0.3s ease;
      user-select: none;
    }

    .toggle-option.active {
      color: #fff;
      background: var(--accent-purple);
      box-shadow: 0 0 10px var(--accent-glow);
    }

    /* Main Container */
    .stream-container {
      padding: 12px;
      flex-grow: 1;
      height: calc(100vh - 60px);
      gap: 10px;
      display: grid;
      transition: all 0.3s ease;
    }

    .stream-box.hidden {
      display: none !important;
    }

    /* Grid Layouts */
    .stream-container.layout-grid {
      grid-template-columns: repeat(6, 1fr);
      grid-template-rows: 1fr 1fr;
    }

    .stream-container.layout-grid #box1 { grid-column: span 2; grid-row: 1; }
    .stream-container.layout-grid #box2 { grid-column: span 2; grid-row: 1; }
    .stream-container.layout-grid #box3 { grid-column: span 2; grid-row: 1; }
    .stream-container.layout-grid #box4 { grid-column: span 3; grid-row: 2; }
    .stream-container.layout-grid #box5 { grid-column: span 3; grid-row: 2; }

    /* Focus Mode Layout Rules */
    .stream-container.layout-focus {
      grid-template-columns: 1fr 320px;
      grid-template-rows: repeat(4, 1fr);
    }

    .stream-container.layout-focus .stream-box {
      grid-column: auto !important;
      grid-row: auto !important;
    }

    .stream-container.layout-focus .stream-box.focused {
      grid-column: 1 !important;
      grid-row: 1 / span 4 !important;
    }

    .stream-container.layout-focus .stream-box:not(.focused) {
      grid-column: 2 !important;
    }

    /* Stream Card Base with Hardware Acceleration Optimizations */
    .stream-box {
      background: var(--glass-bg);
      backdrop-filter: blur(12px);
      border-radius: 12px;
      border: 1px solid var(--glass-border-light);
      overflow: hidden;
      display: flex;
      flex-direction: column;
      position: relative;
      box-shadow: var(--glass-shadow);
      will-change: transform, opacity;
      transform: translateZ(0);
      backface-visibility: hidden;
      transition: border-color 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
    }

    .stream-box.is-offline {
      opacity: 0.65;
      filter: grayscale(40%);
    }

    .stream-box.focused {
      border: 2px solid var(--accent-purple);
      box-shadow: 0 0 20px var(--accent-glow);
      opacity: 1 !important;
      filter: grayscale(0%) !important;
    }

    .stream-header {
      background: rgba(0, 0, 0, 0.45);
      padding: 6px 12px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 12px;
      font-weight: 600;
      user-select: none;
      backdrop-filter: blur(8px);
      z-index: 2;
    }

    .stream-header-left {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .status-badge {
      font-size: 10px;
      font-weight: 700;
      padding: 2px 6px;
      border-radius: 10px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      display: inline-flex;
      align-items: center;
      gap: 4px;
    }

    .status-badge.live {
      background: var(--live-red);
      color: #fff;
      box-shadow: 0 0 8px var(--live-glow);
    }

    .status-badge.live::before {
      content: '';
      width: 5px;
      height: 5px;
      background: #fff;
      border-radius: 50%;
      animation: pulse 1.5s infinite;
    }

    .status-badge.offline {
      background: rgba(255, 255, 255, 0.1);
      color: var(--text-muted);
      border: 1px solid rgba(255, 255, 255, 0.15);
    }

    .quality-badge {
      font-size: 10px;
      font-weight: 600;
      color: #c4a1ff;
      background: rgba(145, 70, 255, 0.15);
      border: 1px solid rgba(145, 70, 255, 0.3);
      padding: 1px 6px;
      border-radius: 8px;
    }

    @keyframes pulse {
      0% { opacity: 0.4; }
      50% { opacity: 1; }
      100% { opacity: 0.4; }
    }

    .audio-badge {
      cursor: pointer;
      opacity: 0.75;
      font-size: 13px;
      transition: opacity 0.2s;
    }
    .audio-badge:hover { opacity: 1; }

    .focus-icon-btn {
      background: transparent;
      border: none;
      color: var(--text-muted);
      cursor: pointer;
      font-size: 14px;
      transition: all 0.2s;
    }

    .focus-icon-btn:hover,
    .stream-box.focused .focus-icon-btn {
      color: var(--accent-purple);
      transform: scale(1.15);
    }

    .player-wrapper {
      position: relative;
      flex-grow: 1;
      width: 100%;
      height: 100%;
    }

    .player-target {
      width: 100%;
      height: 100%;
    }

    .player-target iframe {
      width: 100%;
      height: 100%;
      border: none;
    }

    .offline-overlay {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: radial-gradient(circle, rgba(30, 23, 48, 0.95) 0%, rgba(12, 9, 20, 0.98) 100%);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 10px;
      z-index: 1;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.3s ease;
    }

    .stream-box.is-offline .offline-overlay {
      opacity: 1;
      pointer-events: auto;
    }

    .offline-icon { font-size: 32px; opacity: 0.4; }
    .offline-title { font-size: 14px; font-weight: 700; color: var(--text-muted); }
    .offline-sub { font-size: 11px; color: rgba(255, 255, 255, 0.3); }

    /* Modals */
    .modal-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      background: rgba(0, 0, 0, 0.65);
      backdrop-filter: blur(8px);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 100;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
    }

    .modal-overlay.active { opacity: 1; pointer-events: auto; }

    .modal {
      background: rgba(22, 18, 33, 0.95);
      border: 1px solid var(--glass-border);
      border-radius: 16px;
      padding: 24px;
      width: 420px;
      max-width: 90%;
      max-height: 90vh;
      overflow-y: auto;
      box-shadow: 0 16px 40px rgba(0,0,0,0.6);
      transform: translateY(20px);
      transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .modal-overlay.active .modal { transform: translateY(0); }

    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 18px;
    }

    .modal-title { font-size: 16px; font-weight: 700; }

    .close-btn {
      background: transparent;
      border: none;
      color: var(--text-muted);
      font-size: 18px;
      cursor: pointer;
    }

    .modal-body {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .input-field {
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .input-field label { font-size: 12px; color: var(--text-muted); }

    input, select {
      background: rgba(0, 0, 0, 0.4);
      border: 1px solid var(--glass-border-light);
      color: #fff;
      padding: 10px 12px;
      border-radius: 8px;
      font-size: 13px;
    }

    input:focus, select:focus {
      outline: none;
      border-color: var(--accent-purple);
      box-shadow: 0 0 8px var(--accent-glow);
    }

    .modal-footer {
      display: flex;
      justify-content: flex-end;
      gap: 8px;
      margin-top: 18px;
    }

    /* Mobile & Tablet Responsive Enhancements */
    @media (max-width: 900px) {
      header {
        padding: 12px 16px;
        justify-content: center;
      }
      
      .brand {
        font-size: 18px;
        width: 100%;
        justify-content: center;
      }

      .header-actions {
        width: 100%;
        justify-content: center;
        gap: 8px;
      }

      .glass-btn {
        padding: 6px 12px;
        font-size: 12px;
      }

      .stream-container {
        height: auto;
        min-height: calc(100vh - 110px);
        padding: 8px;
      }

      .stream-container.layout-grid,
      .stream-container.layout-focus {
        display: flex;
        flex-direction: column;
      }

      .stream-box { 
        height: auto;
        width: 100%;
        aspect-ratio: 16 / 9;
      }

      .modal {
        padding: 18px;
        width: 95%;
      }
    }

    @media (max-width: 480px) {
      .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
      }

      .view-toggle {
        grid-column: span 2;
        justify-content: center;
      }

      .toggle-option {
        flex: 1;
        text-align: center;
      }

      .glass-btn {
        justify-content: center;
      }
    }