/* ===================== Reset & base ===================== */
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--page-bg);
  color: var(--text);
  overflow: hidden;
  transition: background 0.5s ease, color 0.4s ease;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===================== Skin tokens ===================== */

/* 6c — Cinematic OLED Amber (default) */
body,
body[data-skin="amber"],
.skin-swatch[data-preview="amber"] {
  --page-bg: #000000;
  --text: #ffffff;
  --text-2: rgba(255,255,255,0.55);
  --text-3: rgba(255,255,255,0.4);
  --text-4: rgba(255,255,255,0.3);
  --divider: rgba(255,255,255,0.08);
  --header-bg: transparent;
  --header-blur: none;
  --btn-idle-bg: rgba(255,255,255,0.06);
  --btn-idle-border: rgba(255,255,255,0.15);
  --icon-fill: #ffffff;
  --accent: #FF9F0A;
  --accent-fill: rgba(255,159,10,0.16);
  --accent-fill-soft: rgba(255,159,10,0.14);
  --tile-border: rgba(255,255,255,0.1);
  --tile-hatch-a: rgba(255,159,10,0.05);
  --tile-hatch-b: rgba(255,255,255,0.012);
  --tile-label: rgba(255,255,255,0.4);
  --sidebar-bg: rgba(255,255,255,0.035);
  --sidebar-border: rgba(255,255,255,0.09);
  --sidebar-shadow: 0 20px 50px rgba(0,0,0,0.3);
  --sidebar-blur: none;
  --chip-bg: rgba(255,255,255,0.05);
  --chip-border: rgba(255,255,255,0.09);
  --chip-icon: rgba(255,255,255,0.3);
  --chip-radius: 14px;
  --chip-swatch-display: flex;
  --diagram-inactive: rgba(255,255,255,0.4);
  --diagram-inactive-text: rgba(255,255,255,0.6);
  --sheet-bg: rgba(20,16,10,0.97);
  --sheet-border: rgba(255,255,255,0.1);
  --fab-bg: #FF9F0A;
  --fab-shadow: rgba(255,159,10,0.4);
  --fab-icon: #000000;
  --logo-b: #ffffff;
  --aurora-opacity: 0;
}

