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

:root {
  --bg: #18181b;
  --panel: #1f1f23;
  --border: #2c2c34;
  --border2: #3a3a3d;
  --text: #efeff1;
  --muted: #adadb8;
  --muted2: #53535f;
  --accent: #9147ff;
  --green: #00f593;
  --danger: #ff6b6b;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Focus visibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

.header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap; /* allows hint to stay below controls on narrow widths */
}

/* Theatre mode hides chrome */
body.theatre-mode .header,
body.theatre-mode .footer {
  display: none;
}

/* Theatre mode exit pill (auto-hide) */
.theatre-exit {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  padding: 10px 12px;
  background: rgba(31, 31, 35, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  gap: 10px;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body.theatre-mode .theatre-exit {
  display: inline-flex;
}
body.theatre-mode .theatre-exit.visible {
  opacity: 1;
  pointer-events: auto;
}

.theatre-exit:hover {
  border-color: var(--accent);
}

.theatre-exit svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 170px;
  flex: 0 0 auto;
}

.logo {
  width: 22px;
  height: 22px;
  fill: var(--accent);
}
h1 {
  font-size: 1.1rem;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.header-right {
  display: flex;
  flex-direction: column; /* stack: controls row then hint */
  align-items: flex-end;
  gap: 6px;
  flex: 1 1 520px; /* allows the right block to be wider */
  min-width: 320px;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  width: 100%;
}

.channel-input {
  padding: 10px 12px;
  background: #2c2c34;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  flex: 1 1 360px; /* make it wider by default */
  min-width: 220px;
  max-width: 520px;
}
.channel-input:focus {
  outline: none;
  border-color: var(--accent);
}

.start-input {
  padding: 10px 12px;
  background: #2c2c34;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  flex: 0 1 220px;
  min-width: 180px;
  max-width: 280px;
}
.start-input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  padding: 10px 12px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition:
    background 0.2s,
    opacity 0.2s,
    transform 0.05s;
  white-space: nowrap;
}
button:hover:not(:disabled) {
  background: #772ce8;
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text);
  font-weight: 600;
}
.ghost-btn:hover:not(:disabled) {
  background: #2c2c34;
}

.is-hidden {
  display: none !important;
}

.icon-label-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.icon-label-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#rotateVideoBtn svg {
  fill: currentColor;
  stroke: none;
}
.icon-label-btn .btn-text {
  display: inline-block;
}

.mini-btn {
  padding: 6px 8px;
  font-size: 0.78rem;
  border-radius: 6px;
}

.icon-btn {
  padding: 10px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  width: 40px;
  height: 40px;
}
.icon-btn:hover:not(:disabled) {
  background: #2c2c34;
  border-color: var(--border2);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 6px;
  cursor: pointer;
}
.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

#chatDrawerBtn {
  display: none;
}

#rotateVideoBtn {
  display: none;
}

.start-input-wrap {
  display: inline-flex;
  align-items: center;
  position: relative;
  max-width: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transition:
    max-width 220ms ease,
    opacity 180ms ease;
}
.start-input-wrap.show {
  max-width: 420px;
  opacity: 1;
  pointer-events: auto;
}

.start-input-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.start-btn {
  min-width: 52px;
}

.start-time-preview {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  font-size: 0.72rem;
  color: var(--muted2);
  padding-left: 2px;
  min-height: 16px;
  white-space: nowrap;
}
.start-time-preview.error {
  color: var(--danger);
}

.history-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.history-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: auto;
  min-width: 200px;
  max-width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 1200;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.history-menu.open {
  display: flex;
}

.history-empty {
  font-size: 0.78rem;
  color: var(--muted2);
  padding: 6px 2px;
  text-align: left;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #2c2c34;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text);
}
.history-item:hover {
  border-color: var(--border2);
  background: #333340;
}

.history-meta {
  font-size: 0.7rem;
  color: var(--muted2);
}

.advanced-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.footer-link {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
}
.footer-link:visited {
  color: var(--muted2);
}
.footer-link:hover {
  color: var(--text);
  border-bottom-color: var(--muted2);
}

.hint,
.error {
  font-size: 0.75rem;
  line-height: 1.2;
  text-align: right; /* keep it visually under right-aligned controls */
  color: var(--muted);
  width: 100%;
  max-width: 900px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.error {
  color: var(--danger);
  display: none;
}

.kbd {
  background: #2c2c34;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  font-size: 0.72rem;
  border: 1px solid var(--border2);
  display: inline-block;
  transform: translateY(-1px);
}

.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(24, 24, 27, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  flex-direction: column;
  gap: 12px;
}
.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #2c2c34;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(31, 31, 35, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.85rem;
  z-index: 1100;
  display: none;
  gap: 8px;
  align-items: center;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  max-width: min(780px, calc(100vw - 24px));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show {
  display: inline-flex;
}

.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  text-align: center;
  padding: 16px;
}

