:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #161b22;
  --border: #2a3038;
  --text: #e6edf3;
  --muted: #8b96a5;
  --accent: #4f8cff;
  --accent-hover: #3d78ea;
  --danger: #e5484d;
  --ok: #3fb950;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.25rem;
}

.wrap {
  width: 100%;
  max-width: 640px;
}

/* Watch page: ditch the narrow centered column so the player can actually
   fill the screen, and lay out player + chat side by side. Fixed to
   exactly the viewport height with overflow hidden, rather than
   min-height, so the page itself can never need scrolling regardless of
   the stream's aspect ratio - the video is size-capped to fit within
   what's left after the status line (see .video-frame video below),
   letterboxing rather than growing past its box. */
body.watch-page {
  align-items: stretch;
  padding: 1rem;
  height: 100vh;
  overflow: hidden;
}

.watch-layout {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.player-column {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  text-align: center;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 2rem;
  font-size: 0.95rem;
}

.stats-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
  margin: -1.25rem 0 1.5rem;
}

.stats-bar strong {
  color: var(--text);
  font-weight: 600;
}

.stats-sep {
  color: var(--border);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.select-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.9rem;
}

.select-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Generic blocking modal - currently just the watch-page consent overlay. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  padding: 1.5rem;
}

.modal-panel {
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: left;
}

.modal-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.segmented {
  display: flex;
  gap: 0.5rem;
}

.segmented button {
  flex: 1;
  padding: 0.55rem 0.5rem;
  background: #1c2128;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.segmented button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.segmented button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.9rem;
}

.primary-btn {
  width: 100%;
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { background: #384150; cursor: not-allowed; }

/* Loading state for any button with a .btn-spinner child (Start, Switch
   Window/Screen) - both have a real delay (permission prompt, POST,
   several async setParameters/replaceTrack calls), so this covers that gap
   instead of the button just looking unresponsive. */
.btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  margin-right: 0.5rem;
  vertical-align: -2px;
  animation: btn-spin 0.7s linear infinite;
}

button.loading .btn-spinner {
  display: inline-block;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.danger-btn {
  width: 100%;
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  margin-top: 0.75rem;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: -0.5rem 0 1.25rem;
}

.config-note {
  min-height: 1.1em;
  margin: -0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--accent);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,185,80,0.2); }

.share-box {
  display: none;
  margin-top: 1rem;
}

.share-box.visible { display: block; }

.share-row {
  display: flex;
  gap: 0.5rem;
}

.share-row input {
  flex: 1;
  padding: 0.6rem 0.7rem;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.85rem;
}

.share-row button {
  padding: 0.6rem 0.9rem;
  background: #1c2128;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}

.error-box {
  display: none;
  background: rgba(229,72,77,0.1);
  border: 1px solid var(--danger);
  color: #ff9192;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.error-box.visible { display: block; }

video {
  width: 100%;
  border-radius: 12px;
  background: black;
  display: block;
}

.viewer-msg {
  color: var(--muted);
  margin-top: 1rem;
  flex-shrink: 0;
}

.player {
  background: black;
  border-radius: 12px;
  overflow: hidden;
  flex: 1;
  min-height: 0;
  display: flex;
}

.player video {
  border-radius: 0;
}

.video-frame {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Never taller/wider than the space actually available (bounded, in turn,
   by body.watch-page's fixed 100vh) - letterboxes on unusual aspect
   ratios (e.g. Native resolution, or a portrait/ultrawide window) rather
   than pushing the page taller and forcing a scrollbar. */
.video-frame video {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.danmaku-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.danmaku-item {
  position: absolute;
  left: 100%;
  top: 0;
  white-space: nowrap;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 8px rgba(0, 0, 0, 0.6);
  animation-name: danmaku-scroll;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes danmaku-scroll {
  from { transform: translateX(0); }
  /* translateX(-100%) clears the item's own width; -100vw on top of that
     guarantees it fully exits the left edge regardless of container size. */
  to { transform: translateX(calc(-100% - 100vw)); }
}

/* Floats directly on the video itself (bottom edge), rather than a
   separate bar below it - a fading gradient keeps it legible over any
   video content without fully hiding the frame behind it. */
.video-controls-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 0.75rem 0.6rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
}

.controls-spacer {
  flex: 1;
}

.control-btn {
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1c2128;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.control-btn:hover {
  background: #262c36;
}

.control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.volume-slider {
  width: 110px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Chat sidebar: viewer count + a normal scrolling message list (comments
   aren't only the fly-by overlay on the video - this is always on). */
.chat-sidebar {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  height: calc(100vh - 2rem);
  max-height: calc(100vh - 2rem);
}

.chat-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.viewer-count-badge {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.chat-header-toggle {
  font-size: 0.8rem;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-message {
  font-size: 0.85rem;
  line-height: 1.35;
  word-break: break-word;
  text-align: left;
  color: var(--text);
}

.chat-message-name {
  font-weight: 700;
  color: var(--accent);
}

.chat-empty {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: left;
}

.comment-composer {
  padding: 0.75rem;
  background: #10151c;
  border-top: 1px solid var(--border);
}

.emoji-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}

.emoji-btn {
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #1c2128;
  cursor: pointer;
}

.emoji-btn:hover,
.emoji-btn:active {
  background: #262c36;
}

.comment-form {
  display: flex;
  gap: 0.5rem;
}

.comment-form input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.85rem;
}

.comment-notice {
  min-height: 1.1em;
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: left;
}

/* Mobile: the sidebar would otherwise eat most of a portrait phone
   screen and squeeze the actual video down. Hide it behind an explicit
   toggle instead - a bottom-right button opens it as a slide-in drawer
   over the video rather than pushing the page layout around. */
.chat-toggle-btn,
.chat-close-btn,
.chat-backdrop {
  display: none;
}

@media (max-width: 860px) {
  .chat-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 60;
    padding: 0.7rem 1.1rem;
    border-radius: 999px;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  }

  .chat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 54;
    background: rgba(0, 0, 0, 0.5);
  }

  .chat-backdrop.visible {
    display: block;
  }

  .chat-close-btn {
    display: inline-flex;
    align-self: flex-end;
    padding: 0.3rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #1c2128;
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    width: 85vw;
    max-width: 360px;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-bottom: none;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }
}

/* Fill the whole screen; .video-frame/video's own base rules (flex:1 +
   max-width/max-height + object-fit:contain) already letterbox correctly
   at any container size, fullscreen included, so nothing further is
   needed for them here. The video-controls-overlay lives inside
   .video-frame so it stays usable fullscreened too. The chat sidebar
   (including the comments-toggle) is outside #player and isn't part of
   the fullscreened element - standard behavior, same as any other site's
   chat sidebar disappearing in fullscreen. The danmaku overlay itself
   still renders either way, since it's inside .video-frame too. */
.player:fullscreen {
  display: flex;
  flex-direction: column;
  border-radius: 0;
  width: 100vw;
  height: 100vh;
}