/* 6b — Midnight Blue */
body[data-skin="midnight"],
.skin-swatch[data-preview="midnight"] {
  --page-bg: linear-gradient(165deg,#0b1220,#04070d);
  --text: #ffffff;
  --text-2: rgba(255,255,255,0.65);
  --text-3: rgba(255,255,255,0.42);
  --text-4: rgba(255,255,255,0.35);
  --divider: rgba(255,255,255,0.08);
  --header-bg: transparent;
  --header-blur: none;
  --btn-idle-bg: rgba(255,255,255,0.06);
  --btn-idle-border: rgba(255,255,255,0.15);
  --icon-fill: #ffffff;
  --accent: #5AC8FA;
  --accent-fill: rgba(90,200,250,0.16);
  --accent-fill-soft: rgba(90,200,250,0.14);
  --tile-border: rgba(255,255,255,0.1);
  --tile-hatch-a: rgba(90,200,250,0.05);
  --tile-hatch-b: rgba(255,255,255,0.012);
  --tile-label: rgba(255,255,255,0.42);
  --sidebar-bg: rgba(255,255,255,0.045);
  --sidebar-border: rgba(255,255,255,0.1);
  --sidebar-shadow: 0 20px 50px rgba(0,0,0,0.4);
  --sidebar-blur: none;
  --chip-bg: rgba(255,255,255,0.05);
  --chip-border: rgba(255,255,255,0.09);
  --chip-icon: rgba(255,255,255,0.3);
  --chip-radius: 14px;
  --chip-swatch-display: flex;
  --diagram-inactive: rgba(255,255,255,0.4);
  --diagram-inactive-text: rgba(255,255,255,0.6);
  --sheet-bg: rgba(8,13,22,0.97);
  --sheet-border: rgba(255,255,255,0.1);
  --fab-bg: #5AC8FA;
  --fab-shadow: rgba(90,200,250,0.4);
  --fab-icon: #04070d;
  --logo-b: #ffffff;
  --aurora-opacity: 0;
}

/* 6d — Aurora / visionOS */
body[data-skin="aurora"],
.skin-swatch[data-preview="aurora"] {
  --page-bg: #0a0710;
  --text: #ffffff;
  --text-2: rgba(255,255,255,0.7);
  --text-3: rgba(255,255,255,0.5);
  --text-4: rgba(255,255,255,0.45);
  --divider: rgba(255,255,255,0.1);
  --header-bg: rgba(10,7,16,0.4);
  --header-blur: blur(20px);
  --btn-idle-bg: rgba(255,255,255,0.08);
  --btn-idle-border: rgba(255,255,255,0.16);
  --icon-fill: #ffffff;
  --accent: #BF5AF2;
  --accent-fill: rgba(191,90,242,0.18);
  --accent-fill-soft: rgba(191,90,242,0.16);
  --tile-border: rgba(255,255,255,0.18);
  --tile-hatch-a: rgba(255,255,255,0.07);
  --tile-hatch-b: rgba(255,255,255,0.025);
  --tile-label: rgba(255,255,255,0.5);
  --sidebar-bg: rgba(255,255,255,0.07);
  --sidebar-border: rgba(255,255,255,0.12);
  --sidebar-shadow: 0 20px 50px rgba(0,0,0,0.4);
  --sidebar-blur: blur(24px);
  --chip-bg: rgba(255,255,255,0.07);
  --chip-border: rgba(255,255,255,0.12);
  --chip-icon: rgba(255,255,255,0.35);
  --chip-radius: 14px;
  --chip-swatch-display: flex;
  --diagram-inactive: rgba(255,255,255,0.45);
  --diagram-inactive-text: rgba(255,255,255,0.7);
  --sheet-bg: rgba(15,10,20,0.85);
  --sheet-border: rgba(255,255,255,0.14);
  --fab-bg: #BF5AF2;
  --fab-shadow: rgba(191,90,242,0.45);
  --fab-icon: #0a0710;
  --logo-b: #ffffff;
  --aurora-opacity: 0.6;
}

/* 6e — Monochrome Slate */
body[data-skin="slate"],
.skin-swatch[data-preview="slate"] {
  --page-bg: #111113;
  --text: #ffffff;
  --text-2: rgba(255,255,255,0.65);
  --text-3: rgba(255,255,255,0.45);
  --text-4: rgba(255,255,255,0.35);
  --divider: rgba(255,255,255,0.14);
  --header-bg: transparent;
  --header-blur: none;
  --btn-idle-bg: rgba(255,255,255,0.06);
  --btn-idle-border: rgba(255,255,255,0.18);
  --icon-fill: #ffffff;
  --accent: #ffffff;
  --accent-fill: rgba(255,255,255,0.14);
  --accent-fill-soft: rgba(255,255,255,0.12);
  --tile-border: rgba(255,255,255,0.18);
  --tile-hatch-a: rgba(255,255,255,0.03);
  --tile-hatch-b: transparent;
  --tile-label: rgba(255,255,255,0.45);
  --sidebar-bg: rgba(255,255,255,0.03);
  --sidebar-border: rgba(255,255,255,0.1);
  --sidebar-shadow: 0 20px 50px rgba(0,0,0,0.4);
  --sidebar-blur: none;
  --chip-bg: transparent;
  --chip-border: rgba(255,255,255,0.14);
  --chip-icon: rgba(255,255,255,0.35);
  --chip-radius: 0px;
  --chip-swatch-display: none;
  --diagram-inactive: rgba(255,255,255,0.4);
  --diagram-inactive-text: rgba(255,255,255,0.65);
  --sheet-bg: rgba(17,17,19,0.97);
  --sheet-border: rgba(255,255,255,0.14);
  --fab-bg: #ffffff;
  --fab-shadow: rgba(255,255,255,0.25);
  --fab-icon: #111113;
  --logo-b: #ffffff;
  --aurora-opacity: 0;
}

/* Fixed channel identity colors — constant across all skins */
:root {
  --ch-blue: #0A84FF;
  --ch-purple: #BF5AF2;
  --ch-green: #30D158;
  --ch-amber: #FF9F0A;
  --drop-border: #0A84FF;
  --drop-fill: rgba(10,132,255,0.1);
  --video-card-radius: max(2px, 0.3125vw);
}

/* ===================== Aurora glow layer ===================== */
.aurora-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 15%, rgba(94,92,230,0.45), transparent 45%),
    radial-gradient(circle at 90% 5%, rgba(191,90,242,0.4), transparent 42%),
    radial-gradient(circle at 55% 90%, rgba(10,132,255,0.3), transparent 45%);
  filter: blur(60px);
  opacity: var(--aurora-opacity, 0);
  transition: opacity 0.6s ease;
}