.welcome-icon {
  width: 64px;
  height: 64px;
  fill: var(--muted2);
}
.welcome h2 {
  font-size: 1.5rem;
  color: var(--muted);
}
.welcome p {
  color: var(--muted2);
}

.info-box {
  margin-top: 28px;
  padding: 14px;
  background: var(--panel);
  border-radius: 10px;
  max-width: 600px;
  text-align: left;
  border: 1px solid var(--border);
}
.info-box h3 {
  color: #5890ff;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.info-box p,
.info-box ul {
  font-size: 0.875rem;
  color: var(--muted);
}
.info-box ul {
  list-style-position: inside;
  margin: 8px 0;
}

.container {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.container.vertical {
  flex-direction: column;
}

@media (max-width: 820px) {
  .header-right {
    align-items: stretch;
  }
  .hint,
  .error {
    text-align: left;
  }
  .advanced-controls {
    display: none;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
  .advanced-controls.open {
    display: inline-flex;
  }
  #advancedToggleBtn {
    display: inline-flex;
  }
}

@media (min-width: 821px) {
  #advancedToggleBtn {
    display: none;
  }
}

@media (max-width: 768px) {
  .main-content {
    padding-bottom: 0;
  }
  .footer {
    display: none;
  }
  .container {
    flex-direction: column !important;
  }
  .video-section {
    order: 1;
  }
  .chat-section {
    order: 2;
  }
  .chat-section {
    border-left: none !important;
    border-top: 1px solid var(--border) !important;
  }
  .resize-handle {
    display: none !important;
  }
  .header {
    padding: 8px 12px;
  }
  .controls-row {
    gap: 8px;
  }
  .channel-input {
    padding: 8px 10px;
  }
  button {
    padding: 8px 10px;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
    padding: 8px;
  }
  .hint {
    font-size: 0.7rem;
  }
  .section-header {
    min-height: 40px;
    padding: 6px 10px;
  }
  #layoutBtn {
    display: none !important;
  }
  #theatreBtn {
    display: none !important;
  }
  .desktop-only {
    display: none !important;
  }
  .hint {
    text-align: center !important;
  }
  .section-header {
    flex-wrap: wrap;
    justify-content: center;
  }
  .video-section .section-header,
  .chat-section .section-header {
    display: none;
  }
  .section-header-left {
    width: 100%;
    justify-content: center;
  }
  .section-header-right {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .player-controls {
    justify-content: center;
    width: 100%;
  }
  .player-status {
    text-align: center;
    min-width: 0;
    width: 100%;
  }
  .quality-select {
    margin: 0 auto;
  }
  #chatDrawerBtn {
    display: inline-flex;
  }
  #rotateVideoBtn {
    display: inline-flex;
  }
  .chat-section {
    display: none !important;
  }
  body.chat-drawer-open .chat-section {
    display: flex !important;
  }
  .footer-note {
    display: none;
  }
  .history-menu {
    right: 0;
    left: auto;
    max-width: 80vw;
  }
  .icon-label-btn .btn-text {
    display: none;
  }
  .icon-label-btn {
    gap: 0;
    padding-left: 10px;
    padding-right: 10px;
  }
  .icon-label-btn svg {
    width: 18px;
    height: 18px;
  }
}

.container.mobile-stack {
  flex-direction: column !important;
}
.container.mobile-stack .video-section {
  order: 1;
}
.container.mobile-stack .chat-section {
  order: 2;
}
.container.mobile-stack {
  height: 100%;
}
.container.mobile-stack .video-section,
.container.mobile-stack .chat-section {
  flex: 1 1 0;
}

@media (max-width: 768px) {
  body.video-rotated .video-section {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 1700;
    background: #000;
  }
  body.video-rotated #videoFrame,
  body.video-rotated .player-host {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100vh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(-90deg);
    transform-origin: center;
    z-index: 1701;
  }
  body.video-rotated .chat-section,
  body.video-rotated .footer,
  body.video-rotated .header {
    display: none !important;
  }
  body.video-rotated .rotate-exit-btn {
    display: inline-flex;
  }
}

body.chat-drawer-open .chat-section {
  display: flex !important;
}
body.chat-drawer-open .chat-drawer-backdrop {
  display: block;
}

