/* ============================================
   LiveStream — 四窗口直播 CSS v2
   Dark glass theme · responsive · hi-DPI aware
   Optimized for 1920×1080 / 2560×1440 sources
   ============================================ */

:root {
  /* Palette */
  --bg-primary: #07070f;
  --bg-secondary: rgba(16, 16, 30, 0.85);
  --bg-card: #12121f;
  --bg-card-hover: #191928;
  --bg-input: rgba(26, 26, 46, 0.8);
  --border-color: rgba(120, 120, 170, 0.14);
  --border-strong: rgba(140, 140, 200, 0.25);
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --accent-dim: rgba(99, 102, 241, 0.12);
  --text-primary: #eef0f8;
  --text-secondary: #9aa0b5;
  --text-muted: #5a5e75;
  --success: #34d399;
  --success-glow: rgba(52, 211, 153, 0.5);
  --warning: #fbbf24;
  --danger: #f87171;

  /* Sizing */
  --header-height: 54px;
  --radius-lg: 14px;
  --radius-md: 9px;
  --radius-sm: 7px;
  --gap: 12px;

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-med: 280ms cubic-bezier(0.4, 0, 0.2, 1);

  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

/* ============================================
   Reset & Base
   ============================================ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
}

body {
  /* dvh fixes iOS dynamic toolbar viewport bug */
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display",
    "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(99, 102, 241, 0.09), transparent),
    radial-gradient(ellipse 60% 40% at 90% 110%, rgba(139, 92, 246, 0.07), transparent),
    var(--bg-primary);
  background-attachment: fixed;
  color: var(--text-primary);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

/* ============================================
   Header — glass bar
   ============================================ */
.header {
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  padding-top: env(safe-area-inset-top);
  background: var(--bg-secondary);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(135deg, #818cf8, #6366f1);
  box-shadow: 0 0 10px var(--accent-glow), 0 0 22px rgba(99, 102, 241, 0.2);
  animation: logo-pulse 2.4s ease-in-out infinite;
}

@keyframes logo-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.86); }
}

.logo-text {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #fff 20%, #a5b4fc 60%, #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  padding: 0 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-touch-callout: none;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.96);
}

.btn svg { flex-shrink: 0; }

.btn-header {
  height: 32px;
  padding: 0 12px;
  font-size: 12.5px;
  background: rgba(255, 255, 255, 0.05);
}

.btn-header:hover {
  background: rgba(129, 140, 248, 0.15);
  border-color: rgba(129, 140, 248, 0.4);
  color: #c7d2fe;
}

.btn-settings {
  width: 32px;
  padding: 0;
  border-radius: 50%;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #818cf8, #6366f1);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background: transparent;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: rgba(129, 140, 248, 0.18);
  color: #c7d2fe;
}

.btn-icon:active {
  transform: scale(0.9);
}

.btn-connect {
  height: 30px;
  width: 30px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border: none;
  color: #fff;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-connect:hover {
  background: linear-gradient(135deg, #818cf8, #6366f1);
  box-shadow: 0 3px 12px rgba(99, 102, 241, 0.45);
}

.btn-connect.connected {
  background: linear-gradient(135deg, #f87171, #dc2626);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
}

/* ============================================
   Modal panels (settings / push)
   ============================================ */
.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 12, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.settings-panel.active {
  display: flex;
}

.settings-content {
  background: linear-gradient(160deg, #17172a, #10101d);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 100%;
  max-width: 430px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: modal-in 240ms cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.settings-content h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

.form-group { margin-bottom: 15px; }

.form-group label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-group input,
.form-group select {
  width: 100%;
  height: 40px;
  padding: 0 13px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: var(--font-mono);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-group select {
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa0b5' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 38px;
}

.form-group select option {
  background: #17172a;
  color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-dim);
}

.form-group input::placeholder { color: var(--text-muted); }
.form-group input[readonly] { color: var(--text-secondary); cursor: default; }

.form-hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-top: 5px;
}

.form-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ============================================
   Grid — 2×2 desktop
   ============================================ */
.grid-container {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
  overflow: hidden;
}

/* Large desktop: breathe more */
@media (min-width: 1800px) {
  :root { --gap: 16px; --header-height: 58px; }
  .logo-text { font-size: 18px; }
}

/* ============================================
   Stream Window — card
   ============================================ */
.stream-window {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
  min-width: 0;
  transition: border-color var(--transition-med), box-shadow var(--transition-med);
  box-shadow: var(--shadow-card);
}

.stream-window.connected {
  border-color: rgba(99, 102, 241, 0.55);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25), 0 4px 28px rgba(99, 102, 241, 0.18);
}

.stream-window.error {
  border-color: rgba(248, 113, 113, 0.45);
  box-shadow: 0 4px 24px rgba(239, 68, 68, 0.12);
}

/* ---- Window header ---- */
.window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--border-color);
  min-height: 36px;
}

.window-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: nowrap;
}

.window-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-offline { background: var(--text-muted); }

.status-connecting {
  background: var(--warning);
  animation: status-blink 1s ease-in-out infinite;
}

.status-online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
}

.status-error { background: var(--danger); }

@keyframes status-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.window-label {
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-window.connected .window-label { color: var(--text-primary); }

.window-latency,
.window-res {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.5px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.stream-window.connected .window-latency {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.25);
}

.window-res { color: #a5b4fc; border-color: rgba(129, 140, 248, 0.25); }

.window-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ---- Video area ---- */
.window-video-area {
  flex: 1;
  position: relative;
  background: #000;
  min-height: 0;
  overflow: hidden;
}

.window-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: #000;
}

.window-video.active { display: block; }

.window-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12.5px;
  background:
    repeating-linear-gradient(45deg, transparent, transparent 12px, rgba(255,255,255,0.012) 12px, rgba(255,255,255,0.012) 24px);
}

