:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2230;
  --border: #2a2f3d;
  --text: #e8e9ee;
  --text-dim: #9aa0ae;
  --accent: #6c8bff;
  --accent-2: #4f6be0;
  --danger: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
  transition: background .15s, opacity .15s;
}
button:hover { background: var(--accent-2); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.secondary { background: var(--panel-2); color: var(--text); }
button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }

input[type="text"], input[type="url"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}
input:focus { outline: 1px solid var(--accent); }

/* ---------- Landing page ---------- */
.landing {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.landing-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.landing-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.landing-card p.sub {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 13px;
}
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.tabs button {
  flex: 1;
  background: var(--panel-2);
  color: var(--text-dim);
}
.tabs button.active {
  background: var(--accent);
  color: #fff;
}
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.panel-view { display: none; }
.panel-view.active { display: block; }
.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 16px;
  line-height: 1.6;
}
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

/* ---------- Room page ---------- */
.room-wrap {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: auto 1fr;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.room-code {
  font-weight: 700;
  letter-spacing: 2px;
  background: var(--panel-2);
  padding: 6px 10px;
  border-radius: 8px;
}
.badge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-dim);
}
.badge.host { background: var(--accent); color: #fff; }
.users-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
  align-items: center;
}
.user-chip {
  font-size: 12px;
  background: var(--panel-2);
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--text-dim);
}
.user-chip.host { color: var(--accent); }

.main-area {
  display: flex;
  flex-direction: column;
  background: #000;
  min-width: 0;
}
.video-box {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.video-box video, .video-box iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
}
.video-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
  max-width: 420px;
}
.video-empty h3 { color: var(--text); margin-bottom: 8px; }
.viewer-lock-note {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0,0,0,.55);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
}
.activate-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  cursor: pointer;
}
.activate-overlay button {
  font-size: 15px;
  padding: 14px 24px;
  pointer-events: none;
}
.generic-warning {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 170, 0, .12);
  border-top: 1px solid rgba(255,170,0,.4);
  color: #ffcf7a;
  font-size: 12px;
  padding: 6px 10px;
  text-align: center;
}

.host-controls {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}
.source-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.source-row input { flex: 1; }
.playback-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.playback-row input[type="range"] { flex: 1; }
.time-label { font-size: 12px; color: var(--text-dim); min-width: 90px; text-align: center; }

.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg .who {
  font-weight: 600;
  margin-right: 6px;
}
.chat-msg.mine .who { color: var(--accent); }
.chat-msg.host-msg .who { color: #ffd479; }
.chat-msg.system {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 10px;
  position: relative;
}
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input-row input { flex: 1; }
.emoji-btn {
  background: var(--panel-2);
  padding: 10px 12px;
}
.emoji-picker {
  position: absolute;
  bottom: 56px;
  right: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: none;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  width: 280px;
  max-height: 180px;
  overflow-y: auto;
}
.emoji-picker.open { display: grid; }
.emoji-picker span {
  cursor: pointer;
  text-align: center;
  padding: 4px;
  font-size: 18px;
  border-radius: 6px;
}
.emoji-picker span:hover { background: var(--border); }

@media (max-width: 860px) {
  .room-wrap { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .chat-panel { border-left: none; border-top: 1px solid var(--border); height: 260px; }
}
