/* ZeroLab Caller */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #101010;
  --surface: #181818;
  --border: #2a2a2a;
  --text: #c8c8c8;
  --text-dim: #666;
  --accent: #e04e1a;
  --green: #2ea043;
  --red: #c33;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "SF Mono", monospace;
}

html { font-size: 15px; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.03em; }
.brand-zero { color: #fff; }
.brand-lab  { color: var(--accent); }
.brand-link { text-decoration: none; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.version {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

.my-name {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
}

.rename-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
  transition: color .15s;
}
.rename-btn:hover { color: var(--text); }

.room-tag {
  font-family: var(--mono);
  font-size: 0.7rem;
  background: var(--border);
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 3px;
}

.invite-btn {
  font-family: var(--mono);
  font-size: 0.7rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color .15s;
}
.invite-btn:hover { border-color: var(--accent); }

/* ---------- main (room page) ---------- */

.room-main {
  flex: 1;
  width: 100%;
  padding: 16px 24px;
}

/* ---------- 2-column room layout: chat + center ---------- */

.room-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  min-height: calc(100vh - 120px);
}

.panel-title {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text-dim);
  text-transform: lowercase;
  margin-bottom: 12px;
}

/* ---------- center panel ---------- */

.center-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

/* ---------- status ---------- */

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--mono);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #444;
  flex-shrink: 0;
}

.dot.live {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: blink 2s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: .4; }
}

/* ---------- participants grid (tile cards) ---------- */

.participants-grid {
  flex: 1;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  grid-auto-rows: min-content;
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  min-height: 0;
  padding: 4px;
}
.participants-grid.hidden { display: none; }

/* ---------- featured tile (expanded) ---------- */

.featured-tile {
  width: 100%;
  flex: 1 1 0;
  min-height: 120px;
  background: var(--bg);
  border: 2px solid var(--accent);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
  position: relative;
  overflow: hidden;
}
.featured-tile.hidden { display: none; }

.featured-tile.speaking {
  border-color: var(--green);
  box-shadow: 0 0 20px rgba(46, 160, 67, .3);
}

.featured-tile .tile-avatar {
  width: 80px;
  height: 80px;
  aspect-ratio: 1;
  font-size: 2.2rem;
}

.featured-tile .tile-name {
  font-size: 1.1rem;
}

.featured-tile .tile-icons {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 1rem;
  gap: 10px;
  background: rgba(0,0,0,.4);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---------- carousel (horizontal strip below featured) ---------- */

.carousel {
  width: 100%;
  height: 122px;
  min-height: 122px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 6px 2px;
  flex-shrink: 0;
}
.carousel.hidden { display: none; }

.carousel::-webkit-scrollbar { height: 4px; }
.carousel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.carousel .participant-tile {
  flex: 0 0 110px;
  min-width: 110px;
  height: 110px;
  min-height: 110px;
  aspect-ratio: auto;
  scroll-snap-align: start;
  padding: 8px 6px;
  gap: 4px;
}

.carousel .tile-avatar {
  width: 36px;
  height: 36px;
  aspect-ratio: 1;
  font-size: 1rem;
}

.carousel .tile-name {
  font-size: 0.65rem;
}

.participant-tile {
  aspect-ratio: 1;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color .2s, background .2s, box-shadow .2s;
  padding: 12px 8px;
  position: relative;
}

.participant-tile:hover {
  border-color: #555;
  background: #1a1a1a;
}

.participant-tile.speaking {
  border-color: var(--green);
  box-shadow: 0 0 12px rgba(46, 160, 67, .25);
}

.participant-tile.is-me {
  border-color: var(--accent);
}
.participant-tile.is-me.speaking {
  border-color: var(--green);
}

.tile-avatar {
  width: 48px;
  height: 48px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.tile-name {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}
.tile-name.is-me { color: var(--accent); }

.tile-icons {
  display: flex;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.icon-mic-off {
  display: flex;
  color: var(--red);
}

/* ---------- tile video overlay ---------- */

.participant-tile.has-video,
.featured-tile.has-video {
  padding: 0;
  overflow: hidden;
}

.tile-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  z-index: 0;
  border-radius: 6px;
}
.tile-video.no-mirror { transform: none; }

.participant-tile.has-video .tile-avatar,
.featured-tile.has-video .tile-avatar { display: none; }

.participant-tile.has-video .tile-name,
.featured-tile.has-video .tile-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  background: rgba(0,0,0,.55);
  padding: 3px 6px;
  border-radius: 0 0 6px 6px;
}

.participant-tile.has-video .tile-icons,
.featured-tile.has-video .tile-icons {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  background: rgba(0,0,0,.4);
  padding: 2px 5px;
  border-radius: 4px;
}

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

.bottom-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  gap: 10px;
}

