:root {
  --brand: #6a5acd;
  --brand-dark: #2b2689;
  --brand-deep: #3a3470;
  --brand-bright: #4d4dff;
  --accent: #2e9e6b;
  --danger: #c0392b;
  --live: #e0245e;

  --bg: #f6f5fc;
  --surface: #ffffff;
  --surface-2: #eceafb;
  --border: #d6d2f0;
  --text: #1e1b3a;
  --muted: #6b6890;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(43, 38, 137, 0.10);
  --shadow-sm: 0 2px 10px rgba(43, 38, 137, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { color: var(--brand-dark); line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.9rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- nav ---------- */
.topnav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--brand-dark); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-bright) 100%);
  color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 1.15rem;
  box-shadow: var(--shadow-sm);
}
.brand-name { font-size: 1.25rem; letter-spacing: .5px; }
.nav-links { display: flex; align-items: center; gap: 18px; }
.nav-links a { color: var(--brand-deep); font-weight: 600; }

/* ---------- layout ---------- */
.container { max-width: 1000px; margin: 0 auto; padding: 28px 24px 60px; }
.container-narrow { max-width: 620px; margin: 0 auto; padding: 28px 24px 60px; }

/* ---------- flash ---------- */
.flash-wrap { max-width: 1000px; margin: 12px auto 0; padding: 0 24px; }
.flash {
  padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 8px;
  font-weight: 600; border: 1px solid transparent;
}
.flash-success { background: #e4f6ee; color: #1c6e4a; border-color: #b9e6cf; }
.flash-error   { background: #fbe7e4; color: #9a2b1f; border-color: #f0c2bb; }
.flash-warning { background: #fff3da; color: #8a5a00; border-color: #f3dca5; }
.flash-message, .flash-info { background: var(--surface-2); color: var(--brand-deep); border-color: var(--border); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--brand); color: #fff; border: none; cursor: pointer;
  padding: 11px 20px; border-radius: var(--radius-sm); font-weight: 700; font-size: .98rem;
  transition: transform .05s, filter .15s; text-decoration: none;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 14px; font-size: .88rem; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface-2); color: var(--brand-deep); }
.btn-danger { background: var(--danger); }
.btn-accent { background: var(--accent); }
.btn-outline { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; margin: 14px 0 6px; color: var(--brand-deep); }
input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=datetime-local], input[type=number], input[type=url], textarea, select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(106, 90, 205, .18);
}
textarea { min-height: 90px; resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 9px; margin-top: 12px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 160px; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 4px; }

/* ---------- badges / pills ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  background: var(--surface-2); color: var(--brand-deep);
}
.badge-live { background: var(--live); color: #fff; }
.badge-scheduled { background: #e7e9ff; color: var(--brand-dark); }
.badge-draft { background: #ece9f2; color: var(--muted); }
.badge-ended { background: #e3e0ee; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.dot-live { background: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .4px; }

/* ---------- event cards ---------- */
.event-card { display: flex; flex-direction: column; gap: 8px; }
.event-card .meta { color: var(--muted); font-size: .9rem; }
.event-card h3 { margin: 0; }
.event-card .actions { margin-top: auto; display: flex; gap: 8px; padding-top: 10px; flex-wrap: wrap; }

/* ---------- auth ---------- */
.auth-wrap { max-width: 380px; margin: 8vh auto; }
.auth-wrap .card { text-align: center; }
.auth-wrap .brand-mark { width: 54px; height: 54px; font-size: 1.7rem; margin: 0 auto 14px; }

/* ---------- empty state ---------- */
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 2.4rem; }

/* ---------- hero (landing) ---------- */
.hero { text-align: center; padding: 24px 0 8px; }
.hero h1 { font-size: 2.2rem; }
.cover { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 18px; }

/* =========================================================
   STUDIO / VIEWER  (dark, StreamYard-like)
   ========================================================= */
