/* HeraCloud — modern dark theme. Single sheet, hand-tuned. No framework.
   Color system: a single accent (cyan) on top of a layered slate background.
   Cards are subtly translucent ("glass") on a noisy radial backdrop. */

:root {
  color-scheme: dark;

  /* Surfaces — picked so cards 'rise' off the body without harsh borders */
  --bg:        #0a0e14;
  --bg-2:      #0f141c;
  --surface:   rgba(22, 28, 40, 0.72);
  --surface-2: rgba(30, 38, 54, 0.88);
  --border:    rgba(120, 145, 180, 0.14);
  --border-strong: rgba(120, 145, 180, 0.28);

  /* Type */
  --fg:        #e6eaf2;
  --fg-mute:   #9aa4b8;
  --fg-dim:    #6a7385;

  /* Accents — cyan/teal, evokes the cloud mark */
  --accent:        #06b6d4;
  --accent-hover:  #22d3ee;
  --accent-soft:   rgba(6, 182, 212, 0.14);
  --accent-strong: rgba(6, 182, 212, 0.55);

  --danger:        #f87171;
  --danger-soft:   rgba(248, 113, 113, 0.12);
  --warn:          #fbbf24;
  --ok:            #34d399;

  --radius:    10px;
  --radius-lg: 14px;
  --shadow-soft: 0 8px 24px rgba(0,0,0,0.35);
  --shadow-pop:  0 12px 40px rgba(0,0,0,0.55);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Backdrop — subtle radial-gradient halos so the page doesn't feel flat.
   Pure CSS, no images to ship. */
body {
  background:
    radial-gradient(60vw 60vw at 12% -10%, rgba(6,182,212,0.10), transparent 60%),
    radial-gradient(50vw 50vw at 110% 10%, rgba(168,85,247,0.07), transparent 65%),
    var(--bg);
  background-attachment: fixed;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  background: rgba(10, 14, 20, 0.78);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  text-decoration: none; color: var(--fg);
  font-weight: 600; letter-spacing: -0.01em;
}
.brand-glyph { width: 26px; height: 26px; color: var(--accent); }
.brand-name { font-size: 15px; }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.nav-link {
  text-decoration: none; color: var(--fg-mute);
  padding: 6px 12px; border-radius: 8px; font-size: 13px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface); color: var(--fg); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.topbar-spacer { flex: 1; }
.user-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.user-pill:hover { background: var(--accent-soft); border-color: var(--accent); }
.user-name { font-size: 13px; color: var(--fg); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; overflow: hidden;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 600; font-size: 11px; text-transform: uppercase;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- buttons ---------- */
.btn, .btn-primary, .btn-ghost, .btn-danger {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px; border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  text-decoration: none;
}
.btn:active, .btn-primary:active, .btn-ghost:active, .btn-danger:active {
  transform: translateY(1px);
}
.btn { background: var(--surface-2); color: var(--fg); border-color: var(--border-strong); }
.btn:hover { background: var(--surface); border-color: var(--accent-strong); }
.btn-primary { background: var(--accent); color: #04161b; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #1e2530; color: var(--fg-dim); cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--fg-mute); }
.btn-ghost:hover { background: var(--surface); color: var(--fg); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(248,113,113,0.3); }
.btn-danger:hover { background: rgba(248,113,113,0.22); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- inputs ---------- */
input, select, textarea {
  font: inherit; color: var(--fg);
  background: rgba(10, 14, 20, 0.6);
  border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 9px 12px;
  outline: none; transition: border-color .15s, background .15s;
  width: 100%;
}
input::placeholder { color: var(--fg-dim); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-strong);
  background: rgba(10, 14, 20, 0.85);
}

/* ---------- app container ---------- */
.app {
  max-width: 1100px; margin: 0 auto;
  padding: 32px 22px 64px;
  min-height: calc(100vh - 60px);
}

/* ---------- generic card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
}

/* ---------- auth (login/register) ---------- */
.auth-wrap {
  min-height: calc(100vh - 32px);
  display: grid; place-items: center; padding: 32px 16px;
}
.auth-card {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 16px;
}
.auth-brand {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-bottom: 4px;
}
.auth-brand .brand-glyph { width: 40px; height: 40px; color: var(--accent); }
.auth-brand h1 {
  margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
}
.auth-brand .tag { color: var(--fg-mute); font-size: 12px; }
.auth-tabs {
  display: flex; background: rgba(10, 14, 20, 0.6);
  border: 1px solid var(--border); border-radius: 8px; padding: 3px;
  gap: 3px;
}
.auth-tab {
  flex: 1; text-align: center; padding: 7px 10px; border-radius: 6px;
  background: transparent; border: none; cursor: pointer;
  color: var(--fg-mute); font: inherit; transition: background .15s, color .15s;
}
.auth-tab.active { background: var(--surface-2); color: var(--fg); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--fg-mute); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 500;
}
.auth-form .err {
  color: var(--danger); font-size: 13px; min-height: 18px;
  text-transform: none; letter-spacing: 0;
}
.auth-foot {
  text-align: center; color: var(--fg-dim); font-size: 12px; margin-top: 4px;
}

/* ---------- rooms list ---------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 18px; gap: 16px;
}
.section-head h1 {
  margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
}
.section-sub { color: var(--fg-mute); font-size: 13px; margin: 0; }

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.room-card {
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-decoration: none; color: inherit;
  transition: transform .12s, border-color .12s, background .15s;
}
.room-card:hover {
  border-color: var(--accent-strong);
  background: var(--surface-2);
  transform: translateY(-1px);
}
.room-card.singleton {
  background: linear-gradient(135deg, rgba(6,182,212,0.10), var(--surface));
  border-color: var(--accent-strong);
}
.room-card .top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.room-card .name {
  font-size: 16px; font-weight: 600; color: var(--fg);
}
.room-card .lock {
  color: var(--fg-mute); font-size: 13px;
}
.room-card .meta {
  display: flex; gap: 10px; color: var(--fg-mute); font-size: 12px;
}
.room-card .meta .dot { color: var(--fg-dim); }
.room-card .badges {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  color: var(--fg-mute); font-size: 11px;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.live { background: rgba(52,211,153,0.12); color: var(--ok); border-color: transparent; }

.empty {
  display: grid; place-items: center;
  padding: 72px 24px; text-align: center;
  color: var(--fg-mute);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.empty .emoji { font-size: 38px; opacity: 0.7; margin-bottom: 8px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(8px);
}
.modal {
  width: 100%; max-width: 460px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 4px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--fg-mute); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 500;
}
.modal-body .checkrow {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(10, 14, 20, 0.5);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; user-select: none;
}
.modal-body .checkrow input { width: auto; }
.modal-body .checkrow .what {
  display: flex; flex-direction: column; gap: 2px;
}
.modal-body .checkrow .what .label {
  color: var(--fg); font-size: 13px; font-weight: 500;
  text-transform: none; letter-spacing: 0;
}
.modal-body .checkrow .what .desc {
  color: var(--fg-mute); font-size: 12px;
  text-transform: none; letter-spacing: 0;
}
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px; border-top: 1px solid var(--border);
  background: rgba(10, 14, 20, 0.5);
}
.modal .err {
  color: var(--danger); font-size: 13px; min-height: 18px;
}

/* PIN field with placeholder-as-hint UX. The placeholder shows a randomly
   generated PIN at half opacity; clicking the field clears it so the user
   can type their own. Submitting empty uses the placeholder value. */
.pin-input {
  position: relative;
}
.pin-input input { font-family: ui-monospace, monospace; letter-spacing: 0.2em; }
.pin-input input.suggested { color: rgba(230, 234, 242, 0.45); }

/* ---------- room view (Phase 15 skeleton) ---------- */
.room-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.room-header h1 {
  margin: 0 0 4px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em;
}
.room-header .meta {
  color: var(--fg-mute); font-size: 13px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.room-header .actions { display: flex; gap: 8px; }

.room-grid-2col {
  display: grid; grid-template-columns: 1fr 280px; gap: 18px;
}
@media (max-width: 720px) {
  .room-grid-2col { grid-template-columns: 1fr; }
}
.devices-pane h3, .members-pane h3 {
  margin: 0 0 10px; font-size: 13px; color: var(--fg-mute);
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em;
}
.devices-pane .stub {
  padding: 36px 20px; text-align: center; color: var(--fg-mute);
}
.member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
}
.member-row:hover { background: var(--surface); }
.member-row .av {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 600; font-size: 12px; text-transform: uppercase;
}
.member-row .name { color: var(--fg); font-size: 13px; }
.member-row .host {
  margin-left: auto;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10px; padding: 1px 8px; border-radius: 999px;
  text-transform: uppercase; font-weight: 600; letter-spacing: 0.04em;
}
.member-row .av { text-decoration: none; overflow: hidden; }
.member-row .av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.member-row .name { text-decoration: none; }
.member-row .name:hover { text-decoration: underline; }
.member-row .kick {
  margin-left: auto;
  padding: 2px 8px; font-size: 12px; line-height: 1;
  border-radius: 6px; color: var(--fg-mute);
  background: transparent;
  border: 1px solid transparent;
}
.member-row .kick:hover {
  color: var(--danger, #e44); background: rgba(255, 80, 80, 0.08);
  border-color: rgba(255, 80, 80, 0.2);
}
.member-row .host + .kick { margin-left: 0; }
.btn-xs { padding: 2px 8px; font-size: 12px; }

/* ---------- room: devices gallery ---------- */
.devices-section { margin-top: 22px; }
.devices-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.devices-section h3 {
  margin: 0; font-size: 13px; color: var(--fg-mute);
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em;
}

/* When ANY tile is focused, lock the body so its scrollbar doesn't poke
   through the fullscreen overlay. Set by room.js's toggleFocus and cleared
   on view exit. */
body.fullscreen-active { overflow: hidden; }

/* Default grid: equal cells, auto-fill. */
.device-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

/* ---------- Fullscreen focus mode ----------
   When a tile gets `.focused`, the gallery sprouts a `.has-focus` class. The
   focused tile pops out of the document flow into a `position: fixed`
   overlay that fills the viewport. Other tiles are *cloned* (well, just
   styled — see below) and arranged as smaller thumbnails along the bottom
   edge. Double-click the big tile (or press Escape) to exit. */
.device-gallery.has-focus {
  /* The flow tiles stay in the grid below the overlay, but they're not
     visible because the overlay's solid backdrop covers everything. */
}

/* Fullscreen focus mode. The gallery becomes a fixed overlay; the focused
   tile fills the viewport; non-focused tiles overlay on the left edge in
   a vertically-centered group wrapped by a single blurred-glass strip
   (rendered as the gallery's ::before pseudo-element). Tiles keep their
   DOM identity across focus swaps — only CSS positions change, so WHEP /
   raw-video connections survive. */
.device-gallery.has-focus {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: block;             /* override grid */
  padding: 0;
  overflow: hidden;
}

/* The wrapping "strip" behind the thumbs. Vertically centered, sized to
   the thumb-count via JS-supplied --thumb-count. Hidden until chrome
   shows. */
.device-gallery.has-focus::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 212px;
  height: calc(var(--thumb-count, 0) * 145px + 6px);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  border: 1px solid var(--border);
  z-index: 120;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.device-gallery.has-focus.show-chrome::before { opacity: 1; }
/* No thumbs → no strip at all. */
.device-gallery.has-focus[style*="--thumb-count: 0"]::before { display: none; }

/* Focused tile fills the entire viewport — black bars whichever direction
   needed. object-fit: contain inside handles letterboxing. */
.device-tile.focused {
  position: absolute;
  inset: 0;
  z-index: 110;
  background: #000;
  border: none;
  border-radius: 0;
  display: block;
  cursor: default;
}

/* Non-focused tiles are positioned absolutely on the left edge, vertically
   centered as a GROUP via a math shift using --thumb-count and --thumb-i.
   Auto-fade with the show-chrome class on the gallery. */
.device-gallery.has-focus .device-tile:not(.focused) {
  position: absolute;
  left: 12px;
  width: 200px;
  height: 135px;
  top: calc(50% - (var(--thumb-count, 1) * 145px / 2) + (var(--thumb-i, 0) * 145px) + 5px);
  z-index: 130;
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  margin: 0;
  overflow: hidden;
  transition: border-color .12s, transform .12s, opacity .25s;
  opacity: 0;
  pointer-events: none;
}
.device-gallery.has-focus.show-chrome .device-tile:not(.focused),
.device-gallery.has-focus .device-tile:not(.focused):hover {
  opacity: 1;
  pointer-events: auto;
}
.device-gallery.has-focus .device-tile:not(.focused):hover {
  border-color: var(--accent-strong);
  transform: translateX(2px);
}
/* Thumb tiles: hide foot + Switch 2 pills (irrelevant on a thumb), but
   repurpose the head as a bottom-of-thumb caption with owner + game. */
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-foot,
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-slots {
  display: none;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 4px 8px;
  display: flex; align-items: center; gap: 6px;
  background: linear-gradient(to top, rgba(0,0,0,0.92), transparent);
  border: none; border-radius: 0;
  z-index: 5; pointer-events: none;
  font-size: 11px;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .av-sm {
  display: none;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .device-tile-title {
  flex-direction: row; gap: 5px; align-items: baseline;
  min-width: 0; overflow: hidden;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .device-tile-title .name {
  color: #fff; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .device-tile-title .sub {
  color: rgba(255,255,255,0.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .device-tile-title .sub::before {
  content: '· ';
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .btn-ghost,
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .btn-danger,
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-head .tile-binding-pick {
  display: none;
}
.device-gallery.has-focus .device-tile:not(.focused) .device-tile-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  aspect-ratio: auto;
}
.device-tile.focused .device-tile-video {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  /* Override every aspect-ratio source — default 3:2 on .device-tile-video
     AND the 16:9 override on .device-tile-16x9 — so the focused tile's
     video container always fills the viewport. The video element inside
     uses object-fit: contain to letterbox if its intrinsic ratio differs. */
  aspect-ratio: auto !important;
  background: #000;
  display: block;
}
.device-tile.focused .device-tile-video video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;          /* letterbox on whichever axis the screen is wider */
  image-rendering: pixelated;
  background: #000;
}
/* Head floats top-left on the focused tile (owner + game info). Auto-hides
   with the gallery's show-chrome class (set by the room-view mousemove
   handler, also drives the exit hint + thumb-strip visibility). */
.device-tile.focused .device-tile-head {
  position: absolute;
  left: 20px; top: 20px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  border: 1px solid var(--border);
  z-index: 140;
  padding: 6px 12px;
  opacity: 0;
  transition: opacity .2s;
}
.device-gallery.has-focus.show-chrome .device-tile.focused .device-tile-head { opacity: 1; }

.device-tile.focused .device-tile-foot {
  position: absolute; left: 50%; bottom: 20px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border);
  z-index: 140; font-size: 12px;
  opacity: 0; transition: opacity .2s;
}
.device-gallery.has-focus.show-chrome .device-tile.focused .device-tile-foot { opacity: 1; }

/* Slot pills floating bottom-center on any focused multi-controller tile
   (Switch 2 lounge, Wii, GameCube). Same auto-hide as head/foot. */
.device-tile.focused .device-tile-slots {
  position: absolute; left: 50%; bottom: 60px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  padding: 6px 8px; border-radius: 999px;
  border: 1px solid var(--border);
  z-index: 140;
  width: auto; max-width: 90vw;
  opacity: 0; transition: opacity .2s;
}
.device-gallery.has-focus.show-chrome .device-tile.focused .device-tile-slots { opacity: 1; }

/* (thumb-strip CSS removed — Phase 17.6 merged thumbs into the same DOM as
   the main tiles. CSS rearranges them via --thumb-i; no separate WHEP per
   thumb means no flicker when swapping focus.) */

/* Exit hint, top-right of the overlay. */
.focus-exit-hint {
  position: fixed; top: 20px; right: 22px; z-index: 202;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  padding: 6px 12px; border-radius: 999px;
  font-size: 12px; color: var(--fg);
  border: 1px solid var(--border);
  cursor: pointer;
  pointer-events: none; /* swapped to auto only when .show is on */
  opacity: 0;
  transition: opacity .2s, background .15s;
  user-select: none;
}
.focus-exit-hint.show { opacity: 1; pointer-events: auto; }
.focus-exit-hint:hover { background: rgba(0,0,0,0.78); }

.device-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  display: flex; flex-direction: column;
}
.device-tile:hover { border-color: var(--accent-strong); }
.device-tile.focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-strong), 0 8px 24px rgba(6, 182, 212, 0.18);
}
.device-tile.focused.mine {
  /* The "I am driving this" state — slightly stronger highlight. */
  box-shadow: 0 0 0 2px var(--accent), 0 12px 36px rgba(6, 182, 212, 0.30);
}

.device-tile-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; gap: 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.device-tile-owner { display: flex; align-items: center; gap: 8px; min-width: 0; }
.device-tile-title { display: flex; flex-direction: column; min-width: 0; }
.device-tile-title .name { font-size: 13px; font-weight: 500; color: var(--fg); }
.device-tile-title .sub  { font-size: 11px; color: var(--fg-mute); }
.av-sm {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 600; font-size: 10px; text-transform: uppercase;
  flex: none;
}

.device-tile-video {
  position: relative;
  aspect-ratio: 3 / 2;        /* 240×160 = 3:2 — perfect fit for GBA */
  background: #000;
  /* When the host is in landscape, video tiles want to expand to fill. */
}
/* 16:9 only applies in the GRID (unfocused) view. The focused tile fills
   the viewport and uses aspect-ratio: auto — without :not(.focused) the
   16:9 rule overrides it and the focused video gets boxed in the top-left
   of the screen instead of filling. */
.device-tile-16x9:not(.focused) .device-tile-video {
  aspect-ratio: 16 / 9;       /* Wii / GameCube widescreen output */
}
.device-tile-foot {
  padding: 6px 12px;
  font-size: 11px; color: var(--fg-mute);
  background: rgba(0, 0, 0, 0.25);
  border-top: 1px solid var(--border);
  text-align: center;
}
.device-tile-foot.focused-hint {
  background: var(--accent-soft); color: var(--accent);
}

/* ---------- Multi-controller slot pills (Switch 2, Wii, GameCube) ---------- */
.device-tile-slots {
  display: flex; gap: 6px; padding: 8px 10px;
  background: rgba(0, 0, 0, 0.32);
  border-top: 1px solid var(--border);
}
.slot-pill {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 4px 8px; font-size: 11px; font-weight: 500;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--fg-mute);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.slot-pill .slot-num { opacity: 0.6; font-family: ui-monospace, monospace; }
.slot-pill .slot-name { font-weight: 600; }
.slot-pill:hover {
  border-color: var(--accent-strong);
  background: var(--surface);
}
.slot-pill.mine {
  /* You hold this slot — strong cyan. */
  background: var(--accent); color: #04161b;
  border-color: var(--accent);
}
.slot-pill.mine .slot-num { color: #04161b; opacity: 0.7; }
.slot-pill.mine:hover { background: var(--accent-hover); }
.slot-pill.taken {
  /* Someone else holds it — non-clickable visually. */
  background: rgba(120, 145, 180, 0.10);
  color: var(--fg-mute);
  cursor: default;
}
.slot-pill.taken:hover {
  border-color: var(--border-strong);
  background: rgba(120, 145, 180, 0.10);
}
.slot-pill.free { color: var(--fg-mute); }

/* ---------- Input RTT pill in tile head ---------- */
.tile-rtt-pill {
  font-size: 10px; font-family: ui-monospace, monospace;
  padding: 2px 6px; border-radius: 4px;
  background: var(--surface-2); color: var(--fg-mute);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.tile-rtt-pill[data-tier="good"] { color: #4ade80; border-color: rgba(74, 222, 128, 0.4); }
.tile-rtt-pill[data-tier="ok"]   { color: #facc15; border-color: rgba(250, 204, 21, 0.4); }
.tile-rtt-pill[data-tier="warn"] { color: #fb923c; border-color: rgba(251, 146, 60, 0.4); }
.tile-rtt-pill[data-tier="bad"]  { color: #f87171; border-color: rgba(248, 113, 113, 0.5); }

/* ---------- switch lounge launch card (legacy launcher, kept hidden) ---------- */
.switch-launch {
  display: block; padding: 28px;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
  border: 1px solid var(--accent-strong);
  border-radius: var(--radius-lg); text-decoration: none; color: var(--fg);
  transition: transform .12s, box-shadow .15s;
}
.switch-launch:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(6, 182, 212, 0.15);
}
.switch-launch .label {
  display: block; color: var(--accent); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px;
}
.switch-launch .title {
  font-size: 18px; font-weight: 600; margin-bottom: 4px;
}
.switch-launch .desc { color: var(--fg-mute); font-size: 13px; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; left: 16px; bottom: 16px; z-index: 200;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  color: var(--fg);
  padding: 10px 14px; border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-soft);
  max-width: 360px;
  animation: toastIn .2s ease-out, toastOut .35s ease-in 4s forwards;
}
.toast.error  { border-left-color: var(--danger); }
.toast.ok     { border-left-color: var(--ok); }
.toast.warn   { border-left-color: var(--warn); }
@keyframes toastIn  { from {opacity:0; transform: translateX(-12px);} to {opacity:1; transform: translateX(0);} }
@keyframes toastOut { from {opacity:1; transform: translateX(0);} to {opacity:0; transform: translateX(-12px);} }

/* ---------- spinner ---------- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-page {
  display: grid; place-items: center; padding: 72px 24px; color: var(--fg-mute);
}

/* ---------- bindings view ---------- */
.bindings-view .bindings-cols {
  display: grid; grid-template-columns: 280px 1fr; gap: 16px; margin-top: 14px;
}
.binding-list { padding: 0; overflow: hidden; }
.binding-list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.binding-list-head h3 { margin: 0; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--fg-mute); }
.binding-rows { display: flex; flex-direction: column; }
.binding-row {
  padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.binding-row:hover { background: var(--surface-2); }
.binding-row.active { background: rgba(6,182,212,0.10); border-left: 3px solid var(--accent); padding-left: 13px; }
.binding-row-name { font-weight: 500; }
.binding-row-meta { color: var(--fg-mute); font-size: 12px; margin-top: 2px;
  display: flex; gap: 8px; align-items: center; }
.tag-muted, .tag-warn {
  display: inline-block; padding: 1px 6px; font-size: 11px; border-radius: 4px;
  border: 1px solid var(--border-strong);
}
.tag-muted { color: var(--fg-mute); }
.tag-warn  { color: var(--warn); border-color: var(--warn); }
.binding-editor { padding: 14px 16px; min-height: 540px; }
.binding-editor-head {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  margin-bottom: 10px;
}
.binding-editor-fields {
  display: grid; grid-template-columns: repeat(3, auto); gap: 10px 16px;
  flex: 1;
}
.binding-field {
  display: flex; flex-direction: column; gap: 4px; font-size: 12px;
  color: var(--fg-mute); text-transform: uppercase; letter-spacing: 0.05em;
}
.binding-field .input { font-size: 13px; padding: 6px 8px; }
.binding-field input[type="checkbox"] { width: 16px; height: 16px; }
.binding-editor-actions {
  display: flex; gap: 8px; align-items: center;
}
.binding-editor-code-wrap { display: flex; flex-direction: column; gap: 10px; }
.binding-code { background: #0f1419; color: #d6e0ea; }
.binding-api-ref { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.binding-api-ref summary {
  cursor: pointer; padding: 8px 12px; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-mute);
}
.binding-api-ref pre {
  margin: 0; padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 12px; line-height: 1.5; overflow: auto;
}
.template-pick {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 8px; cursor: pointer; display: flex; justify-content: space-between;
}
.template-pick:hover { background: var(--surface-2); border-color: var(--accent); }
.template-pick-name { font-weight: 500; }
.template-pick-kind { color: var(--fg-mute); font-size: 12px; }

/* ---------- stickers view ---------- */
.sticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px; margin-top: 14px;
}
.sticker-card {
  display: block; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  text-decoration: none; color: var(--fg);
  transition: border-color .12s, transform .12s;
}
.sticker-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.sticker-card-title { font-weight: 500; font-size: 15px; margin-bottom: 4px; }
.sticker-card-meta { color: var(--fg-mute); font-size: 12px; margin-bottom: 10px; }
.sticker-card-bar { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.sticker-card-bar-fill { height: 100%; background: var(--accent); transition: width .25s; }

.sticker-row {
  display: grid; grid-template-columns: 48px 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.sticker-row:last-child { border-bottom: none; }
.sticker-row.earned { background: rgba(34, 197, 94, 0.05); }
.sticker-row:not(.earned) .sticker-badge { opacity: 0.35; filter: grayscale(0.7); }
.sticker-badge {
  width: 48px; height: 48px; border-radius: 6px; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden;
}
.sticker-badge img { width: 100%; height: 100%; image-rendering: pixelated; }
.sticker-title { font-weight: 500; }
.sticker-desc  { color: var(--fg-mute); font-size: 12px; margin-top: 2px; }
.sticker-pts   { color: var(--fg-mute); font-size: 12px; }
.sticker-earned { color: var(--ok); font-size: 18px; font-weight: 700; }

/* ---------- per-tile binding picker (in the device-tile head) ---------- */
.tile-binding-pick {
  font-size: 11px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; color: var(--fg);
  max-width: 160px;
}
.tile-binding-pick:focus { outline: 1px solid var(--accent); }
.tile-binding-error {
  position: absolute; bottom: 8px; right: 8px; max-width: 60%;
  background: rgba(220,38,38,0.85); color: #fff; font-size: 11px;
  padding: 4px 8px; border-radius: 4px; font-family: ui-monospace, monospace;
  pointer-events: none;
}

/* ---------- profile / users / me (Phase B) ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 14px; }
.page-head h1 { margin: 0; font-size: 22px; }

.profile-view { max-width: 920px; margin: 24px auto; padding: 0 22px; }
.profile-head {
  display: flex; gap: 24px; align-items: center;
  padding: 22px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface);
}
.profile-avatar {
  width: 120px; height: 120px; border-radius: 50%; overflow: hidden;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 38px; font-weight: 700; text-transform: uppercase;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-meta h1 { margin: 0; font-size: 26px; }
.profile-meta .handle { color: var(--fg-mute); font-size: 13px; margin-top: 2px; }
.profile-meta .bio { color: var(--fg); margin: 10px 0 6px; white-space: pre-wrap; }
.profile-meta .profile-stats {
  color: var(--fg-mute); font-size: 13px; margin-top: 8px;
  display: flex; gap: 6px; flex-wrap: wrap;
}
.profile-meta .profile-stats .sep { opacity: 0.4; }
.profile-meta .profile-actions { margin-top: 12px; }
.profile-stickers { margin-top: 28px; }
.profile-stickers h2 {
  font-size: 13px; color: var(--fg-mute); text-transform: uppercase;
  letter-spacing: 0.06em; margin: 0 0 12px;
}
.sticker-game-list { display: flex; flex-direction: column; gap: 22px; }
.sticker-game-block h3 {
  font-size: 14px; margin: 0 0 10px;
}
.sticker-game-block h3 a { color: var(--fg); text-decoration: none; }
.sticker-game-block h3 a:hover { text-decoration: underline; }
.sticker-game-block h3 .count { color: var(--fg-mute); font-weight: 400; font-size: 12px; }
.sticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.sticker-card {
  text-align: center; padding: 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  transition: transform .15s, border-color .15s;
}
.sticker-card:hover { transform: translateY(-1px); border-color: var(--accent); }
.sticker-badge {
  width: 64px; height: 64px; border-radius: 12px; margin: 0 auto;
  display: block; object-fit: cover;
}
.sticker-badge.stub {
  display: grid; place-items: center; background: var(--accent-soft);
  color: var(--accent); font-size: 28px;
}
.sticker-title { font-size: 12px; margin-top: 8px; color: var(--fg); line-height: 1.2; }
.sticker-points { font-size: 10px; color: var(--fg-mute); margin-top: 2px; }

.users-view { max-width: 920px; margin: 24px auto; padding: 0 22px; }
.user-search {
  width: 100%; max-width: 420px; margin-bottom: 18px;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--fg); font-size: 14px;
}
.user-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.user-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); text-decoration: none; color: inherit;
  transition: border-color .15s, transform .15s;
}
.user-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.user-card .user-avatar { width: 40px; height: 40px; font-size: 14px; }
.user-card .user-meta .name { font-weight: 500; color: var(--fg); }
.user-card .user-meta .handle { font-size: 12px; color: var(--fg-mute); }

.me-view { max-width: 720px; margin: 24px auto; padding: 0 22px; }
.profile-edit {
  display: flex; flex-direction: column; gap: 18px;
  padding: 22px;
}
.profile-edit-grid { display: flex; gap: 22px; align-items: center; }
.profile-edit .avatar-actions { display: flex; gap: 8px; align-items: center; }
.profile-edit .hint { color: var(--fg-mute); font-size: 12px; margin-top: 4px; }
.profile-edit label { display: block; font-size: 13px; color: var(--fg-mute); }
.profile-edit input[type=text], .profile-edit textarea {
  width: 100%; margin-top: 6px;
  padding: 9px 12px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border); color: var(--fg);
  font: inherit; font-size: 14px; resize: vertical;
}
.profile-edit textarea { font-family: inherit; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- sticker unlock banners (Minecraft-style, top-right) ---------- */
.sticker-banners {
  position: fixed; top: 70px; right: 22px; z-index: 999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.sticker-banner {
  display: flex; align-items: center; gap: 12px;
  min-width: 280px; max-width: 380px;
  padding: 12px 16px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(24, 32, 44, 0.96), rgba(36, 28, 12, 0.96));
  border: 1px solid #d4af37;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5),
              0 0 0 1px rgba(212, 175, 55, 0.25) inset;
  color: #fff;
  transform: translateX(420px); opacity: 0;
  transition: transform 380ms cubic-bezier(.16,.84,.44,1), opacity 300ms;
  pointer-events: auto;
}
.sticker-banner.show { transform: translateX(0); opacity: 1; }
.sticker-banner.dismissing { transform: translateX(420px); opacity: 0; }
.sticker-banner .badge {
  width: 48px; height: 48px; border-radius: 10px; flex-shrink: 0;
  background: rgba(212, 175, 55, 0.15);
  display: grid; place-items: center;
  font-size: 22px;
  color: #d4af37;
}
.sticker-banner .badge img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.sticker-banner .text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sticker-banner .kicker {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #d4af37;
}
.sticker-banner .title {
  font-size: 14px; font-weight: 600; line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis;
}
.sticker-banner .points { font-size: 11px; color: rgba(255,255,255,0.65); margin-top: 2px; }

/* (older duplicate .slot-pill block was here — unified into the
   "Multi-controller slot pills" block above to keep one canonical
   visual + interaction model for every device kind with slots.) */

