/* Neon tide: blue-black glass, a teal-to-violet tide for accents. Fonts are
   self-hosted (assets/fonts, SIL OFL), so the page makes no third-party requests. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../assets/fonts/inter-latin-wght-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../assets/fonts/space-grotesk-latin-wght-normal.woff2') format('woff2');
}

:root {
  --bg: #060a13;
  --panel: #0a101d;
  --card: rgba(22, 30, 52, 0.62);
  --line: rgba(120, 160, 255, 0.14);
  --text: #e8edf7;
  --muted: #7d8db0;
  --faint: #4f5b78;
  --accent: #33e1e6;
  --accent-2: #9d7bff;
  --tide: linear-gradient(90deg, var(--accent), var(--accent-2));
  --on-tide: #061018;
  --accent-soft: rgba(51, 225, 230, 0.14);
  --glass: blur(12px);
  --display: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --topbar: 52px;
  --side: 264px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  height: var(--topbar);
  background: rgba(12, 18, 32, 0.7);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 600 21px/1 var(--display);
  letter-spacing: -0.02em;
}
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-word { background: var(--tide); -webkit-background-clip: text; background-clip: text; color: transparent; }

.rooms { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: rgba(255, 255, 255, 0.05); }

.room {
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font: 500 13px/1 var(--display);
  color: var(--muted);
}
.room:hover { color: var(--text); }
.room.is-active { color: var(--on-tide); background: var(--tide); }

.spacer { flex: 1; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  display: grid;
  place-items: center;
  font-size: 16px;
  backdrop-filter: var(--glass);
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn-small { width: 24px; height: 24px; font-size: 14px; }

/* ---------------------------------------------------------------- layout */

.app {
  height: calc(100% - var(--topbar));
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr) var(--side);
}

.panel {
  background: var(--panel);
  overflow-y: auto;
  padding: 16px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }

.room-head { display: flex; gap: 12px; align-items: flex-start; }

.room-mark {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  gap: 2px;
  margin-top: 6px;
}
.room-mark i { height: 12px; border-radius: 3px; background: var(--text); }
.room-mark i:nth-child(4) { background: var(--tide); }
.room-mark i:nth-child(2) { background: none; }

.room-title {
  margin: 0;
  font: 600 24px/1.05 var(--display);
  letter-spacing: -0.02em;
}

.hint, small { color: var(--muted); font-size: 11.5px; margin: 0; }