/* ===================== App shell ===================== */
.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.mobile-only { display: none; }

/* ===================== Header ===================== */
.header {
  flex: none;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--divider);
  background: var(--header-bg);
  -webkit-backdrop-filter: var(--header-blur);
  backdrop-filter: var(--header-blur);
  transition: background 0.4s ease, border-color 0.4s ease, opacity 0.4s ease;
}

.logo { display: flex; align-items: center; gap: 16px; }
.logo-svg { width: 56px; height: auto; display: block; flex: none; }
.logo-a { fill: #009fe3; }
.logo-c { fill: #d4103a; }
.logo-b { fill: var(--logo-b); transition: fill 0.4s ease; }

.logo-divider {
  width: 1px;
  height: 24px;
  flex: none;
  background: var(--divider);
  transition: background 0.4s ease;
}

/* Broadcast-style nameplate: tracked caps, "VIEW" takes the skin accent. */
.wordmark {
  font: 600 15px/1 -apple-system, "SF Pro Text", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.32em;
  margin-right: -0.32em; /* cancel trailing tracking so optical centering holds */
  color: var(--text);
  white-space: nowrap;
  transition: color 0.4s ease;
}
.wordmark-accent {
  color: var(--accent);
  font-weight: 400;
  transition: color 0.4s ease;
}

.header-controls { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--btn-idle-bg);
  border: 1px solid var(--btn-idle-border);
  transition: background 0.25s cubic-bezier(.4,0,.2,1), border-color 0.25s cubic-bezier(.4,0,.2,1), transform 0.2s cubic-bezier(.4,0,.2,1);
}
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { transform: scale(1.06); } }
.icon-btn:active { transform: scale(0.96); }
.icon-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; width: 15px; height: 15px; }
.icon-grid i { background: var(--icon-fill); border-radius: 1px; display: block; }

.icon-bars { display: flex; flex-direction: column; gap: 2px; width: 16px; height: 14px; justify-content: center; }
.icon-bars i { background: var(--icon-fill); border-radius: 1px; display: block; }
.icon-bars i:nth-child(1) { flex: 2; }
.icon-bars i:nth-child(2) { flex: 1; opacity: 0.6; }
.fullscreen-icon {
  width: 16px;
  height: 16px;
  display: block;
  fill: none;
  stroke: var(--icon-fill);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.fullscreen-icon--exit,
.icon-btn[aria-pressed="true"] .fullscreen-icon--enter { display: none; }
.icon-btn[aria-pressed="true"] .fullscreen-icon--exit { display: block; }
.icon-btn .mute-icon {
  width: 19px;
  height: 19px;
}

.layout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.layout-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 6px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1.5px solid transparent;
  transition: background 0.2s cubic-bezier(.4,0,.2,1), border-color 0.2s cubic-bezier(.4,0,.2,1), transform 0.15s cubic-bezier(.4,0,.2,1);
}
@media (hover: hover) and (pointer: fine) { .layout-option:hover { transform: translateY(-1px); } }
.layout-option[data-selected="true"] {
  background: var(--accent-fill-soft);
  border-color: var(--accent);
}
.layout-option .diagram { pointer-events: none; }
.layout-option .bar {
  background: var(--diagram-inactive);
  border-radius: 2px;
  transition: background 0.2s ease;
}
.layout-option[data-selected="true"] .bar { background: var(--accent); }
.layout-option .opt-label {
  font: 500 10.5px/1 -apple-system, sans-serif;
  color: var(--diagram-inactive-text);
  pointer-events: none;
}
.layout-option[data-selected="true"] .opt-label { color: var(--text); }

.diagram { display: flex; width: 32px; height: 20px; gap: 3px; }
.diagram.col { flex-direction: column; }
.diagram .sub { display: flex; gap: 3px; flex: 1; }
.diagram .sub.col { flex-direction: column; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 3px; width: 32px; height: 20px; }

