:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --line: #2a2f37;
  --fg: #e7e9ec;
  --muted: #9aa3ad;
  --accent: #f28c28;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  body.login { --bg: #f4f5f7; --panel: #fff; --line: #d6dae0; --fg: #1b1f24; --muted: #5b636d; color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* login */
body.login { display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; display: grid; gap: 14px; }
.card h1 { margin: 0 0 4px; font-size: 20px; }
.card label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.card input { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; font-size: 16px; }
.card button[type=submit] { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; padding: 10px; }
.err { margin: 0; color: var(--bad); }
.muted { margin: 0; color: var(--muted); }
.btn { display: block; text-align: center; text-decoration: none; background: var(--accent); color: #111; font-weight: 600; padding: 10px; border-radius: 6px; }

/* app */
body.app { display: flex; flex-direction: column; overflow: hidden; height: 100dvh; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line);
}

/* segmented mode switch */
.modes { display: flex; padding: 3px; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.modes button { border: 0; background: transparent; border-radius: 7px; padding: 6px 12px; color: var(--muted); white-space: nowrap; }
.modes button:hover { color: var(--fg); }
.modes button[aria-selected=true] { background: var(--accent); color: #111; font-weight: 600; }

.actions { display: flex; align-items: center; gap: 6px; flex: none; }
button.icon { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 38px; height: 38px; padding: 0 9px; border-radius: 10px; }
button.icon svg { flex: none; }

/* overflow menu */
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; min-width: 180px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.menu-pop[hidden] { display: none; }
.menu-pop form { margin: 0; }
.menu-pop button { display: flex; justify-content: space-between; align-items: center; width: 100%; border: 0; background: transparent; text-align: left; padding: 10px 12px; border-radius: 7px; }
.menu-pop button:hover, .menu-pop button:focus-visible { background: var(--line); }
.menu-pop button[hidden] { display: none; }
kbd { font: 12px/1 ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; }

/* stage + overlays */
#stage { position: relative; flex: 1; min-height: 0; background: #000; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#view:active { cursor: grabbing; }
.hud-top, .hud-bottom { position: absolute; left: 0; right: 0; pointer-events: none; }
.hud-top { top: 0; padding: 10px max(10px, env(safe-area-inset-left)); }
.hud-bottom { bottom: 0; padding: 0 0 max(10px, env(safe-area-inset-bottom)); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #e7e9ec; white-space: nowrap; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.live::before { background: var(--ok); }
.badge.wait::before { background: var(--muted); }
.badge.stale::before { background: var(--warn); }
.badge.off::before { background: var(--bad); }
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; pointer-events: auto;
  padding: 2px max(10px, env(safe-area-inset-left)); scroll-padding-inline: 10px;
  -webkit-overflow-scrolling: touch;
  /* fade the trailing edge so a clipped chip reads as "swipe for more" */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chips[hidden] { display: none; }
.chips button {
  flex: none; white-space: nowrap; font-size: 13px; padding: 7px 14px; border-radius: 999px;
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.18); color: #e7e9ec;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.chips button:hover { border-color: rgba(255,255,255,.45); }
.quad-labels { position: absolute; inset: 0; display: grid; grid-template: 1fr 1fr / 1fr 1fr; gap: 2px; pointer-events: none; }
.quad-labels.stacked { grid-template: repeat(4, 1fr) / 1fr; }
.quad-labels[hidden] { display: none; }
.quad-labels span {
  align-self: end; justify-self: start; margin: 8px; padding: 3px 9px; border-radius: 999px; font-size: 12px;
  background: rgba(0,0,0,.55); color: #e7e9ec; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modes .short { display: none; }
.warn { margin: 0; padding: 6px 12px; background: #3a2a05; color: #f5d27a; border-bottom: 1px solid #6b4f12; font-size: 13px; }
.warn[hidden] { display: none; }
.msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; padding: 10px 14px; background: rgba(0,0,0,.7); border-radius: 8px; color: var(--fg); text-align: center; max-width: calc(100% - 32px); }
body.stale #view { filter: grayscale(.7) brightness(.8); }

@media (max-width: 560px) {
  .bar { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .modes button { padding: 6px 9px; }
  .modes .long { display: none; }
  .modes .short { display: inline; }
  button.icon .label { display: none; }
}
@media (max-width: 340px) {
  .modes button { padding: 6px 7px; font-size: 14px; }
}
