/* A friends' arcade at night (docs/DESIGN.md): the stage is the cabinet, each shared screen a
   monitor, each person a player with a color. Shared content stays the brightest thing; the
   marquee yellow marks only what is yours or live. */
:root {
  color-scheme: dark;
  --wall: #17142b;
  --edge: rgba(31, 27, 58, 0.95);
  --solid: #1f1b3a;
  --raise: #2a2550;
  --line: #3a3466;
  --glass: #0f0d1f;
  --text: #ece8f7;
  --dim: #9c96bf;
  --amber: #f4c95d;
  --amber-ink: #2b1f05;
  --mint: #86d9a0;
  --coral: #ef7b86;
  --font-head: Bahnschrift, "DIN Alternate", "Arial Narrow", sans-serif;
  --font-ui: Bahnschrift, "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--wall);
}

body {
  color: var(--text);
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

svg.i {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

input {
  background: var(--solid);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 3px;
  border-width: 2px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  width: 100%;
}

input::placeholder {
  color: var(--dim);
}

.primary {
  background: var(--amber);
  color: var(--amber-ink);
  border: 0;
  border-radius: 3px;
  padding: 10px 18px;
  font-family: var(--font-head);
  font-weight: 700;
}

.ghost {
  background: transparent;
  border: 2px solid var(--line);
  border-radius: 3px;
  padding: 9px 16px;
  font-weight: 600;
}

.danger {
  color: var(--coral);
}

.hint {
  color: var(--dim);
  font-size: 13.5px;
  margin: 0;
}

.row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------- Door ---------- */
.door {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-left, 0px));
}

.door {
  background: radial-gradient(ellipse at 50% 40%, #231e44 0%, var(--wall) 70%);
}

.door form {
  display: grid;
  gap: 10px;
  width: min(320px, 100%);
}

.door h1 {
  font-family: var(--font-head);
  font-stretch: 75%;
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--amber);
  text-shadow: 0 3px 0 #a8833a, 0 6px 0 var(--glass);
  margin: 0 0 18px;
  text-align: center;
  overflow-wrap: anywhere;
}

.door button {
  background: var(--amber);
  color: var(--amber-ink);
  border: 0;
  padding: 13px;
  font-family: var(--font-head);
  font-stretch: 85%;
  font-weight: 700;
  font-size: 18px;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px),
    calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
}

.door .err {
  color: var(--coral);
  font-size: 13.5px;
  text-align: center;
  margin: 0;
}

/* ---------- Room ---------- */
.room {
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

.room.idle {
  cursor: none;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  isolation: isolate;
  overflow: hidden;
  background:
    repeating-linear-gradient(to bottom, transparent 0 2px, rgba(6, 5, 16, 0.16) 2px 3px),
    radial-gradient(ellipse at 50% 45%, #211c40 0%, var(--wall) 75%);
}

.overlay {
  position: absolute;
  z-index: 10;
  background: var(--edge);
  border: 2px solid var(--line);
  transition: opacity 0.35s, transform 0.35s;
}

.room.idle .overlay {
  opacity: 0;
  pointer-events: none;
}

.room.idle .rail.left {
  transform: translateX(-12px);
}

.room.idle .rail.right {
  transform: translateX(12px);
}

.room.idle .controls {
  transform: translate(-50%, 12px);
}

.rail {
  top: 12px;
  bottom: 76px;
  width: 64px;
  border-radius: 4px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 10px;
  padding: 12px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.rail.left {
  left: 12px;
}

.rail.right {
  right: 12px;
}

.room.no-people .rail.left, .room.no-screens .rail.right {
  display: none;
}

.person {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid var(--glass);
  padding: 0;
  position: relative;
  display: grid;
  place-items: center;
  font-family: var(--font-head);
  font-stretch: 85%;
  font-weight: 700;
  font-size: 17px;
  color: var(--glass);
  background: var(--p, var(--raise));
  overflow: hidden;
}

.person video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.person span {
  position: relative;
}

.person.cam {
  border-color: var(--mint);
}

.person.sharing::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 2px var(--solid);
}

.person[aria-pressed="true"] {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.person.away {
  opacity: 0.45;
}

.screen-btn {
  width: 48px;
  aspect-ratio: 16 / 10;
  border-radius: 2px;
  border: 2px solid var(--p, var(--line));
  padding: 0;
  background: var(--glass);
  display: grid;
  place-items: center;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 13px;
  position: relative;
}

.screen-btn[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--text);
}

.screen-btn.mine {
  border-color: var(--amber);
}

.screen-btn span {
  max-width: 100%;
  padding: 0 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-stretch: 80%;
  font-weight: 700;
  color: var(--p, var(--dim));
}

.screen-btn[aria-pressed="true"] span {
  color: var(--text);
}

.screen-btn.mine span {
  color: var(--amber);
}

.screen-btn .live {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--coral);
  border: 1.5px solid var(--wall);
}

.controls {
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
}

.ctrl {
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border-radius: 3px;
  border: 0;
  background: transparent;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.ctrl:hover {
  background: var(--raise);
}

.ctrl[aria-pressed="true"] {
  background: var(--raise);
  color: var(--mint);
}

/* The arcade button: the one thing that puts you on the screens. */
.ctrl.cast {
  background: var(--amber);
  color: var(--amber-ink);
  font-family: var(--font-head);
  font-stretch: 85%;
  font-weight: 700;
  font-size: 16px;
  padding: 0 14px;
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 6px, 100% calc(100% - 6px),
    calc(100% - 6px) 100%, 6px 100%, 0 calc(100% - 6px), 0 6px);
}

.ctrl.cast:hover {
  background: #f7d77f;
}

.ctrl.cast[aria-pressed="true"] {
  background: var(--coral);
  color: #2b0a0e;
}

.ctrl[aria-expanded="true"] {
  background: var(--raise);
}

.ctrl:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.vol {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  color: var(--dim);
}

.vol button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 6px;
  border-radius: 3px;
  display: grid;
  place-items: center;
}

