:root {
  --bg: #0f1115;
  --panel: #181b22;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #9aa1ad;
  --accent: #ff4d6d;
  --ok: #3ccf91;
  --warn: #f5b84a;
  --r: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

/* 16px inputs stop iOS Safari from zooming on focus. */
input[type="text"] {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  height: 44px;
  padding: 0 12px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--panel);
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

.btn {
  height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover { border-color: #3a4150; }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.big { height: 52px; font-size: 17px; width: 100%; }
.btn.icon { padding: 0 12px; font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 8px; align-items: center; }

/* Account pages */
.topbar {
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar .brand { flex: 1; font-weight: 600; }
.icon-link { display: inline-grid; place-items: center; padding: 0; }
.topbar a.btn { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; max-width: 50%; overflow: hidden; text-overflow: ellipsis; }
.page {
  margin: 0 auto;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.narrow { max-width: 560px; }
#screen-signin { padding-top: 14vh; }
.page h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.page h2 { margin: 0 0 8px; font-size: 18px; }
.page p { margin: 0 0 10px; }
.sub { margin: 0 0 8px; color: var(--muted); }
.small { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.note { color: var(--warn); }
.ok { color: var(--ok); font-size: 14px; margin-top: 6px; }
a { color: inherit; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
}
.card .btn { background: #20242d; }
.card .btn.primary { background: var(--accent); }
.card .row { margin-top: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.points { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; display: grid; gap: 6px; }
.btn.google { background: #fff; color: #1f1f1f; border-color: #fff; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.btn.danger { background: #3a1820; border-color: #6b2635; color: #ffb3c0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { opacity: 0.7; cursor: progress; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--text); text-decoration: underline; cursor: pointer; font-size: inherit; }
.code {
  font: 600 32px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.3em;
  margin: 8px 0 12px;
  color: var(--text);
}
.requests { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.request { border-top: 1px solid var(--line); padding-top: 12px; }
#invite-url { width: 100%; font-size: 14px; }
.danger-zone { border-color: #4a2029; }
.danger-zone input { text-transform: uppercase; }
.prose ul { margin: 0 0 12px; padding-left: 18px; display: grid; gap: 4px; }
.prose h2 { margin-top: 8px; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; background: #12151b; padding: 4px; border-radius: var(--r); }
.tab { flex: 1; height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.tab[aria-selected="true"] { background: #262b35; color: var(--text); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; }
.field input { flex: none; width: 100%; }
input[type="password"] {
  font-size: 16px; height: 44px; padding: 0 12px; border-radius: var(--r);
  border: 1px solid var(--line); background: #12151b; outline: none; width: 100%;
}
input[type="password"]:focus { border-color: var(--accent); }
.card input[type="text"] { background: #12151b; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn.google:disabled { opacity: 0.35; filter: grayscale(1); }

/* Room */
.room {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bar { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent); color: #fff;
  text-decoration: none; font-size: 16px;
}
.room-info { flex: 1; min-width: 0; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot[data-s="online"] { background: var(--ok); }
.dot[data-s="offline"] { background: var(--accent); }

.err { color: var(--accent); font-size: 14px; margin-top: -4px; }

.stage { width: 100%; }
.player-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--r);
  overflow: hidden;
}
/* On wide, short screens shrink the player (keeping 16:9) so the controls
   stay on screen without scrolling. */
@media (min-aspect-ratio: 4/3) {
  .stage { display: flex; justify-content: center; }
  .player-box { width: min(100%, calc((100vh - 260px) * 16 / 9)); }
  @supports (height: 100dvh) {
    .player-box { width: min(100%, calc((100dvh - 260px) * 16 / 9)); }
  }
}
.player-box iframe, #player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 24px; text-align: center; color: var(--muted);
}
.tap {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px;
  color: var(--text); font-size: 14px; white-space: nowrap; cursor: pointer;
}

.controls { display: flex; flex-direction: column; gap: 6px; }
.ctl-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.ctl-buttons { display: flex; gap: 8px; }
.time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.status { color: var(--muted); font-size: 13px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seek {
  --p: 0%;
  position: relative;
  height: 28px; /* big touch target, thin visual track */
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  outline: none;
}
.seek-track { position: relative; width: 100%; height: 4px; border-radius: 2px; background: var(--line); transition: height 0.1s; }
.seek-fill { position: absolute; inset: 0 auto 0 0; width: var(--p); border-radius: inherit; background: var(--accent); }
.seek-thumb {
  position: absolute; top: 50%; left: var(--p);
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.seek:hover .seek-track, .seek.dragging .seek-track { height: 6px; }
.seek.dragging .seek-thumb { transform: scale(1.3); }
.seek:focus-visible .seek-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Room layout: video column + chat. Narrow screens: chat is a tab. */
.room-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.room-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tabbar { display: flex; gap: 4px; background: #12151b; padding: 4px; border-radius: var(--r); margin-top: 6px; }
.tabbar .tab { position: relative; }
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
}
.panel[hidden] { display: none !important; }

@media (min-width: 900px) {
  .room-grid { grid-template-columns: minmax(0, 1fr) 320px; align-items: stretch; }
  /* Chat always visible beside the video; tabs only switch the lists below. */
  #chat, #chat.panel[hidden] { display: flex !important; }
  #tab-chat { display: none; }
}

/* Chat */
.chat {
  display: flex; flex-direction: column; gap: 8px; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px;
}
@media (min-width: 900px) {
  .chat { max-height: calc(100dvh - 90px); position: sticky; top: calc(10px + env(safe-area-inset-top, 0px)); }
}
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-head h2 { margin: 0; font-size: 16px; }
.small-btn { height: 32px; min-width: 32px; padding: 0 10px; font-size: 13px; }
.chat-log { flex: 1; min-height: 220px; max-height: 50vh; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; }
@media (min-width: 900px) { .chat-log { max-height: none; } }
.chat-older { align-self: center; margin: 4px 0 8px; font-size: 13px; color: var(--muted); }
.chat-empty { margin: auto; text-align: center; max-width: 220px; }
.chat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; margin-top: auto; }
.msg { max-width: 85%; display: flex; flex-direction: column; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .bubble {
  padding: 7px 11px; border-radius: 16px; background: #262b35;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.35;
}
.msg.mine .bubble { background: var(--accent); color: #fff; }
.msg.pending .bubble { opacity: 0.6; }
.msg.failed .bubble { background: #3a1820; color: #ffb3c0; }
.msg .meta-line { font-size: 11px; color: var(--muted); margin: 1px 6px 4px; }
.day { align-self: center; font-size: 11px; color: var(--muted); margin: 8px 0 4px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea {
  flex: 1; min-width: 0; resize: none; font: inherit; font-size: 16px; line-height: 1.35;
  padding: 11px 12px; max-height: 120px; min-height: 44px;
  color: var(--text); background: #12151b; border: 1px solid var(--line); border-radius: var(--r); outline: none;
}
.chat-form textarea:focus { border-color: var(--accent); }

/* History */
.hist-when { white-space: nowrap; }

/* "Watch this?" banner */
.proposal {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #1d2230;
  border: 1px solid #3a4560;
  border-radius: var(--r);
}
.proposal.theirs { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.thumb { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; background: #000; display: block; }
/* A thumbnail that didn't load: an empty dark box, not a broken-image icon. */
.thumb.missing { content: url('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='); }
.proposal-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.proposal-actions { display: flex; gap: 8px; }
.proposal .err { grid-column: 1 / -1; }

/* Shared playlists */
.lists { margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.lists-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lists-head h2 { margin: 0 auto 0 0; font-size: 17px; }
.lists select {
  height: 44px; max-width: 55%; min-width: 0; padding: 0 10px;
  font-size: 16px; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
}
.save-current { align-self: flex-start; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.item .thumb { width: 80px; height: 45px; }
.item-text { min-width: 0; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-actions { display: flex; gap: 4px; }
.item-actions .btn { padding: 0 10px; min-width: 40px; }
.item.playing { border-color: var(--ok); }
.confirm { flex-wrap: wrap; font-size: 14px; }

/* Toasts sit at the top so they never cover the playback buttons. */
.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  transform: translateX(-50%);
  pointer-events: none;
  max-width: calc(100% - 32px);
  background: #262b35;
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 10;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

/* Phone: tighter chrome, player goes edge to edge. */
@media (max-width: 600px) {
  .proposal, .lists { margin-left: 12px; margin-right: 12px; }
  .proposal { grid-template-columns: auto 1fr; }
  .proposal-actions { grid-column: 1 / -1; }
  .proposal-actions .btn { flex: 1; }
  .item { grid-template-columns: auto 1fr; }
  .item-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .lists-head { flex-wrap: nowrap; }
  .lists-head h2 { font-size: 15px; white-space: nowrap; }
  .lists select { flex: 1; max-width: none; }
  .load { flex-wrap: wrap; }
  .load input { flex-basis: 100%; }
  .load .btn { flex: 1; }
  .room { padding: 8px 0 16px; }
  .bar, .load, .err, .controls { padding: 0 12px; }
  .player-box { border-radius: 0; }
  .ctl-row { grid-template-columns: 1fr auto; }
  .ctl-row .status { grid-column: 1 / -1; text-align: left; }
  .time { order: 0; }
}

/* Phone in landscape: give the video the screen. */
@media (max-width: 600px) {
  .tabbar, .chat { margin-left: 12px; margin-right: 12px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .room { padding-top: 4px; }
  .load, .err { display: none; }
  .player-box { width: min(100%, calc((100dvh - 110px) * 16 / 9)); border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
}
