:root {
  color: #f4f1ec;
  background: #030406;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;

  --bg: #030406;
  --bg-elevated: #0b0d12;
  --bg-panel: rgba(13, 15, 21, 0.92);
  --bg-panel-soft: rgba(19, 22, 31, 0.74);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f1ec;
  --text-soft: #c8c2bb;
  --text-muted: #85818a;
  --brand: #ff5e9c;
  --brand-2: #9c6cff;
  --brand-soft: rgba(255, 94, 156, 0.16);
  --ok: #79e6b3;
  --danger: #ff7272;
  --shadow-stage: 0 26px 90px rgba(0, 0, 0, 0.68);
  --shadow-panel: 0 18px 60px rgba(0, 0, 0, 0.42);
  --radius: 8px;
  --control-h: 42px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 16%),
    linear-gradient(116deg, rgba(255, 94, 156, 0.09), transparent 28%),
    linear-gradient(244deg, rgba(156, 108, 255, 0.07), transparent 30%),
    #030406;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.014) 1px, transparent 1px);
  background-size: 76px 76px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent 62%);
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

button {
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  -webkit-tap-highlight-color: transparent;
  font-size: 15px;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.085);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

input {
  width: 100%;
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  -webkit-tap-highlight-color: transparent;
  font-size: 16px;
}

input::placeholder {
  color: rgba(200, 194, 187, 0.58);
}

input:focus {
  border-color: rgba(255, 94, 156, 0.58);
  box-shadow: 0 0 0 3px rgba(255, 94, 156, 0.14);
}

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(10, 12, 18, 0.86), rgba(3, 4, 6, 0.96)),
    linear-gradient(125deg, rgba(255, 94, 156, 0.12), transparent 34%);
  backdrop-filter: blur(18px);
}

.onboarding-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 24px;
  display: grid;
  gap: 14px;
  background: rgba(11, 13, 18, 0.94);
  box-shadow: var(--shadow-panel);
}

.onboarding-logo {
  width: 190px;
  max-width: 70%;
  justify-self: center;
  filter: drop-shadow(0 16px 28px rgba(255, 94, 156, 0.16));
}

.onboarding-panel h1 {
  margin: 4px 0 0;
  text-align: center;
  font-size: 24px;
  letter-spacing: 0;
}

.onboarding-panel p {
  margin: 0 0 4px;
  color: var(--text-muted);
  text-align: center;
}

.onboarding-panel button[type="submit"],
.chat-form button {
  border-color: rgba(255, 94, 156, 0.42);
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 12px 26px rgba(255, 94, 156, 0.18);
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 16px;
  padding: 16px;
  align-items: stretch;
}

.watch-stage {
  min-width: 0;
  display: grid;
  min-height: calc(100vh - 32px);
  min-height: calc(100svh - 32px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.topbar {
  min-height: 58px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: rgba(9, 11, 16, 0.72);
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(255, 94, 156, 0.18));
}

.brand > div {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand p,
.watch-meta p,
.movie-panel span,
.muted {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.signal {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.045);
  white-space: nowrap;
}

.signal span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 114, 114, 0.1);
}

.signal.online {
  color: var(--text);
  border-color: rgba(121, 230, 179, 0.2);
  background: rgba(121, 230, 179, 0.07);
}

.signal.online span {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(121, 230, 179, 0.12);
}

.video-frame {
  position: relative;
  width: 100%;
  min-height: 0;
  aspect-ratio: 16 / 9;
  align-self: center;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 18%),
    #000;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-stage);
}

.video-frame::before {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.video-frame::before {
  inset: 0;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.035),
    inset 0 34px 52px rgba(255, 255, 255, 0.035),
    inset 0 -80px 96px rgba(0, 0, 0, 0.42);
}

.video-frame video {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

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

.danmaku-bubble {
  position: absolute;
  right: -42%;
  max-width: min(520px, 76%);
  padding: 4px 10px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.42);
  border-radius: 4px;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.86),
    0 0 12px rgba(0, 0, 0, 0.64);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: danmaku 7s linear forwards;
}

.empty-state {
  width: min(420px, calc(100% - 36px));
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
  color: var(--text);
}

.empty-state strong {
  font-size: 18px;
}

.empty-state span {
  color: var(--text-muted);
}

.loader {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 950ms linear infinite;
}

.watch-meta {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: rgba(9, 11, 16, 0.72);
  backdrop-filter: blur(20px);
}

.watch-meta strong {
  display: block;
  max-width: min(820px, 66vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#syncBadge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 11px;
  color: #ffe6ef;
  background: var(--brand-soft);
  border: 1px solid rgba(255, 94, 156, 0.26);
  font-size: 12px;
}

.side-panel {
  min-width: 0;
  min-height: 0;
  max-height: calc(100vh - 32px);
  max-height: calc(100svh - 32px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 18%),
    var(--bg-panel);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(22px);
}

.drawer-tabs {
  min-height: 42px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.drawer-tab {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  color: var(--text-muted);
  background: transparent;
  box-shadow: none;
  font-size: 13px;
}

.drawer-tab:hover:not(:disabled) {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.055);
}

.drawer-tab.active {
  color: #fff;
  background: rgba(255, 94, 156, 0.16);
}

.drawer-panel {
  min-height: 0;
  display: none;
}

.drawer-panel.active {
  display: grid;
}

.movie-panel,
.people-panel,
.chat-panel {
  border-radius: var(--radius);
  padding: 4px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text-soft);
  font-size: 13px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.panel-title span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px rgba(255, 94, 156, 0.1);
}