.vol button:hover {
  background: var(--raise);
  color: var(--text);
}

.vol button[aria-pressed="true"] .wave,
.vol button[aria-pressed="false"] .cross {
  display: none;
}

.vol button[aria-pressed="true"] {
  color: var(--coral);
}

.vol input {
  width: 96px;
  accent-color: var(--amber);
  padding: 0;
}

.sep {
  width: 1px;
  height: 24px;
  background: var(--line);
  margin: 0 4px;
}

.layouts {
  display: inline-flex;
  gap: 2px;
  background: var(--glass);
  border-radius: 3px;
  padding: 2px;
}

.layouts button {
  width: 36px;
  height: 34px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--dim);
}

.layouts button[aria-pressed="true"] {
  background: var(--raise);
  color: var(--text);
}

.menu {
  position: absolute;
  bottom: calc(100% + 8px);
  background: var(--solid);
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 5px;
  min-width: 260px;
  display: grid;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.65);
  z-index: 20;
}

/* Groups of items (invite, admin) stack like the menu, so each item spans its whole width. */
.menu > div:not(.sub) {
  display: grid;
}

.menu.at-left {
  left: 0;
}

.menu.at-right {
  right: 0;
}

.menu button {
  border: 0;
  background: transparent;
  border-radius: 2px;
  padding: 8px 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  font-size: 14.5px;
}

.menu button:hover {
  background: var(--raise);
}

.menu .check {
  width: 18px;
  color: var(--mint);
  display: inline-grid;
  place-items: center;
}

.menu small {
  margin-left: auto;
  color: var(--dim);
  font-size: 12.5px;
}

.menu hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 2px;
}

.menu .sub {
  color: var(--dim);
  font-size: 12.5px;
  padding: 6px 10px 2px;
}

#obs-box {
  display: grid;
  gap: 6px;
  padding: 6px 6px 4px;
}

.copy {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--wall);
  border-radius: 7px;
  padding: 5px 5px 5px 10px;
  font-size: 12.5px;
  min-width: 0;
}

.copy span {
  color: var(--dim);
}

.copy code {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Consolas, ui-monospace, monospace;
}

.menu .copy button {
  padding: 3px 8px;
  background: var(--raise);
  font-size: 12px;
}

/* Shown to the sharer when the captured window closes; stays visible while idle. */
.lost {
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-color: var(--amber);
  border-radius: 4px;
  z-index: 15;
}

.room.idle .lost {
  opacity: 1;
  pointer-events: auto;
}

.toast {
  position: absolute;
  left: 50%;
  top: max(14px, env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  background: var(--raise);
  border: 2px solid var(--amber);
  border-radius: 3px;
  padding: 7px 14px;
  font-size: 13.5px;
  z-index: 30;
}

/* ---------- Windows ---------- */
.win {
  position: absolute;
  border-radius: 2px;
  overflow: hidden;
  background: var(--glass);
  min-width: 160px;
  min-height: 90px;
  box-shadow: 0 0 0 3px var(--glass), 0 0 0 5px var(--p, var(--line)),
    0 18px 36px -14px rgba(0, 0, 0, 0.8);
  cursor: grab;
  transition: left 0.18s, top 0.18s, width 0.18s, height 0.18s;
  touch-action: none;
  animation: crt-on 0.42s ease-out;
}

@keyframes crt-on {
  0% { clip-path: inset(49.5% 0 49.5% 0); filter: brightness(3); }
  45% { clip-path: inset(49.5% 0 49.5% 0); filter: brightness(2.2); }
  100% { clip-path: inset(0 0 0 0); filter: brightness(1); }
}

.win.moving {
  transition: none;
  cursor: grabbing;
}

.win.max {
  border-radius: 0;
}

.win.mine {
  --p: var(--amber);
}

.win video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--glass);
  pointer-events: none;
}