/* Skin picker (sidebar / sheet) — dropdown, opens upward since it sits
   at the very bottom of its panel */
.skin-dropdown { position: relative; }

.skin-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  text-align: left;
  transition: background 0.2s ease, border-color 0.2s ease;
}
body[data-skin="slate"] .skin-trigger { border-radius: 0; border: none; border-bottom: 1px solid var(--chip-border); }
@media (hover: hover) and (pointer: fine) { .skin-trigger:hover { background: var(--accent-fill-soft); } }
.skin-dropdown[data-open="true"] .skin-trigger {
  background: var(--accent-fill-soft);
  border-color: var(--accent);
}

.skin-trigger-label { font: 600 13px/1.2 -apple-system, sans-serif; color: var(--text); flex: 1; }
.skin-chevron {
  width: 8px;
  height: 8px;
  flex: none;
  border-right: 1.5px solid var(--text-3);
  border-bottom: 1.5px solid var(--text-3);
  transform: rotate(45deg);
  margin-top: -4px;
  transition: transform 0.25s cubic-bezier(.4,0,.2,1), margin-top 0.25s cubic-bezier(.4,0,.2,1);
}
.skin-dropdown[data-open="true"] .skin-chevron { transform: rotate(-135deg); margin-top: 2px; }

.skin-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border-radius: 14px;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transform-origin: bottom;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(.34,1.56,.64,1);
  z-index: 30;
}
.skin-menu.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.skin-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
  width: 100%;
  text-align: left;
}
@media (hover: hover) and (pointer: fine) { .skin-option:hover { background: rgba(128,128,128,0.1); } }
.skin-option[data-selected="true"] {
  background: var(--accent-fill-soft);
  border-color: var(--accent);
}
/* Swatch = the skin's ground with one accent dot. data-preview pulls in that
   skin's tokens (see the skin blocks above), so it follows any token change. */
.skin-swatch {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex: none;
  overflow: hidden;
  background: var(--page-bg);
}
.skin-swatch::before { /* Aurora's glow, at swatch scale; opacity 0 on other skins */
  content: "";
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(circle at 15% 20%, rgba(94,92,230,0.9), transparent 45%),
    radial-gradient(circle at 90% 10%, rgba(191,90,242,0.85), transparent 45%),
    radial-gradient(circle at 55% 95%, rgba(10,132,255,0.7), transparent 45%);
  filter: blur(4px);
  opacity: var(--aurora-opacity);
}
.skin-swatch::after { /* hairline edge that reads on any ground */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(128,128,128,0.28);
}
.skin-swatch-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
}
.skin-trigger .skin-swatch { width: 24px; height: 24px; border-radius: 7px; }
.skin-trigger .skin-swatch-dot { width: 10px; height: 10px; }
.skin-name { font: 600 13px/1.2 -apple-system, sans-serif; color: var(--text); }
.skin-desc { font: 400 11px/1.3 -apple-system, sans-serif; color: var(--text-3); }

/* ===================== Body / tile area ===================== */
.body {
  position: relative;
  flex: 1;
  padding: 28px 32px;
  min-height: 0;
  overflow: hidden;
}

.tile-area {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(calc(100% - 64px), calc((100dvh - 128px) * 16 / 9));
  aspect-ratio: 16 / 9;
  min-height: 0;
  transform: translate(-50%, -50%);
}

/* ===================== Full screen ===================== */
body.is-fullscreen .header {
  position: fixed;
  inset: 0 0 auto 0;
  height: 52px;
  padding: 8px 16px 6px;
  z-index: 11;
  border-bottom: none;
  background:
    linear-gradient(rgba(0,0,0,0.55), rgba(0,0,0,0.22) 58%, transparent);
}
body.is-fullscreen .body {
  padding: 0;
}
body.is-fullscreen .tile-area {
  width: min(100%, calc(100dvh * 16 / 9));
}
body.is-fullscreen:not(.is-idle) .tile-area {
  width: min(100%, calc((100dvh - 52px) * 16 / 9));
  transform: translate(-50%, calc(-50% + 26px));
}

/* Single composited multiview stream — fills the whole tile area behind
   the overlay tiles. Its internal quadrant layout is fixed server-side,
   which is why the tile rects above are exact MKIO geometry rather than
   arbitrary percentages: they must land on the same regions the stream
   already renders. */