.label {
  margin: 8px 0 -4px;
  font: 600 10.5px var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.card {
  background: var(--card);
  backdrop-filter: var(--glass);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stack { display: flex; flex-direction: column; gap: 14px; }

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kv b, .toggle b { font-weight: 500; }

/* -------------------------------------------------------------- controls */

.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 7px 14px;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.is-on { border-color: var(--accent); background: var(--accent-soft); }
.btn-wide { width: 100%; }
.btn-small { padding: 3px 10px; font-size: 12px; }
.btn-danger { color: #ff7a9a; }
.btn-accent { background: var(--tide); border-color: transparent; color: var(--on-tide); font-weight: 600; }
.btn-accent:hover:not(:disabled) { border-color: transparent; filter: brightness(1.12); }
.btn-accent.is-on { background: var(--card); color: var(--text); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.toggle-text { display: flex; flex-direction: column; gap: 2px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  position: relative;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}
.toggle input:checked + .switch { background: var(--tide); }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.range-field { display: flex; flex-direction: column; gap: 6px; }
input[type='range'] { width: 100%; accent-color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: none;
  border-radius: 999px;
  padding: 5px 11px;
  color: var(--muted);
}
.chip:hover { color: var(--text); }
.chip.is-active { color: #e8f9ff; border-color: #5fd8e6; background: linear-gradient(90deg, rgba(51, 225, 230, 0.25), rgba(157, 123, 255, 0.25)); }

.dropzone {
  border: 1px dashed rgba(120, 160, 255, 0.28);
  border-radius: 16px;
  background: var(--card);
  padding: 14px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dropzone strong { font-size: 14px; font-weight: 600; }
.dropzone p { margin: 0; color: var(--muted); font-size: 11.5px; }
body.dragging .dropzone { border-color: var(--accent); background: var(--accent-soft); }

.audio-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.text-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  padding: 7px 12px;
}
.text-input:focus { border-color: var(--muted); outline: none; }
.text-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.fold > summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: '▸'; color: var(--muted); font-size: 11px; }
.fold[open] > summary::before { content: '▾'; }
.fold > summary .label { margin: 0; }
.fold-note { color: var(--muted); font-size: 11.5px; margin-left: auto; }
.fold .btn { align-self: flex-start; }
.tag-search { position: relative; display: flex; }
.tag-search .text-input { padding-right: 30px; }
.tag-search .text-input::-webkit-search-cancel-button { display: none; } /* our own × instead */
.tag-search-clear { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; }

.kept-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.kept-list li { display: flex; align-items: center; gap: 6px; }
.kept-list span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

body:not([data-room='scroller']) .scroller-only { display: none; }
body[data-room='scroller'] .wall-only,
body[data-room='scroller'] .tile-loop { display: none; } /* everything loops there */

/* ----------------------------------------------------------------- stage */

.stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  overflow: clip; /* also blocks focus-driven scrolling of the wall */
  background: var(--bg);
}

.wall { position: absolute; inset: 0; will-change: transform; }

.tile {
  position: absolute;
  top: 0;
  left: 0;
  cursor: zoom-in;
  /* No text selection or iOS callout on a long press. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation; /* no double-tap-zoom delay */
  transition: transform 0.35s ease, width 0.35s ease, height 0.35s ease;
}
body[data-room='scroller'] .tile { transition: none; }
.tile video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.wall.crop .tile video { object-fit: cover; }
.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.tile:hover::after,
.tile.touch-hover::after { opacity: 1; }

.tile-skip,
.tile-loop,
.tile-big,
.tile-sound {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  /* No backdrop-filter here: blurring over a playing video stops Chrome
     painting its frames. */
  background: rgba(6, 10, 19, 0.72);
  color: #e8f9ff;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  /* Hidden buttons can't be hit: on touch, a tap on a tile's corner opens the
     clip rather than pressing a button you can't see. */
  pointer-events: none;
  transition: opacity 0.15s, background 0.15s;
}
.tile:hover :is(.tile-skip, .tile-loop, .tile-big, .tile-sound),
.tile.touch-hover :is(.tile-skip, .tile-loop, .tile-big, .tile-sound),
:is(.tile-skip, .tile-loop, .tile-big, .tile-sound):focus-visible { pointer-events: auto; }
/* ↻ sits opposite the ×: top left. The speaker sits bottom right. */
.tile-loop { right: auto; left: 6px; font-size: 16px; }
.tile-sound { top: auto; bottom: 6px; }
/* + / − (enlarge) sits bottom left. Wall only. */
.tile-big { top: auto; bottom: 6px; right: auto; left: 6px; font-size: 20px; }
body[data-room='scroller'] .tile-big { display: none; }
.tile-sound .sound-off,
.tile.is-heard .tile-sound .sound-on { display: inline; }
.tile-sound .sound-on,
.tile.is-heard .tile-sound .sound-off { display: none; }
.tile:hover .tile-skip,
.tile.touch-hover .tile-skip,
.tile-skip:focus-visible,
.tile:hover .tile-loop,
.tile.touch-hover .tile-loop,
.tile-loop:focus-visible,
.tile:hover .tile-sound,
.tile.touch-hover .tile-sound,
.tile-sound:focus-visible,
.tile:hover .tile-big,
.tile.touch-hover .tile-big,
.tile-big:focus-visible { opacity: 1; }
.tile-skip:hover,
.tile-loop:hover,
.tile-sound:hover,
.tile-big:hover,
.tile.is-held .tile-loop,
.tile.has-sound-override .tile-sound { background: var(--tide); color: var(--on-tide); }
body.idle .tile:hover .tile-skip,
body.idle .tile:hover .tile-loop,
body.idle .tile:hover .tile-sound,
body.idle .tile:hover .tile-big,
body.idle .tile:hover::after { opacity: 0; }
/* A long press reveals the buttons even though touch leaves the page "idle".
   Same specificity as the rule above, so it must come after it. */
body.idle .tile.touch-hover .tile-skip,
body.idle .tile.touch-hover .tile-loop,
body.idle .tile.touch-hover .tile-sound,
body.idle .tile.touch-hover .tile-big,
body.idle .tile.touch-hover::after { opacity: 1; }
/* A held clip keeps its ↻ showing, and a clip heard or silenced by hand its
   speaker, so you can see which clips break the rules. */
.tile.is-held .tile-loop,
body.idle .tile.is-held .tile-loop,
.tile.has-sound-override .tile-sound,
body.idle .tile.has-sound-override .tile-sound { opacity: 0.9; }

/* The main clip: never skipped or held (it always loops), and labelled on hover. */
.tile.is-main .tile-skip,
.tile.is-main .tile-loop { display: none; }
.tile.is-main::before {
  content: 'Main clip';
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--tide);
  color: var(--on-tide);
  font-size: 11px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.tile.is-main:hover::before,
.tile.is-main.touch-hover::before { opacity: 1; }
body.idle .tile.is-main:hover::before { opacity: 0; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 16px;
  pointer-events: none;
}
.empty h1 {
  margin: 0;
  font: 600 clamp(40px, 7vw, 96px)/1 var(--display);
  letter-spacing: -0.03em;
  background: var(--tide);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.empty p { color: var(--muted); font-size: 14px; }

.focus {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
}
.focus video { max-width: 88%; max-height: 88%; border-radius: 14px; box-shadow: 0 20px 80px rgba(0, 0, 0, 0.7); }
.focus-close { position: absolute; top: 14px; right: 14px; }

.drop-veil {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  background: rgba(51, 225, 230, 0.08);
  font: 600 44px/1 var(--display);
  letter-spacing: -0.02em;
  pointer-events: none;
}
body.dragging .drop-veil { display: grid; }

body.idle .stage,
body.idle .stage * { cursor: none !important; }

.stage:fullscreen { background: #000; }

.status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
}
.status .warn { color: #ff8a8a; }
.muted { color: var(--faint); }

/* ----------------------------------------------------------------- guide */

.guide {
  max-width: 520px;
  width: calc(100% - 32px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
}
.guide::backdrop { background: rgba(0, 0, 0, 0.7); }
.guide ol { padding-left: 18px; display: flex; flex-direction: column; gap: 10px; color: #c8d2e6; }
.guide b { color: var(--text); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 16px 0 20px; }
.keys dd { margin: 0; color: var(--muted); }
kbd {
  font: 11px var(--ui);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  background: var(--card);
}

/* ------------------------------------------------------------ narrow use */

/* Adjust has its own column on wide screens. Narrower, it slides in over the
   stage from the toolbar's Adjust button. */
.adjust-btn,
.adjust-close { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: var(--side) minmax(0, 1fr); }
  .adjust-btn { display: inline-block; }
  .adjust-close { display: grid; }
  body.adjust-open .adjust-btn { border-color: var(--accent); background: var(--accent-soft); }
  .panel-right {
    position: fixed;
    top: var(--topbar);
    right: 0;
    bottom: 0;
    z-index: 20;
    width: min(var(--side), 100vw);
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.6);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }
  body.adjust-open .panel-right { transform: none; visibility: visible; }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .topbar { gap: 12px; }
  .app { display: flex; flex-direction: column-reverse; height: auto; }
  .stage-wrap { height: 70vh; }
  .panel-left { border-right: 0; border-top: 1px solid var(--line); }
}

/* Bigger × for fingers. */
@media (pointer: coarse) {
  .tile-skip,
  .tile-loop,
  .tile-big,
  .tile-sound { width: 40px; height: 40px; font-size: 22px; }
  .tile-sound svg { width: 22px; height: 22px; }
}

/* ------------------------------------------------------- back to reality */

.quit-btn { font-size: 12px; padding: 6px 12px; }
.quit-dialog { max-width: 380px; }
.farewell {
  height: 100vh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  padding: 16px;
}
.farewell .brand { justify-content: center; font-size: clamp(40px, 9vw, 80px); }
.farewell .brand-mark { width: 0.9em; height: 0.9em; }
.farewell p { color: var(--muted); margin: 0; }
