*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #0b0b0d;
  --panel: #141418;
  --line: #24242c;
  --fg: #f4f4f1;
  --dim: #8b8b96;
  --said: #43434e;
  --accent: #ffc857;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.view { height: 100%; }
.hidden { display: none !important; }

/* ---------- editor ---------- */

#editor { overflow-y: auto; }

.shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 48px 28px 64px;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.ghost {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font: 400 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
}

.ghost:hover { border-color: #3f3f4c; background: var(--panel); }

#signedIn { display: flex; align-items: center; gap: 12px; }
#userEmail { color: var(--dim); font-size: 13px; }

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.workspace.solo { grid-template-columns: minmax(0, 1fr); }

@media (max-width: 700px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  #scriptList { max-height: 180px; }
}

#library {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lib-head .ghost { padding: 5px 10px; font-size: 12px; text-transform: none; letter-spacing: 0; }

#scriptList { margin: 0; padding: 0; list-style: none; max-height: 320px; overflow-y: auto; }

#scriptList li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
}

#scriptList li:hover { background: #1c1c22; }
#scriptList li.active { background: #23232b; }
#scriptList .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#scriptList .when { color: var(--dim); font-size: 11px; }

#scriptList .del {
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  opacity: 0;
}

#scriptList li:hover .del { opacity: 1; }
#scriptList .del:hover { background: #2e2e38; color: var(--fg); }

#scriptList .empty { color: var(--dim); cursor: default; font-size: 13px; }
#scriptList .empty:hover { background: transparent; }

.title-row { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }

#title {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--fg);
  font: 500 14px/1.2 inherit;
  outline: none;
}

#title:focus { border-color: #3a3a46; }
#title.hidden { display: none; }

#saveState { color: var(--dim); font-size: 12px; white-space: nowrap; }

.sub {
  margin: 6px 0 28px;
  color: var(--dim);
  font-size: 14px;
}

#script {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--fg);
  font: 400 16px/1.7 ui-sans-serif, -apple-system, system-ui, sans-serif;
  outline: none;
}

#script:focus { border-color: #3a3a46; }

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px 22px;
  margin: 26px 0 8px;
}

.field { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--dim); }
.field b { color: var(--fg); font-weight: 500; }

select {
  appearance: none;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--fg);
  font-size: 14px;
}

input[type=range] {
  appearance: none;
  height: 4px;
  margin: 12px 0;
  border-radius: 99px;
  background: var(--line);
}

input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg);
  cursor: pointer;
}

.toggles { gap: 12px; justify-content: center; }
.check { display: flex; align-items: center; gap: 9px; color: var(--fg); font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.actions { display: flex; align-items: center; gap: 16px; margin-top: 26px; }

.primary {
  padding: 13px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--fg);
  color: #101014;
  font: 500 15px/1 inherit;
  cursor: pointer;
}

.primary:hover { background: #fff; }
.hint { color: var(--dim); font-size: 13px; }

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 34px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
  color: var(--dim);
  font-size: 12px;
}

kbd {
  display: inline-block;
  min-width: 20px;
  margin-right: 4px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font: 500 11px/1.4 ui-monospace, monospace;
  text-align: center;
}

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

#stage {
  position: relative;
  overflow: hidden;
  background: #07070a;
  --size: 46px;
  --width: 70%;
}

#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 13%, #000 84%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 13%, #000 84%, transparent 100%);
}

#stage.mirror #viewport { transform: scaleX(-1); }

#band {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  height: calc(var(--size) * 1.42);
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.045) 18%, rgba(255, 255, 255, 0.045) 82%, transparent);
  pointer-events: none;
}

#track {
  position: relative;
  width: var(--width);
  margin: 0 auto;
  padding: 38vh 0 78vh;
  font-size: var(--size);
  font-weight: 450;
  line-height: 1.42;
  letter-spacing: -0.005em;
  will-change: transform;
}

#track p { margin: 0 0 1.05em; }

#track span {
  transition: color 260ms ease, opacity 260ms ease;
}

#track span.said { color: var(--said); }
#track span.now { color: var(--accent); }

#exit {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 5;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 20, 26, 0.6);
  color: var(--dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 200ms ease;
}

#exit:hover, #exit:focus-visible { opacity: 1; }

#cam {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 3;
  width: min(210px, 30vw);
  border-radius: 12px;
  background: #000;
  transform: scaleX(-1);
  opacity: 0.85;
}

#cam.hidden { display: none; }

#progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  height: 2px;
  background: rgba(255, 255, 255, 0.07);
}

#progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 200ms linear;
}

#hud {
  position: absolute;
  bottom: 22px;
  left: 50%;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 15px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(14, 14, 18, 0.72);
  backdrop-filter: blur(8px);
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.02em;
  transform: translateX(-50%);
  transition: opacity 400ms ease;
}

#hud.faded { opacity: 0.18; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3c3c46;
  transition: background 200ms ease, box-shadow 200ms ease;
}

.dot.live {
  background: #6ee7a8;
  box-shadow: 0 0 0 4px rgba(110, 231, 168, 0.14);
}

.sep { opacity: 0.4; }

#toast {
  position: absolute;
  top: 26px;
  left: 50%;
  z-index: 5;
  max-width: 460px;
  padding: 11px 18px;
  border-radius: 12px;
  background: rgba(255, 200, 87, 0.12);
  color: var(--accent);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  transform: translateX(-50%) translateY(-8px);
  transition: opacity 300ms ease, transform 300ms ease;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