.video-layer {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  overflow: hidden;
  background: transparent;
  z-index: 0;
  transition: background 0.3s ease;
}
.video-layer.is-active { background: #000; }
.video-layer video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile {
  position: absolute;
  z-index: 1;
  border-radius: var(--video-card-radius);
  overflow: hidden;
  clip-path: inset(0 round var(--video-card-radius));
  border: 1px solid var(--tile-border);
  background-image: repeating-linear-gradient(135deg, var(--tile-hatch-a) 0px, var(--tile-hatch-a) 10px, var(--tile-hatch-b) 10px, var(--tile-hatch-b) 20px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none; /* double-click enlarges; don't select label text */
  transition:
    left 0.42s cubic-bezier(.4,0,.2,1),
    top 0.42s cubic-bezier(.4,0,.2,1),
    width 0.42s cubic-bezier(.4,0,.2,1),
    height 0.42s cubic-bezier(.4,0,.2,1),
    opacity 0.3s ease,
    transform 0.3s cubic-bezier(.4,0,.2,1),
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.2s ease,
    background-image 0.3s ease;
}
.tile.is-hidden { opacity: 0; transform: scale(0.85); pointer-events: none; }
/* Channel set: solid accent frame (inset shadow thickens it without
   shifting layout). Blue stays reserved for the drag-over state below. */
.tile.is-assigned {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 0.5px var(--accent);
}
/* Dashed = "drop here": distinct from the solid assigned frame. */
.tile.is-dragover {
  border: 1.5px dashed var(--drop-border);
  box-shadow: none;
  background-color: var(--drop-fill);
  transform: scale(1.015);
}
/* Real video is playing behind this tile — drop the placeholder hatch so
   it shows through, and shrink the label to a corner badge. */
.tile.is-live {
  background-image: none;
  align-items: flex-start;
  justify-content: flex-start;
}
.tile.is-live .tile-label {
  color: #fff;
  margin: 10px 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.tile.is-armable { cursor: pointer; }
.tile-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 11px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.08em;
  color: var(--tile-label);
  pointer-events: none;
  text-transform: uppercase;
}
.tile.is-assigned .tile-label { color: var(--text); }
.tile-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  display: var(--chip-swatch-display); /* hidden on Slate, which drops channel color */
}
.audio-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.42);
  color: #fff;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font: 700 11px/1 -apple-system, "SF Pro Text", sans-serif;
  letter-spacing: 0;
  opacity: 0.78;
  transition: opacity 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}
.audio-btn[hidden] { display: none; }
.audio-btn:focus-visible {
  opacity: 1;
  border-color: var(--accent);
  transform: translateY(-1px);
}
@media (hover: hover) and (pointer: fine) {
  .audio-btn:hover {
    opacity: 1;
    border-color: var(--accent);
    transform: translateY(-1px);
  }
}
.audio-btn.is-active {
  opacity: 1;
  color: #000;
  background: var(--accent);
  border-color: var(--accent);
}
.audio-icon {
  font-size: 13px;
  line-height: 1;
}
.tile.audio-active {
  box-shadow: inset 0 0 0 1px var(--accent);
}
.tile:focus-visible {
  outline: none;
  transform: scale(1.02);
  box-shadow:
    inset 0 0 0 2px var(--accent),
    0 16px 42px rgba(0,0,0,0.55),
    0 0 0 1px rgba(255,255,255,0.12);
  border-color: var(--accent);
}
.tile.is-dragover:focus-visible {
  transform: scale(1.025);
}

/* Mouse and trackpad: tiles stay clean video until hovered. The tile you're
   listening to keeps its button, so what you hear is always visible. Touch
   devices don't match this query and keep every button showing. */
@media (hover: hover) and (pointer: fine) {
  .tile .audio-btn { opacity: 0; }
  body:not(.is-idle) .tile:hover .audio-btn,
  .tile:focus-within .audio-btn { opacity: 0.78; }
  body:not(.is-idle) .tile .audio-btn:hover,
  .tile .audio-btn:focus-visible,
  .tile .audio-btn.is-active { opacity: 1; }
  body:not(.is-idle) .tile:hover:not(:focus-visible):not(.is-dragover) {
    box-shadow: inset 0 0 0 1.5px var(--accent);
  }
}