body.studio {
  background: #14122b; color: #e9e7f6;
}
.stage-shell { display: grid; grid-template-columns: 1fr 340px; height: 100vh; }
.stage-main { display: flex; flex-direction: column; min-width: 0; }
.stage-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; background: #1c1940; border-bottom: 1px solid #2c2856;
}
.stage-bar .title { font-weight: 700; color: #fff; }
.stage-video {
  flex: 1; background: #0c0a1d; display: grid; place-items: center; position: relative; overflow: hidden;
}
.stage-video video { width: 100%; height: 100%; object-fit: contain; background: #000; }
#stageCanvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #0c0a1d; z-index: 1; }
.stage-placeholder { text-align: center; color: #8b87b8; padding: 40px; position: relative; z-index: 3; }
.count-badge { position: absolute; top: 14px; right: 14px; background: rgba(0, 0, 0, .55); color: #fff; padding: 6px 13px; border-radius: 999px; font-size: .9rem; font-weight: 700; z-index: 4; }
.stage-controls {
  display: flex; gap: 10px; justify-content: center; padding: 14px; background: #1c1940;
  border-top: 1px solid #2c2856; flex-wrap: wrap;
}
.ctrl {
  background: #2c2856; color: #e9e7f6; border: none; border-radius: 10px; padding: 10px 16px;
  font-weight: 600; cursor: pointer; display: inline-flex; gap: 8px; align-items: center;
}
.ctrl:hover { background: #38337a; }
.ctrl.active { background: var(--brand); color: #fff; }
.ctrl.danger { background: var(--live); color: #fff; }

/* side panel: chat */
.side {
  background: #1a1738; border-left: 1px solid #2c2856; display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 12px 16px; border-bottom: 1px solid #2c2856; display: flex; justify-content: space-between; align-items: center; }
.viewers { font-size: .85rem; color: #b6b2e0; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 9px; }
.msg { font-size: .92rem; }
.msg .who { font-weight: 700; color: #b6b2e0; margin-right: 6px; }
.msg.host .who { color: #b3a8ff; }
.msg.host { background: #251f55; border-radius: 8px; padding: 6px 9px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #2c2856; }
.chat-input input { background: #0f0d24; border-color: #2c2856; color: #fff; }
.reactions-bar { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid #2c2856; flex-wrap: wrap; }
.reaction-btn { background: #2c2856; border: none; border-radius: 8px; font-size: 1.1rem; padding: 6px 10px; cursor: pointer; }
.reaction-btn:hover { background: #38337a; }
.sound-overlay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--brand); color: #fff; border: none; border-radius: 999px;
  padding: 14px 28px; font-size: 1.05rem; font-weight: 800; cursor: pointer;
  box-shadow: 0 10px 36px rgba(0, 0, 0, .45); z-index: 5;
}
.sound-overlay:hover { filter: brightness(1.08); }
.settings-panel { display: flex; gap: 16px; justify-content: center; padding: 10px 14px; background: #16143a; border-top: 1px solid #2c2856; flex-wrap: wrap; }
.settings-panel label { color: #b6b2e0; font-size: .78rem; margin: 0 0 4px; display: block; }
.settings-panel select { background: #0f0d24; color: #fff; border: 1px solid #2c2856; border-radius: 8px; padding: 7px 10px; min-width: 210px; }
.kicked-overlay { position: absolute; inset: 0; background: rgba(10, 8, 26, .96); display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; z-index: 10; }
.float-emoji { position: absolute; bottom: 60px; font-size: 2rem; animation: floatup 2.6s ease-out forwards; pointer-events: none; }
@keyframes floatup { 0% { transform: translateY(0); opacity: 1 } 100% { transform: translateY(-260px); opacity: 0 } }

@media (max-width: 820px) {
  .stage-shell { grid-template-columns: 1fr; grid-template-rows: 1fr 300px; }
  .side { border-left: none; border-top: 1px solid #2c2856; }
}