.video-section,
.chat-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.section-header {
  background: var(--panel);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 48px;
}

.section-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.section-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-status {
  font-size: 0.78rem;
  color: var(--muted2);
  min-width: 70px;
  text-align: right;
}
.player-status.online {
  color: var(--green);
}
.player-status.offline,
.player-status.blocked {
  color: var(--danger);
}

.player-controls {
  display: none;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.player-controls.active {
  display: inline-flex;
}

.range-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 4px;
}
.range-control input[type='range'] {
  width: 90px;
  accent-color: var(--accent);
}

.quality-select {
  background: #2c2c34;
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: 6px;
  font-size: 0.78rem;
  padding: 4px 6px;
}

.player-host {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: none;
}
.player-host.active {
  display: block;
}

.control-warning {
  font-size: 0.72rem;
  color: var(--muted2);
}

.section-header svg {
  width: 16px;
  height: 16px;
}
.video-section .section-header svg {
  fill: var(--accent);
  stroke: none;
}
.chat-section .section-header svg {
  fill: var(--green);
  stroke: none;
}

iframe {
  flex: 1;
  border: none;
  width: 100%;
  min-height: 0;
}

.chat-section {
  border-left: 1px solid var(--border);
  position: relative;
}

.chat-drawer-header {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px;
  background: rgba(24, 24, 27, 0.92);
  border-bottom: 1px solid var(--border);
  z-index: 2000;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  backdrop-filter: blur(6px);
}

.chat-drawer-title {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-drawer-close {
  font-size: 0.75rem;
}

.rotate-exit-btn {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1801;
  padding: 8px 10px;
  font-size: 0.75rem;
  backdrop-filter: blur(6px);
}

.container.vertical .chat-section {
  border-left: none;
  border-top: 1px solid var(--border);
}

.container.chat-hidden .chat-section {
  display: none;
}

.container.chat-hidden .video-section {
  width: 100%;
  height: 100%;
}

.chat-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1800;
}

.chat-drawer-open .chat-drawer-backdrop {
  display: block;
}

.chat-drawer-open .chat-section {
  display: flex !important;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 88vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 24px rgba(0, 0, 0, 0.4);
  z-index: 1900;
  opacity: 1;
  visibility: visible;
}

body.chat-drawer-open .chat-section {
  padding-top: 44px;
}

body.chat-drawer-open .chat-drawer-header {
  display: flex;
}

.chat-drawer-open .chat-section iframe {
  min-height: 0;
}

/* Bigger resize hit area + visible guide while dragging */
.resize-handle {
  position: absolute;
  left: -6px; /* makes it easier to grab */
  top: 0;
  bottom: 0;
  width: 14px;
  cursor: ew-resize;
  background: transparent;
  z-index: 10;
}

.container.vertical .resize-handle {
  left: 0;
  right: 0;
  top: -6px;
  bottom: auto;
  width: auto;
  height: 14px;
  cursor: ns-resize;
}

.resize-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  left: 0; /* anchored to divider edge */
  opacity: 0;
  pointer-events: none;
  z-index: 9;
  transition: opacity 120ms ease;
}
.container.vertical .resize-guide {
  left: 0;
  right: 0;
  top: 0;
  bottom: auto;
  width: auto;
  height: 3px;
}

.chat-section:hover .resize-guide {
  opacity: 0.85;
}
.resizing .resize-guide {
  opacity: 1;
}

.resize-label {
  position: absolute;
  z-index: 11;
  background: rgba(31, 31, 35, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.8rem;
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  white-space: nowrap;
}

.resizing .resize-guide,
.resizing .resize-label {
  opacity: 1;
}

.footer {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 0.75rem;
  color: var(--muted2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.channel-name {
  color: var(--accent);
  font-weight: 650;
}

.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 2px solid var(--accent);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 1000;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.3);
}
.cookie-banner.hidden {
  display: none;
}
.cookie-content {
  flex: 1;
  min-width: 240px;
}
.cookie-content h3 {
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
}
.cookie-content p {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.5;
}
.cookie-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-accept {
  background: var(--accent);
}
.btn-decline {
  background: transparent;
  border: 1px solid var(--border2);
}
.btn-decline:hover {
  background: #2c2c34;
}

.noscript-notice {
  background: rgba(255, 255, 255, 0.96);
  color: #000;
  padding: 10px;
  text-align: center;
}

.loading-text {
  color: var(--muted);
}

.info-note {
  margin-top: 10px;
  font-size: 0.78rem;
}

#container {
  display: none;
}