.actions button {
  padding: 10px 24px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.actions button:hover:not(:disabled) {
  border-color: #555;
  background: #222;
}

.actions button:active:not(:disabled) {
  background: #292929;
}

.actions button:disabled {
  opacity: .3;
  cursor: default;
}

.actions button.danger {
  color: var(--red);
  border-color: rgba(204,51,51,.25);
}

.actions button.danger:hover:not(:disabled) {
  background: rgba(204,51,51,.08);
  border-color: var(--red);
}

/* ---------- controls row (mic / cam) ---------- */

.controls-row {
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}

.ctrl-btn:disabled {
  opacity: .3;
  cursor: default;
}

.ctrl-btn.active {
  color: var(--green);
  border-color: var(--green);
}

.ctrl-btn.muted {
  color: var(--red);
  border-color: var(--red);
  background: rgba(204,51,51,.08);
}

.ctrl-btn:hover:not(:disabled) {
  background: #222;
}

/* ---------- side panel (chat / members) ---------- */

.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.side-tab {
  flex: 1;
  padding: 8px 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: lowercase;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.side-tab:hover { color: var(--text); }
.side-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.side-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-view.hidden { display: none; }

/* ---------- members list ---------- */

.members-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.members-list::-webkit-scrollbar { width: 4px; }
.members-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  transition: background .15s;
}
.member-row:hover { background: rgba(255,255,255,.03); }

.member-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.member-name {
  flex: 1;
  font-size: 0.8rem;
  font-family: var(--mono);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-name.is-me { color: var(--accent); }

.member-icons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.member-icon {
  display: flex;
  color: var(--text-dim);
}
.member-icon.off { color: var(--red); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  font-size: 0.8rem;
  line-height: 1.4;
  word-break: break-word;
}

.msg-ts {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: #444;
  margin-right: 4px;
}

.msg-name {
  font-weight: 600;
  color: var(--accent);
  margin-right: 6px;
  font-size: 0.75rem;
}
.msg-name.is-me { color: var(--green); }

.msg-text {
  color: var(--text);
}

.msg-file { margin-top: 4px; }

.msg-file a {
  color: var(--accent);
  font-size: 0.75rem;
  text-decoration: none;
  font-family: var(--mono);
}
.msg-file a:hover { text-decoration: underline; }

.msg-file img {
  max-width: 200px;
  max-height: 160px;
  border-radius: 4px;
  margin-top: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.chat-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-dim);
  padding: 4px;
  transition: color .15s;
}
.attach-btn:hover { color: var(--text); }

.chat-input {
  flex: 1;
  padding: 8px 10px;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.chat-input:focus { border-color: #555; }

.chat-send-btn {
  padding: 8px 14px;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s;
}
.chat-send-btn:hover { border-color: #555; }

/* ---------- fullscreen overlay ---------- */

.fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fullscreen-overlay.hidden { display: none; }
.fullscreen-overlay.idle { cursor: none; }

.fullscreen-overlay .fs-name,
.fullscreen-overlay .fs-icons,
.fullscreen-overlay .fs-controls,
.fullscreen-overlay .fs-btn {
  transition: opacity .4s;
}
.fullscreen-overlay.idle .fs-name,
.fullscreen-overlay.idle .fs-icons,
.fullscreen-overlay.idle .fs-controls,
.fullscreen-overlay.idle .fs-btn {
  opacity: 0;
  pointer-events: none;
}

.fullscreen-overlay .tile-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scaleX(-1);
  pointer-events: none;
}
.fullscreen-overlay .tile-video.no-mirror { transform: none; }

.fullscreen-overlay .fs-name {
  position: absolute;
  bottom: 16px;
  left: 60px;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: #fff;
  background: rgba(0,0,0,.5);
  padding: 4px 10px;
  border-radius: 4px;
  z-index: 1;
}

@media (max-width: 768px) {
  .fullscreen-overlay .fs-name {
    bottom: auto;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
  }
}

.fullscreen-overlay .fs-icons {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1;
}

.fs-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: background .15s;
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 1;
}
.fs-btn:hover { background: rgba(255,255,255,.15); }

.fs-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 1;
  background: rgba(0,0,0,.45);
  padding: 10px 16px;
  border-radius: 28px;
}

.fs-ctrl-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.fs-ctrl-btn:hover { background: rgba(255,255,255,.15); }
.fs-ctrl-btn.active {
  color: var(--green);
  border-color: var(--green);
}
.fs-ctrl-btn.muted {
  color: var(--red);
  border-color: var(--red);
  background: rgba(204,51,51,.15);
}

/* expand button on featured tile */
.expand-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  transition: background .15s;
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 2;
}
.expand-btn:hover { background: rgba(255,255,255,.15); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 20px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: var(--mono);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- log ---------- */

.log-panel {
  margin-top: 12px;
}

.log-panel summary {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  text-transform: lowercase;
}

.log-panel pre {
  margin-top: 8px;
  max-height: 160px;
  overflow-y: auto;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.7;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
}

.log-panel pre::-webkit-scrollbar { width: 4px; }
.log-panel pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---------- footer ---------- */

.bottombar {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.7rem;
  color: #333;
  font-family: var(--mono);
}

/* ========== LOBBY PAGE ========== */

.lobby-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.lobby-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #eee;
  margin-bottom: 8px;
}