.window-placeholder svg {
  opacity: 0.3;
  animation: float-slow 3.5s ease-in-out infinite;
}

@keyframes float-slow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.window-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(5, 5, 12, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: var(--text-secondary);
  font-size: 12.5px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(255, 255, 255, 0.09);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Controls ---- */
.window-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--border-color);
}

.stream-input-group {
  flex: 1;
  display: flex;
  gap: 5px;
  min-width: 0;
}

.stream-input {
  flex: 1;
  height: 30px;
  padding: 0 11px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  min-width: 0;
  user-select: text;
  -webkit-user-select: text;
}

.stream-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.stream-input::placeholder { color: var(--text-muted); }

.control-buttons {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ============================================
   Toast
   ============================================ */
.toast-container {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 7px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 550;
  color: var(--text-primary);
  background: rgba(23, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.3s cubic-bezier(0.34, 1.3, 0.64, 1), toast-out 0.3s ease 2.6s forwards;
  pointer-events: auto;
  max-width: 90vw;
  text-align: center;
}

.toast.success { border-color: rgba(52, 211, 153, 0.5); color: #a7f3d0; }
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
.toast.warning { border-color: rgba(251, 191, 36, 0.5); color: #fde68a; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

/* ============================================
   Fullscreen
   ============================================ */
.stream-window:fullscreen,
.stream-window:-webkit-full-screen {
  border-radius: 0;
  border: none;
  background: #000;
}

.stream-window:fullscreen .window-header,
.stream-window:-webkit-full-screen .window-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  background: linear-gradient(rgba(0,0,0,0.65), transparent);
  border-bottom: none;
}

.stream-window:fullscreen .window-video-area,
.stream-window:-webkit-full-screen .window-video-area {
  position: absolute;
  inset: 0;
}

.stream-window:fullscreen .window-controls,
.stream-window:-webkit-full-screen .window-controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 5;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  border-top: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.stream-window:fullscreen .window-header,
.stream-window:-webkit-full-screen .window-header {
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.stream-window:fullscreen:hover .window-controls,
.stream-window:fullscreen:hover .window-header,
.stream-window:-webkit-full-screen:hover .window-controls,
.stream-window:-webkit-full-screen:hover .window-header {
  opacity: 1;
}

/* ============================================
   Tablet ≤ 1024px
   ============================================ */
@media (max-width: 1024px) {
  :root { --gap: 9px; --header-height: 48px; }

  .btn-header span { display: none; }
  .btn-header { width: 32px; padding: 0; }

  .stream-input { font-size: 11px; }
}

/* ============================================
   Phone ≤ 768px — 2×2 compact
   ============================================ */
@media (max-width: 768px) {
  :root { --gap: 6px; --header-height: 46px; --radius-lg: 11px; }

  body { overflow: hidden; }

  .grid-container {
    gap: var(--gap);
    padding: var(--gap);
    padding-left: max(var(--gap), env(safe-area-inset-left));
    padding-right: max(var(--gap), env(safe-area-inset-right));
  }

  .header { padding-left: 12px; padding-right: 12px; }
  .logo-text { font-size: 15px; }
  .btn-header { height: 29px; width: 29px; }

  .window-header { padding: 4px 8px; min-height: 27px; }
  .window-label { font-size: 10.5px; }
  .window-latency, .window-res { font-size: 9px; padding: 1px 6px; }

  .window-controls { padding: 5px 6px; gap: 4px; }
  .stream-input { height: 26px; padding: 0 8px; font-size: 10px; border-radius: 6px; }
  .btn-connect { width: 26px; height: 26px; border-radius: 6px; }
  .btn-connect svg { width: 11px; height: 11px; }
  .btn-icon { width: 25px; height: 25px; }
  .btn-icon svg { width: 12px; height: 12px; }
  .window-status { width: 6.5px; height: 6.5px; }
}

/* ============================================
   Phone portrait ≤ 640px — 单列堆叠可滚动
   竖屏看游戏直播：每窗接近全宽，上下滑动
   ============================================ */
@media (max-width: 640px) and (orientation: portrait) {
  body { overflow: hidden; }

  .grid-container {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: minmax(0, 1fr);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scrollbar-width: none;
  }

  .grid-container::-webkit-scrollbar { display: none; }
}

/* 手机横屏保持 2×2，压缩头部控件 */
@media (max-width: 900px) and (orientation: landscape) {
  :root { --header-height: 40px; --gap: 5px; }
  .header { padding-top: 0; }
  .logo-dot { width: 8px; height: 8px; }
  .logo-text { font-size: 13px; }
  .btn-header { height: 26px; width: 26px; }
  .btn-header svg { width: 12px; height: 12px; }
  .window-header { min-height: 22px; padding: 2px 6px; }
  .window-controls { padding: 3px 5px; }
  .stream-input { height: 22px; font-size: 9.5px; }
  .btn-connect { width: 22px; height: 22px; }
  .btn-icon { width: 22px; height: 22px; }
}

/* ============================================
   Small phone ≤ 400px
   ============================================ */
@media (max-width: 400px) {
  :root { --gap: 4px; }
  .window-placeholder svg { width: 26px; height: 26px; }
  .window-placeholder span { font-size: 10.5px; }
  .stream-input { font-size: 9px; height: 24px; }
  .btn-connect { width: 24px; height: 24px; }
  .btn-icon { width: 23px; height: 23px; }
  .window-res { display: none; } /* 太窄时隐藏分辨率徽章 */
}

/* ============================================
   Scrollbar
   ============================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(140, 140, 200, 0.2);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(140, 140, 200, 0.35); }

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