:root {
  --bg: #ffffff;
  --text: #0f0f0f;
  --muted: #606060;
  --border: #e5e5e5;
  --chip: #f2f2f2;
  --red: #ff0000;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.yt-header {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.yt-logo { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text); }
.yt-mark { display: inline-grid; place-items: center; width: 30px; height: 21px; background: var(--red); border-radius: 6px; }
.yt-mark svg { width: 14px; height: 14px; margin-left: 1px; }
.yt-title { font-weight: 700; font-size: 1.25rem; letter-spacing: -0.5px; }
.yt-header .subscribe-btn { margin-left: auto; }

/* ---------- Subscribe button ---------- */
.subscribe-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  background: var(--red);
  color: #fff;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 9px 16px;
  border-radius: 999px;
  transition: filter 0.15s;
  white-space: nowrap;
}
.subscribe-btn:hover { filter: brightness(0.92); }
.sub-icon { width: 20px; height: 20px; }

/* ---------- Layout: video + chat ---------- */
.content {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}
.primary { min-width: 0; }

.player { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16 / 9; }
video { display: block; width: 100%; height: 100%; background: #000; }

/* Overlay while offline */
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center; text-align: center;
  padding: 24px; color: #fff; background: #0f0f0f; transition: opacity 0.4s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay h2 { margin: 0 0 8px; font-size: 1.2rem; font-weight: 500; }
.overlay p { margin: 0 auto; color: #aaa; max-width: 420px; font-size: 0.95rem; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--red);
  animation: spin 0.9s linear infinite; margin: 0 auto 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Title + live badge */
.video-title { display: flex; align-items: center; gap: 12px; font-size: 1.4rem; font-weight: 700; margin: 16px 0 12px; line-height: 1.3; }
.live-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; padding: 4px 9px; border-radius: 6px; }
.live-badge .live-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.live-badge.offline { background: var(--chip); color: var(--muted); }
.live-badge.online { background: var(--red); color: #fff; }
.live-badge.online .live-dot { background: #fff; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.viewer-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}
.viewer-count svg { width: 16px; height: 16px; }

/* Channel row */
.channel-row { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.channel { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.avatar { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--red); flex: none; }
.avatar svg { width: 20px; height: 20px; margin-left: 2px; }
.channel-info { display: flex; flex-direction: column; }
.channel-name { font-weight: 500; font-size: 1rem; }
.channel-sub { color: var(--muted); font-size: 0.85rem; }
.channel-row .subscribe-btn { margin-left: auto; }

/* ---------- Live chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  height: min(78vh, 640px);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  position: sticky;
  top: 72px;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
}
.chat-state { font-size: 0.72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.chat-state.ok { color: var(--red); }

.chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg { font-size: 0.9rem; line-height: 1.35; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-name { font-weight: 700; color: var(--muted); margin-right: 7px; }
.msg-text { color: var(--text); }

.chat-foot { border-top: 1px solid var(--border); padding: 12px; }

.name-gate, .msg-form { display: flex; gap: 8px; }
.chat-foot input {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.chat-foot input:focus { outline: none; border-color: #909090; }
.name-gate button, .msg-form button {
  border: none;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  font: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msg-form button { width: 42px; padding: 0; flex: none; }
.msg-form button svg { width: 20px; height: 20px; }
.name-gate button:hover, .msg-form button:hover { filter: brightness(0.92); }

.chat-as { margin-top: 8px; font-size: 0.78rem; color: var(--muted); text-align: center; }
.chat-as a { color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .content { grid-template-columns: 1fr; }
  .chat { height: 460px; position: static; }
}
@media (max-width: 560px) {
  .content { margin: 14px auto; padding: 0 12px; gap: 16px; }
  .video-title { font-size: 1.15rem; }
  .channel-row .subscribe-btn { margin-left: 0; }
}