/* Pointer idle during playback (app.js "Pointer idle"): fade the header, cursor,
   and hover controls. Channel labels and the Listening badge stay by design. */
body.is-idle .header { opacity: 0; }
body.is-idle,
body.is-idle * { cursor: none !important; }

/* ===================== Sidebar ===================== */
.sidebar {
  position: fixed;
  top: 100px;
  right: 32px;
  bottom: 28px;
  z-index: 12;
  width: 280px;
  flex: none;
  margin-left: 0;
  border-radius: 18px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.97);
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 24px 70px rgba(0,0,0,0.72);
  -webkit-backdrop-filter: var(--sidebar-blur);
  backdrop-filter: var(--sidebar-blur);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  opacity: 1;
  transform: translateX(0);
  transition:
    transform 0.34s cubic-bezier(.34,1.1,.64,1),
    opacity 0.28s ease,
    box-shadow 0.3s ease,
    background 0.4s ease,
    border-color 0.4s ease;
}
.sidebar.is-closed {
  transform: translateX(calc(100% + 16px));
  opacity: 0;
  pointer-events: none;
  box-shadow: none;
  border-color: transparent;
}

.section-label {
  font: 700 11px/1 -apple-system, sans-serif;
  letter-spacing: 0.1em;
  color: var(--text-3);
  white-space: nowrap;
  text-transform: uppercase;
}

.chip-list { display: flex; flex-direction: column; gap: 10px; }
.divider { height: 1px; background: var(--divider); margin: 4px 0; }

.skin-section {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.skin-section .divider { margin: 0; }

.chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--chip-radius);
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  cursor: grab;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s cubic-bezier(.4,0,.2,1);
}
body[data-skin="slate"] .chip {
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--chip-border);
}
@media (hover: hover) and (pointer: fine) { .chip:hover { transform: translateX(2px); } }
.chip.is-dragging { opacity: 0.4; }
.chip.is-armed {
  border: 1.5px solid var(--accent);
  background: var(--accent-fill-soft);
}
.chip-swatch {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: var(--chip-swatch-display);
  align-items: center;
  justify-content: center;
  font: 700 13px/1 -apple-system, sans-serif;
  color: #fff;
  flex: none;
  pointer-events: none;
}
.chip-label { font: 600 14px/1 -apple-system, sans-serif; color: var(--text); pointer-events: none; }
.chip-handle { margin-left: auto; color: var(--chip-icon); font-size: 15px; pointer-events: none; }

/* ===================== Mobile FAB ===================== */
.fab {
  position: fixed;
  bottom: 26px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--fab-bg);
  box-shadow: 0 10px 24px var(--fab-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: background 0.4s ease, box-shadow 0.4s ease, transform 0.2s cubic-bezier(.4,0,.2,1);
}
.fab:active { transform: scale(0.92); }
.fab-grid i { background: var(--fab-icon); }