.lobby-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.lobby-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.lobby-input {
  flex: 1;
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  font-family: var(--mono);
}
.lobby-input:focus { border-color: #555; }

.lobby-btn {
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: opacity .15s;
}
.lobby-btn:hover { opacity: .85; }

.lobby-btn-secondary {
  width: 100%;
  padding: 9px 0;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.lobby-btn-secondary:hover {
  border-color: #555;
  color: var(--text);
}

/* ========== RESPONSIVE ========== */

@media (max-width: 768px) {
  html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .room-main {
    padding: 8px;
    min-height: 0;
    overflow: hidden;
    flex: 1;
  }

  .room-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 200px;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  .center-panel {
    order: 1;
    padding: 10px;
    min-height: 0;
    overflow: hidden;
    gap: 8px;
  }

  .side-panel {
    order: 2;
    min-height: 0;
    overflow: hidden;
  }

  .featured-tile {
    min-height: 0;
    padding: 16px;
    gap: 8px;
  }

  .featured-tile .tile-avatar {
    width: 56px;
    height: 56px;
    font-size: 1.6rem;
  }

  .featured-tile .tile-name {
    font-size: 0.9rem;
  }

  .carousel {
    height: 86px;
    min-height: 86px;
  }

  .carousel .participant-tile {
    flex: 0 0 80px;
    min-width: 80px;
    height: 78px;
    min-height: 78px;
    padding: 6px 4px;
    gap: 3px;
  }

  .carousel .tile-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }

  .carousel .tile-name {
    font-size: 0.6rem;
  }

  .bottom-controls { gap: 10px; }
  .actions button { padding: 8px 16px; font-size: 0.8rem; }

  .participants-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar { padding: 10px 12px; }

  .room-layout { grid-template-rows: 1fr 180px; }

  .lobby-card { padding: 24px 16px; }

  .featured-tile .tile-avatar {
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
  }

  .carousel {
    height: 76px;
    min-height: 76px;
  }

  .carousel .participant-tile {
    flex: 0 0 70px;
    min-width: 70px;
    height: 68px;
    min-height: 68px;
  }

  .participants-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
  }

  .participant-tile { padding: 8px 4px; }
  .tile-avatar { width: 36px; height: 36px; aspect-ratio: 1; font-size: 1rem; }
  .tile-name { font-size: 0.65rem; }
}