.win.cam video {
  object-fit: cover;
}

.win .waiting {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--dim);
  font-size: 13.5px;
}

.win .title {
  position: absolute;
  inset: 0 0 auto 0;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px 0 10px;
  background: linear-gradient(rgba(15, 13, 31, 0.94), rgba(15, 13, 31, 0.6));
  border-top: 3px solid var(--p, var(--line));
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s;
  user-select: none;
}

.win:hover .title, .win:focus-within .title, .win.moving .title {
  opacity: 1;
}

.room.idle .win .title {
  opacity: 0;
}

.title .label {
  font-family: var(--font-head);
  font-stretch: 85%;
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.title button {
  width: 30px;
  height: 26px;
  border-radius: 2px;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
}

.title button:hover {
  background: var(--raise);
}

.title button[data-close]:hover {
  background: var(--coral);
  color: #2a0d08;
}

.title button[data-pencil][aria-pressed="true"] {
  background: var(--amber);
  color: var(--amber-ink);
}

.sketch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.win.drawing {
  cursor: crosshair;
}

.title svg.i {
  width: 15px;
  height: 15px;
}

.rz {
  position: absolute;
  z-index: 3;
}

.rz-n {
  top: 0;
  left: 8px;
  right: 8px;
  height: 5px;
  cursor: ns-resize;
}

.rz-s {
  bottom: 0;
  left: 8px;
  right: 8px;
  height: 6px;
  cursor: ns-resize;
}

.rz-e {
  right: 0;
  top: 8px;
  bottom: 8px;
  width: 6px;
  cursor: ew-resize;
}

.rz-w {
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 6px;
  cursor: ew-resize;
}

.rz-ne, .rz-nw, .rz-se, .rz-sw {
  width: 12px;
  height: 12px;
}

.rz-ne {
  top: 0;
  right: 0;
  cursor: nesw-resize;
}

.rz-sw {
  bottom: 0;
  left: 0;
  cursor: nesw-resize;
}

.rz-nw {
  top: 0;
  left: 0;
  cursor: nwse-resize;
}

.rz-se {
  bottom: 0;
  right: 0;
  cursor: nwse-resize;
}

.win.max .rz {
  display: none;
}

.snap {
  position: absolute;
  z-index: 9000;
  border: 2px dashed var(--amber);
  background: rgba(244, 201, 93, 0.12);
  border-radius: 2px;
  pointer-events: none;
  transition: all 0.12s;
}

.snap-grid {
  position: absolute;
  z-index: 8998;
  pointer-events: none;
  border: 1px dashed rgba(244, 201, 93, 0.22);
  background-image:
    linear-gradient(rgba(244, 201, 93, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 201, 93, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--dim);
  text-align: center;
  padding: 0 90px;
}

.empty div {
  display: grid;
  gap: 10px;
  justify-items: center;
}

.empty svg.i {
  width: 34px;
  height: 34px;
  stroke-width: 1.4;
}

/* ---------- Desktop app picker ---------- */
#pick-dialog {
  width: min(760px, calc(100vw - 32px));
}

.sources {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.source {
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background: var(--glass);
  text-align: left;
}

.source img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
}

.source span {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source[aria-pressed="true"] {
  border-color: var(--amber);
}

.opt {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.opt input {
  width: auto;
}

#pick-dialog .err {
  color: var(--coral);
  margin: 0;
}

/* ---------- Dialogs ---------- */
dialog {
  background: var(--solid);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  width: min(440px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgba(9, 8, 20, 0.75);
}

dialog form {
  display: grid;
  gap: 12px;
}

dialog h2 {
  font-family: var(--font-head);
  font-stretch: 85%;
  font-size: 1.35rem;
  margin: 0;
}

.members {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  max-height: 50vh;
  overflow-y: auto;
}

.members li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
}

.members .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--glass);
  background: var(--p, var(--raise));
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: 0 0 auto;
}

.members small {
  display: block;
  color: var(--dim);
  font-size: 12px;
}

.members .acts {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.members .acts button {
  border: 2px solid var(--line);
  background: transparent;
  border-radius: 2px;
  padding: 4px 9px;
  font-size: 13px;
}

.members .acts button.danger {
  border-color: var(--coral);
}

@media (max-width: 760px) {
  .rail {
    width: 52px;
    padding: 10px 5px;
  }
  .person {
    width: 34px;
    height: 34px;
  }
  .screen-btn {
    width: 38px;
  }
  .vol input {
    width: 56px;
  }
  .ctrl .txt {
    display: none;
  }
  .layouts {
    display: none;
  }
  .controls .sep:nth-of-type(2) {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
