:root {
  --bg: #0e0e10;
  --panel: #18181b;
  --raised: #26262c;
  --hover: #34343c;
  --line: #2f2f35;
  --text: #efeff1;
  --muted: #adadb8;
  --accent: #9147ff;
  --chat-w: 340px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
[hidden] { display: none !important; }

button {
  background: var(--raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
  cursor: pointer;
}
button:hover { background: var(--hover); }
button.on { background: var(--accent); border-color: var(--accent); }

/* ---- top bar ---- */
#top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 10px;
  min-height: 44px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 14px; margin-right: 4px; }
.brand b { color: var(--accent); }
#add { display: flex; gap: 4px; }
#add input {
  width: 300px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  font: inherit;
}
#add input:focus { outline: none; border-color: var(--accent); }
#chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  background: #1f1f23;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.chip button { border: 0; border-radius: 0; background: none; padding: 3px 4px 3px 10px; }
.chip button.x { color: var(--muted); padding: 3px 9px 3px 4px; }
.chip button:hover { background: var(--hover); }
.chip.focused { border-color: var(--accent); }
.chip.audio button:first-child::before { content: "🔊 "; }
.spacer { flex: 1; }
#count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- layout ---- */
main { flex: 1; display: flex; min-height: 0; }
#stage { flex: 1; position: relative; min-width: 0; overflow: hidden; }

.tile {
  position: absolute;
  background: #000;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 0 2px transparent;
  transition: left .15s, top .15s, width .15s, height .15s;
}
.tile.audio { box-shadow: 0 0 0 2px var(--accent); }
.tile .player, .tile .player iframe { display: block; width: 100%; height: 100%; border: 0; }

.bar {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: rgba(14, 14, 16, .88);
  border-radius: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.tile:hover .bar, .bar:focus-within { opacity: 1; }
.bar a, .bar button {
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--text);
  padding: 3px 7px;
  text-decoration: none;
  line-height: 18px;
}
.bar a { font-weight: 600; }
.bar a:hover, .bar button:hover { background: var(--hover); }
.bar button.on { background: var(--accent); }
body.no-api .bar [data-act="audio"], body.no-api #btnMute, body.no-api #bgWrap { display: none; }

#bgWrap { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
#bgSel {
  background: var(--raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
}
#soundGate {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: var(--accent);
  border-color: var(--accent);
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}

/* ---- chat ---- */
#chat {
  position: relative;
  width: var(--chat-w);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
}
#chatHandle {
  position: absolute;
  top: 0; bottom: 0; left: -4px;
  width: 8px;
  cursor: col-resize;
  z-index: 3;
}
#chatHandle:hover { background: var(--accent); opacity: .5; }
#chatHead { flex: none; display: flex; border-bottom: 1px solid var(--line); }
#chatTabs { flex: 1; min-width: 0; display: flex; overflow-x: auto; scrollbar-width: thin; }
#chatPop { flex: none; border: 0; border-left: 1px solid var(--line); border-radius: 0; background: none; padding: 0 12px; color: var(--muted); }
#chatPop:hover { color: var(--text); background: var(--hover); }
#chatTabs button {
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  padding: 8px 10px;
  white-space: nowrap;
}
#chatTabs button.on { color: var(--text); border-bottom-color: var(--accent); }
#chatBody { flex: 1; position: relative; }
#chatBody iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: none; }
#chatBody iframe.on { display: block; }

/* Drag shield: iframes swallow mouse events, so cover them while resizing chat. */
#shield { position: fixed; inset: 0; z-index: 100; display: none; cursor: col-resize; }
body.dragging #shield { display: block; }
body.dragging .tile { transition: none; }

/* ---- empty state & toast ---- */
#empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 16px;
}
#empty h1 { color: var(--text); font-size: 20px; margin: 0 0 6px; }
#recentList { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 14px; max-width: 640px; }
#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