.chrome-fab,
.mute-fab {
  position: fixed;
  bottom: 26px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0,0,0,0.58);
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 10px 24px rgba(0,0,0,0.28);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.2s cubic-bezier(.4,0,.2,1);
}
.chrome-fab { right: 152px; }
.mute-fab { right: 88px; }
.chrome-fab[hidden] { display: none; }
.chrome-fab:active,
.mute-fab:active { transform: scale(0.92); }
.chrome-fab .fullscreen-icon {
  width: 20px;
  height: 20px;
}
.mute-icon {
  width: 23px;
  height: 23px;
  display: block;
  fill: none;
  stroke: var(--text);
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mute-icon path:first-child {
  fill: var(--text);
  stroke: none;
}
.mute-toggle .mute-icon--off,
.mute-toggle:not(.is-muted) .mute-icon--on { display: none; }
.mute-toggle:not(.is-muted) .mute-icon--off { display: block; }

/* ===================== Bottom sheet ===================== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.001);
  z-index: 15;
  opacity: 0;
  transition: opacity 0.32s ease;
}
.sheet-backdrop.is-open { opacity: 1; }
.sheet-backdrop[hidden] { display: block; pointer-events: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 20px 20px 0 0;
  background: var(--sheet-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--sheet-border);
  padding: 10px 18px calc(26px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateY(102%);
  transition: transform 0.32s cubic-bezier(.4,0,.2,1), background 0.4s ease, border-color 0.4s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100dvh - 12px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sheet.is-open { transform: translateY(0); }

.sheet-topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 36px;
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  margin: -2px 0 2px;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-4);
  grid-column: 2;
  justify-self: center;
}

.sheet-close {
  grid-column: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  justify-self: end;
  background: var(--btn-idle-bg);
  border: 1px solid var(--btn-idle-border);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.sheet-close:active {
  transform: scale(0.94);
}

.layout-grid--mobile {
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.layout-grid--mobile .layout-option {
  padding: 8px 2px;
  border-radius: 10px;
  gap: 4px;
}
.layout-grid--mobile .diagram,
.layout-grid--mobile .grid4 { width: 22px; height: 14px; }
.layout-grid--mobile .opt-label { font-size: 9px; }

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 100px;
  background: var(--chip-bg, rgba(255,255,255,0.07));
  border: 1.5px solid transparent;
  flex: none;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s cubic-bezier(.4,0,.2,1);
}
.pill:active { transform: scale(0.96); }
.pill.is-armed { border-color: var(--accent); }
.pill.is-selected { border-color: var(--accent); background: var(--accent-fill-soft); }
.pill-swatch { width: 20px; height: 20px; border-radius: 6px; flex: none; pointer-events: none; }
.pill-label { font: 600 12px/1 -apple-system, sans-serif; color: var(--text); pointer-events: none; white-space: nowrap; }

/* ===================== Help overlay ===================== */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0,0,0,0.38);
}
.help-overlay[hidden] { display: none; }
.help-dialog {
  width: min(460px, 100%);
  max-height: min(680px, calc(100dvh - 48px));
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.94);
  color: var(--text);
  box-shadow: 0 28px 90px rgba(0,0,0,0.78);
  -webkit-backdrop-filter: var(--sidebar-blur);
  backdrop-filter: var(--sidebar-blur);
}
.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 10px;
}
.help-header h2 {
  margin: 0;
  font: 700 18px/1.2 -apple-system, "SF Pro Display", sans-serif;
}
.help-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--btn-idle-bg);
  border: 1px solid var(--btn-idle-border);
  font-size: 22px;
  line-height: 1;
}
.help-list {
  display: grid;
  gap: 2px;
  padding: 8px 18px 18px;
}
.help-row {
  display: grid;
  grid-template-columns: minmax(76px, auto) 1fr;
  gap: 14px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid var(--divider);
}
.help-key {
  justify-self: start;
  min-width: 34px;
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--text);
  font: 700 12px/1 ui-monospace, Menlo, monospace;
  text-align: center;
}
.help-desc {
  color: var(--text-2);
  font: 500 13px/1.35 -apple-system, "SF Pro Text", sans-serif;
}

/* ===================== Responsive: mobile layout ===================== */
@media (max-width: 780px), ((hover: none) and (pointer: coarse) and (max-height: 500px)) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex; }

  .header {
    height: 56px;
    padding: 14px 18px 8px;
    align-items: center;
    border-bottom: none;
  }
  .logo { gap: 10px; }
  .logo-svg { width: 40px; }
  .logo-divider { height: 17px; }
  .wordmark { font-size: 11px; letter-spacing: 0.26em; margin-right: -0.26em; }

  .body {
    padding: 8px 18px 0;
  }
  .tile-area {
    position: relative;
    left: auto;
    top: auto;
    width: 100%;
    height: auto;
    min-height: 1px;
    transform: none;
  }
}

@media (min-width: 781px) and (hover: hover) and (pointer: fine) {
  .sheet, .sheet-backdrop, .fab, .mute-fab, .chrome-fab { display: none !important; }
}

/* Leave room for the iPad status area without changing phone or desktop chrome. */
@media (min-width: 600px) and (max-width: 1400px) and (pointer: coarse) {
  .app { padding-top: max(20px, env(safe-area-inset-top)); }
  body.is-fullscreen .header { top: max(20px, env(safe-area-inset-top)); }
  .fab, .mute-fab, .chrome-fab { display: none !important; }
}

/* ===================== Motion accessibility ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
  .tile:focus-visible,
  .tile.is-dragover:focus-visible {
    transform: none;
  }
}