.panel-title h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.movie-panel,
.people-panel {
  align-content: start;
  gap: 6px;
  padding: 8px 4px 4px;
}

.movie-panel strong {
  overflow-wrap: anywhere;
}

.people-list {
  display: grid;
  gap: 8px;
}

.person-row {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 11px;
  background: rgba(255, 255, 255, 0.045);
}

.person-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-row em {
  flex: 0 0 auto;
  font-style: normal;
  font-size: 12px;
  color: var(--ok);
}

.person-row.offline {
  opacity: 0.58;
}

.person-row.offline em {
  color: var(--text-muted);
}

.chat-panel {
  display: none;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.chat-panel.active {
  display: grid;
}

.chat-list {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.chat-list::-webkit-scrollbar {
  width: 8px;
}

.chat-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.chat-empty {
  min-height: 160px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.7;
}

.chat-message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.045);
}

.chat-message.screen-message {
  border-color: rgba(255, 94, 156, 0.22);
  background: rgba(255, 94, 156, 0.08);
}

.chat-message strong {
  display: block;
  color: #ff9fc8;
  font-size: 12px;
  margin-bottom: 4px;
}

.chat-message p {
  margin: 0;
  overflow-wrap: anywhere;
}

.message-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-button {
  min-height: 36px;
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: none;
}

.mode-button.active {
  color: #fff;
  border-color: rgba(255, 94, 156, 0.34);
  background: rgba(255, 94, 156, 0.14);
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
}

.chat-form button {
  padding: 0;
}

.settings-link {
  min-height: 28px;
  justify-self: center;
  border: 0;
  padding: 0 8px;
  color: rgba(200, 194, 187, 0.52);
  background: transparent;
  box-shadow: none;
  font-size: 12px;
}

.settings-link:hover:not(:disabled) {
  color: #ffe6ef;
  border-color: transparent;
  background: transparent;
}

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

@keyframes danmaku {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(calc(-100vw - 100%));
  }
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .watch-stage {
    min-height: 0;
    grid-template-rows: auto auto auto;
  }

  .side-panel {
    max-height: none;
    min-height: 360px;
  }

  .video-frame {
    min-height: 0;
    aspect-ratio: 16 / 9;
  }

  .video-frame video {
    height: 100%;
    max-height: none;
  }
}

@media (min-width: 760px) and (max-width: 1120px) and (orientation: landscape) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .side-panel {
    max-height: calc(100vh - 32px);
    max-height: calc(100svh - 32px);
  }
}

@media (max-width: 560px) {
  body {
    background:
      linear-gradient(130deg, rgba(255, 94, 156, 0.08), transparent 34%),
      #030406;
  }

  body::before {
    opacity: 0.45;
  }

  .app-shell {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 10px;
  }

  .topbar {
    min-height: auto;
    align-items: center;
    flex-direction: row;
    gap: 8px;
    padding: 7px;
  }

  .watch-stage {
    gap: 10px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
  }

  .brand,
  .brand > div {
    min-width: 0;
  }

  .brand h1 {
    font-size: 17px;
  }

  .brand p {
    max-width: calc(100vw - 86px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
  }

  .signal {
    min-height: 30px;
    padding: 0 9px;
    font-size: 12px;
    max-width: 108px;
    overflow: hidden;
  }

  .signal strong {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .video-frame {
    border-radius: var(--radius);
    min-height: 0;
    align-self: start;
  }

  .danmaku-bubble {
    max-width: 82%;
    padding: 3px 8px;
    font-size: 13px;
  }

  .watch-meta {
    min-height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 9px 10px;
  }

  .watch-meta strong {
    max-width: calc(100vw - 42px);
  }

  #syncBadge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .side-panel {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
    height: min(46vh, 360px);
    min-height: 280px;
    max-height: none;
    padding: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-panel);
  }

  .side-panel::before {
    content: none;
  }

  .drawer-tabs {
    min-height: 40px;
    gap: 4px;
    padding: 4px;
  }

  .drawer-tab {
    min-height: 30px;
  }

  .movie-panel,
  .people-panel,
  .chat-panel {
    padding: 2px;
  }

  .panel-title {
    margin-bottom: 8px;
  }

  .panel-title h2 {
    font-size: 14px;
  }

  .people-list {
    gap: 6px;
  }

  .person-row {
    min-height: 36px;
  }

  .message-mode {
    gap: 6px;
  }

  .mode-button {
    min-height: 34px;
  }

  .chat-form {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .chat-form input,
  .chat-form button {
    min-height: 40px;
  }

  .onboarding {
    align-items: start;
    padding: 18px 12px;
    padding-top: max(18px, env(safe-area-inset-top));
  }

  .onboarding-panel {
    margin-top: 4vh;
    padding: 18px;
  }

  .onboarding-logo {
    width: 154px;
  }

  .onboarding-panel h1 {
    font-size: 21px;
  }
}

@media (max-width: 560px) and (max-height: 720px) {
  .side-panel {
    height: 300px;
    min-height: 260px;
  }
}
