/* --- Basic Setup & Existing Styles --- */
html, body {
    margin: 0;
    padding: 0;
    background-color: #000000; /* Pitch black background */
    font-family: "Open Sans", sans-serif;
    color: #f2f2f2; /* Default text color */
    height: 100%;
    overflow-x: hidden; /* Prevent horizontal scroll */
  }
  
  .main-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* Ensure container takes full viewport height */
    padding: 0 1rem; /* Add some padding */
  }
  
  header {
    background-color: #333333;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    padding: 0.8rem 1.5rem; /* Slightly reduced padding */
    width: 100%;
    margin-bottom: 1rem;
    flex-shrink: 0; /* Prevent header from shrinking */
  }
  
  header h1 {
    margin: 0;
    font-size: 1.3rem; /* Slightly smaller */
    font-weight: 600;
    color: #FFFFFF;
  }
  
  /* --- Content Layout (Video + Chat) --- */
  .content-area {
    display: flex;
    flex-grow: 1; /* Allow content area to fill remaining space */
    gap: 1rem; /* Space between video and chat */
    overflow: hidden; /* Prevent content overflow issues */
    flex-direction: row; /* Default layout */
  }
  
  .video-section {
    flex: 1 1 70%; /* Takes up more space initially */
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevent flex item from overflowing */
  }
  
  .video-container {
    position: relative;
    width: 100%;
    background: #1b1b1b;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    overflow: hidden;
    /* Aspect ratio preferred, but fallback height */
    aspect-ratio: 16 / 9;
    height: auto; /* Let aspect ratio dictate height */
    min-height: 300px; /* Minimum height */
  }
  
  .video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
  
  .status-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: rgba(255, 0, 0, 0.5); color: #fff;
    font-size: 1.25rem; font-weight: 600;
    z-index: 15; display: none; /* Initially hidden */
  }
  
  .alternative-play {
    margin-top: 0.5rem; font-size: 0.9rem; color: #cccccc; text-align: left;
  }
  .alternative-play code { background-color: #333; padding: 0.1em 0.4em; border-radius: 3px; color: #f2f2f2; }
  .alternative-play a { color: #4dabf7; text-decoration: none; }
  .alternative-play a:hover { text-decoration: underline; }
  
  
  /* --- Chat Section --- */
  .chat-section {
    flex: 1 1 30%; /* Takes up less space */
    max-width: 350px; /* Max width for chat */
    background-color: #1f1f1f; /* Slightly lighter dark grey */
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Clip content */
    position: relative; /* For absolute positioning inside if needed */
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  }
  
  /* .chat-content {
      display: flex;
      flex-direction: column;
      height: 100%; 
  } */

  
  .chat-header {
    padding: 0.75rem 1rem;
    background-color: #333; /* Match header */
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Prevent shrinking */
  }
  
  .chat-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
  }
  
  .connection-status {
      font-size: 0.8rem;
      padding: 0.2rem 0.5rem;
      border-radius: 4px;
  }
  .connection-status.connecting { color: #ffc107; background-color: rgba(255, 193, 7, 0.2); }
  .connection-status.connected { color: #28a745; background-color: rgba(40, 167, 69, 0.2); }
  .connection-status.disconnected { color: #dc3545; background-color: rgba(220, 53, 69, 0.2); }
  .connection-status.error { color: #dc3545; background-color: rgba(220, 53, 69, 0.2); }
  
  
  .chat-messages {
    flex-grow: 1;         /* Take available vertical space */
    overflow-y: auto;     /* Enable scrolling for overflow */
    padding: 0.75rem 1rem;
    display: flex;          /* Keep as flex if needed for internal alignment, but often not necessary */
    flex-direction: column; /* Keep if you still need items stacked top-to-bottom inside */
    min-height: 0;        /* ADD THIS: Crucial flexbox fix */
  }
  
  /* Style for the loading indicator */
  .loading-spinner {
    display: block;
    margin: 10px auto;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    visibility: hidden; /* Initially hidden */
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  .message-container {
    margin-bottom: 0.75rem;
    padding-left: 5px; /* Indent slightly */
    border-left: 2px solid transparent; /* Placeholder for potential future use */
    position: relative; /* For reaction button positioning */
  }
  
  .message-container:hover .react-button {
      opacity: 1; /* Show on hover */
  }
  
  
  .message-header {
    display: flex;
    align-items: baseline;
    margin-bottom: 0.2rem;
  }
  
  .message-author {
    font-weight: 600;
    font-size: 0.9rem;
    margin-right: 0.5rem;
    /* Color will be set dynamically by JS */
  }
  
  .message-timestamp {
    font-size: 0.75rem;
    color: #aaa;
  }
  
  .message-content {
    font-size: 0.95rem;
    line-height: 1.4;
    color: #e0e0e0;
    word-wrap: break-word; /* Break long words */
  }
  
  /* Markdown Styles */
  .message-content p { margin-bottom: 0.5em; }
  .message-content p:last-child { margin-bottom: 0; }
  .message-content strong, .message-content b { font-weight: bold; }
  .message-content em, .message-content i { font-style: italic; }
  .message-content code {
    background-color: #333;
    padding: 0.1em 0.4em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
  }
  .message-content pre {
    background-color: #2c2c2c;
    padding: 0.5em;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.5em 0;
  }
  .message-content pre code { background-color: transparent; padding: 0; }
  .message-content blockquote {
    border-left: 3px solid #555;
    padding-left: 0.8em;
    margin-left: 0.3em;
    color: #ccc;
  }
  .message-content a {
    color: #4dabf7;
    text-decoration: none;
  }
  .message-content a:hover { text-decoration: underline; }
  
  /* Reactions */
  .message-reactions {
    margin-top: 0.3rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
  }
  
  .reaction {
    background-color: #3a3a3a;
    border: 1px solid #555;
    border-radius: 10px;
    padding: 0.1rem 0.4rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.2rem;
  }
  
  .reaction:hover {
    background-color: #4a4a4a;
    border-color: #777;
  }
  
  .reaction .emoji { /* Can style emoji specifically if needed */ }
  .reaction .count { font-weight: 600; color: #eee; }
  
  /* Add reaction button (initially hidden) */
  .react-button {
      position: absolute;
      top: -5px; /* Adjust as needed */
      right: 0;
      background: #444;
      border: none;
      color: #fff;
      border-radius: 50%;
      width: 20px;
      height: 20px;
      font-size: 12px;
      line-height: 20px; /* Center icon vertically */
      text-align: center;
      cursor: pointer;
      opacity: 0; /* Hidden by default */
      transition: opacity 0.2s ease;
      z-index: 5; /* Above message content */
  }
  
  .react-button:hover {
      background: #555;
  }
  
  
  .system-message {
    font-size: 0.85rem;
    color: #aaa;
    text-align: center;
    margin: 0.5rem 0;
    font-style: italic;
  }
  
  .chat-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid #444;
    background-color: #2a2a2a;
    display: flex;
    flex-wrap: wrap; /* Allow wrapping */
    align-items: flex-end; /* Align items to bottom */
    gap: 0.5rem;
    position: relative; /* For emoji picker positioning */
    flex-shrink: 0; /* Prevent shrinking */
  }
  
  .chat-user-info {
      width: 100%; /* Take full width */
      font-size: 0.8rem;
      color: #ccc;
      margin-bottom: 0.2rem; /* Space below nickname */
  }
  #current-nickname {
      font-weight: bold;
      /* Add color later if desired */
  }
  
  #chat-input {
    flex-grow: 1; /* Take available horizontal space */
    background-color: #3a3a3a;
    border: 1px solid #555;
    border-radius: 4px;
    color: #f2f2f2;
    padding: 0.5rem;
    resize: none; /* Disable manual resize */
    font-family: inherit;
    font-size: 0.95rem;
    min-height: 40px; /* Minimum height */
    max-height: 100px; /* Prevent excessive growth */
    line-height: 1.4;
  }
  
  #chat-input:focus {
    outline: none;
    border-color: #4dabf7;
    box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.3);
  }
  
  #send-button, #emoji-button {
    background-color: #4dabf7;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 600;
    height: 40px; /* Match input height */
  }
  #emoji-button {
      padding: 0.5rem 0.7rem; /* Slightly less padding */
      font-size: 1.2rem;
      line-height: 1; /* Adjust for emoji centering */
  }
  
  #send-button:hover, #emoji-button:hover {
    background-color: #3690da;
  }
  
  #toggle-chat-btn {
      position: fixed;
      bottom: 1rem;
      right: 1rem;
      z-index: 100;
      background-color: #4dabf7;
      color: white;
      border: none;
      border-radius: 50%;
      width: 50px;
      height: 50px;
      font-size: 1.5rem;
      box-shadow: 0 2px 5px rgba(0,0,0,0.3);
      display: none; /* Hidden by default, shown via media query */
      cursor: pointer;
  }
  
  
  /* --- Responsiveness --- */
  @media (max-width: 992px) { /* Medium devices (tablets, smaller desktops) */
      .content-area {
          flex-direction: column; /* Stack video and chat */
      }
      .video-section {
          flex-basis: auto; /* Reset basis */
      }
      .chat-section {
          flex-basis: auto; /* Reset basis */
          max-width: none; /* Allow full width */
          height: 400px; /* Fixed height when stacked */
          min-height: 300px;
      }
  }
  
  @media (max-width: 768px) { /* Small devices (landscape phones, tablets) */
      header h1 { font-size: 1.1rem; }
      .chat-section {
          /* Hide chat by default on small screens, show toggle button */
          position: fixed;
          bottom: 0;
          right: -100%; /* Start off-screen */
          width: 90%;
          max-width: 320px;
          height: 70vh; /* Take significant portion of height */
          z-index: 99;
          transition: right 0.3s ease-in-out;
          border-top-left-radius: 8px;
          border-bottom-left-radius: 8px;
          border-radius: 8px 0 0 8px; /* Rounded corners on the left */
      }
      .chat-section.open {
          right: 0; /* Slide in */
      }
      #toggle-chat-btn {
          display: block; /* Show toggle button */
      }
      .chat-header { padding: 0.5rem 0.75rem; }
      .chat-header h2 { font-size: 0.9rem; }
      .chat-messages { padding: 0.5rem 0.75rem; }
      .message-author { font-size: 0.85rem; }
      .message-content { font-size: 0.9rem; }
      .chat-input-area { padding: 0.5rem 0.75rem; gap: 0.3rem; }
      #chat-input { font-size: 0.9rem; padding: 0.4rem; min-height: 35px; }
      #send-button, #emoji-button { height: 35px; padding: 0.4rem 0.8rem; }
      #emoji-button { font-size: 1rem; padding: 0.4rem 0.6rem; }
  
  }
  
  /* Style for emoji picker popup */
  emoji-picker {
      position: absolute; /* Position relative to input area */
      bottom: 65px; /* Adjust based on input area height */
      right: 10px;
      z-index: 100;
      border: 1px solid #555;
      box-shadow: 0 5px 15px rgba(0,0,0,0.3);
      border-radius: 8px;
      /* Theming is done via 'light'/'dark' class or CSS vars if supported by the element */
  }