@font-face {
  font-family: 'Excalifont';
  src: url('/assets/excalifont.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: var(--tg-theme-bg-color, #121318);
  --bg2: var(--tg-theme-secondary-bg-color, #1d1f27);
  --text: var(--tg-theme-text-color, #f1f3f8);
  --hint: var(--tg-theme-hint-color, #8e95a8);
  --btn: var(--tg-theme-button-color, #3b82f6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --chat-font: 'Excalifont', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }

.app-root {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  background: var(--bg);
}

.topbar {
  padding: 8px 10px 6px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  z-index: 10;
  flex-shrink: 0;
}

.room-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}

.room-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-pill {
  background: rgba(255,255,255,0.08);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--hint);
}

.search-form {
  display: flex;
  gap: 6px;
}

.yt-input, .chat-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
}

.yt-input:disabled { opacity: 0.65; }

.tg-btn {
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.tg-btn-sec {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.search-error {
  margin-top: 5px;
  font-size: 12px;
  color: #f87171;
}

.player-stage {
  position: relative;
  width: 100%;
  flex-shrink: 0;
  background: #000;
  overflow: hidden;
  padding: 8px 10px 4px;
}

.ambient-layer {
  position: absolute;
  inset: -25px;
  background-size: cover;
  background-position: center;
  filter: blur(42px) saturate(1.8) brightness(0.65);
  opacity: 0;
  transition: opacity 0.6s ease, background-image 0.6s ease;
  pointer-events: none;
  z-index: 0;
}

.ambient-layer.active { opacity: 0.85; }

.player-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #090a0e;
  z-index: 1;
  box-shadow: 0 8px 30px rgba(0,0,0,0.65);
}

#ytPlayer, #ytPlayer iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.player-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--hint);
  gap: 8px;
  background: rgba(12,13,18,0.88);
}

.empty-icon { font-size: 32px; }
.empty-text { font-size: 13px; text-align: center; padding: 0 16px; }

.tap-sync-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  z-index: 3;
}

.stage-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
}

.now-playing {
  font-size: 12px;
  color: rgba(255,255,255,0.82);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-section {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chat-feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--chat-font);
}

.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: msgIn 0.16s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  cursor: pointer;
}

.chat-body {
  min-width: 0;
  flex: 1;
  background: var(--bg2);
  padding: 6px 10px;
  border-radius: 12px;
  word-break: break-word;
}

.chat-nick {
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: inline-block;
  margin-bottom: 2px;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}

.chat-text {
  font-size: 15px;
  line-height: 1.3;
  color: var(--text);
}

.chat-sticker-wrap { margin-top: 4px; }
.chat-sticker { width: 112px; height: 112px; object-fit: contain; display: block; }
.chat-ce { width: 36px; height: 36px; object-fit: contain; display: block; }

.sys-msg {
  text-align: center;
  font-size: 12px;
  color: var(--hint);
  padding: 2px 0;
}

.picker-panel {
  height: 210px;
  background: var(--bg2);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
}

.picker-tabs {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.picker-tab {
  background: var(--bg);
  color: var(--hint);
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.picker-tab.active {
  background: var(--btn);
  color: var(--btn-text);
}

.picker-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 6px;
}

.picker-item {
  width: 100%;
  aspect-ratio: 1;
  background: rgba(255,255,255,0.04);
  border: none;
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.picker-item img, .picker-item video, .picker-item .lottie-box {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-input-bar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg2);
  border-top: 1px solid rgba(255,255,255,0.08);
}

.chat-input {
  font-family: var(--chat-font);
  font-size: 15px;
}

.icon-btn {
  background: var(--bg);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  width: 38px;
  font-size: 18px;
  cursor: pointer;
}

.fs-overlay { display: none; }

.player-stage.is-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  padding: 0;
  z-index: 100;
  background: #000;
}

.player-stage.is-fullscreen .ambient-layer { display: none; }

.player-stage.is-fullscreen .player-box {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
}

.player-stage.is-fullscreen .stage-bar { display: none; }

.player-stage.is-fullscreen .fs-overlay {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.fs-top-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
  transition: opacity 0.25s ease;
}

.fs-toggle-chat {
  background: var(--btn);
  color: var(--btn-text);
  opacity: 0.92;
}

.fs-stream-chat {
  position: absolute;
  top: 56px;
  right: 12px;
  bottom: 16px;
  width: min(320px, 46vw);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  overflow: hidden;
  pointer-events: none;
  font-family: var(--chat-font);
  transition: opacity 0.25s ease;
}

.fs-stream-item {
  background: transparent;
  padding: 2px 4px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.95), 0 0 8px rgba(0,0,0,0.85);
  color: #fff;
  font-size: 14px;
  line-height: 1.25;
  word-break: break-word;
}

.fs-stream-item .chat-nick {
  font-size: 14px;
  margin-right: 5px;
  margin-bottom: 0;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.9));
}

.fs-stream-item .chat-sticker { width: 72px; height: 72px; margin-top: 2px; }
.fs-stream-item .chat-ce { width: 28px; height: 28px; display: inline-block; vertical-align: middle; }

.player-stage.is-fullscreen.chat-off .fs-stream-chat {
  opacity: 0;
  pointer-events: none;
}

.player-stage.is-fullscreen.chat-off.ui-idle .fs-top-controls {
  opacity: 0;
  pointer-events: none;
}

.popover, .fatal-screen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.popover-card, .fatal-box {
  background: var(--bg2);
  color: var(--text);
  border-radius: 16px;
  padding: 16px;
  width: min(300px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.popover-name { font-weight: 700; font-size: 16px; }
.danger-btn {
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-weight: 600;
  cursor: pointer;
}
.popover-close {
  background: transparent;
  color: var(--hint);
  border: none;
  padding: 6px;
  cursor: pointer;
}
.fatal-emoji { font-size: 38px; }
