:root {
  --bg: #0e0f12;
  --panel: #17191f;
  --line: #262a33;
  --text: #e7e9ee;
  --muted: #8b90a0;
  --accent: #3d7dff;
  --ok: #2ec16a;
  --off: #6b7280;
  --err: #ff5a5a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }
/* dvh = the CURRENTLY visible viewport (tracks the mobile URL/nav bars as they
 * show/hide), so fixed views never extend under the browser chrome. vh fallback
 * for engines without dvh. */
.view { position: fixed; top: 0; left: 0; right: 0; height: 100vh; height: 100dvh; }
[hidden] { display: none !important; }

/* ---- Login ---- */
#login { display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card input { background: #0f1116; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font-size: 16px; }
.login-card button { background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 12px; font-size: 16px; font-weight: 600; }
.error { color: var(--err); font-size: 13px; min-height: 16px; margin: 4px 0 0; text-align: center; }
/* Text-link look for the login⇄signup toggle. Two classes beat `.login-card
 * button` (one class + type) on specificity, so the accent-filled button style
 * is overridden. */
.login-card .link-btn { background: transparent; color: var(--muted); border: 0;
  padding: 4px; font-size: 14px; font-weight: 400; cursor: pointer; }

/* ---- Wall ---- */
.wall-bar { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.wall-title { font-weight: 700; }
.wall-status { color: var(--muted); font-size: 13px; margin-left: auto; }
.wall-bar button { background: transparent; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.wall-quality { background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 14px; }

.grid { position: absolute; top: 52px; bottom: 0; left: 0; right: 0; overflow-y: auto;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px;
  grid-auto-rows: calc((100vh - 76px) / 2);
  grid-auto-rows: calc((100dvh - 76px) / 2);   /* row = half the visible grid area */
  scroll-snap-type: y proximity; align-content: start; }
/* Each row is half the visible grid height (grid 100dvh−52 bar, minus 8 padding·2
 * + 8 gap = 76), so a 2×2 page fits ONE screen with no scroll; portrait video
 * letterboxes inside its cell. >4 devices → extra rows scroll. */
.cell { scroll-snap-align: start; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; display: flex; flex-direction: column;
  min-height: 0; }
.cell-video { position: relative; flex: 1; min-height: 0; background: #000; display: grid; place-items: center; }
/* Fill the cell-video box (absolute inset:0 avoids the flex-child percentage-height
 * quirk where max-height:100% fails on Safari and the portrait canvas overflows
 * down over the action bar); object-fit:contain letterboxes the video inside.
 * touch-action:none → a swipe on the canvas drives the device, not the wall scroll. */
.cell-video canvas { position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; cursor: pointer; touch-action: none; }
.cell-badge { position: absolute; top: 6px; left: 6px; font-size: 11px; padding: 2px 7px;
  border-radius: 999px; background: rgba(0,0,0,.55); color: var(--muted); }
.cell-badge.online { color: var(--ok); }
.cell-badge.connecting { color: #ffb020; }
.cell-badge.error { color: var(--err); }
.cell-name { position: absolute; bottom: 6px; left: 8px; right: 8px; font-size: 12px;
  color: #d6d9e0; text-shadow: 0 1px 2px #000; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-offline { color: var(--off); font-size: 13px; }
/* Overlays sit above the canvas; let taps fall through to it. */
.cell-badge, .cell-name { pointer-events: none; }

.cell-actions { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.cell-actions button { background: transparent; color: var(--text); border: 0; border-right: 1px solid var(--line);
  padding: 10px 0; font-size: 13px; }
.cell-actions button:last-child { border-right: 0; }
.cell-actions button:disabled { color: var(--off); }
.cell-actions button.fs { color: var(--accent); font-weight: 600; }

/* ---- Manage (reorder + delete) ---- */
.manage-done { margin-left: auto; }
.manage-list { position: absolute; top: 52px; bottom: 0; left: 0; right: 0; overflow-y: auto;
  padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.manage-row { display: flex; align-items: center; gap: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.manage-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.manage-dot.on { background: var(--ok); }
.manage-dot.off { background: var(--off); }
.manage-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 15px; }
.manage-btn { background: transparent; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; min-width: 40px; }
.manage-btn:disabled { color: var(--off); opacity: .5; }
.manage-btn.del { color: var(--err); border-color: var(--err); }
.manage-hint { color: var(--muted); text-align: center; padding: 24px; font-size: 14px; }

/* ---- Fullscreen ---- */
/* Canvas fills the viewport and object-fit:contain letterboxes the video; the
 * letterbox offset is undone in sendTouch() so pointer→video mapping stays exact. */
.fullscreen { background: #000; }
/* Absolute inset:0 fills the fixed 100dvh view directly, so height resolves against
 * a DEFINITE box — not an auto-sized grid row (which made the canvas overflow and
 * cut off the bottom). object-fit:contain then letterboxes the video to fit. */
#full-canvas { position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; display: block; touch-action: none; }
.full-close { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; z-index: 3;
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(0,0,0,.5); color: #fff; font-size: 18px; }

/* Floating action button (only in fullscreen) */
.fab { position: absolute; right: 16px; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 3;
  display: flex; flex-direction: column-reverse; align-items: center; gap: 10px; }
.fab-main { width: 52px; height: 52px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25);
  background: rgba(20,22,28,.8); color: #fff; font-size: 22px; backdrop-filter: blur(6px); }
.fab-menu { display: none; flex-direction: column-reverse; gap: 8px; }
.fab.open .fab-menu { display: flex; }
.fab-menu button { min-width: 60px; padding: 10px 12px; border-radius: 22px;
  border: 1px solid rgba(255,255,255,.2); background: rgba(20,22,28,.85); color: #fff; font-size: 13px; }
