:root {
  --bg: #0e0d12;
  --panel: #16151c;
  --panel-2: #1e1c26;
  --line: #2a2833;
  --text: #f3f1f6;
  --muted: #9a96a6;
  --accent: #ffc24b;
  --accent-ink: #2b1d00;
  --danger: #ff6b7a;
  --ok: #4ade80;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.center { text-align: center; }
.center-img { display: block; margin: 0 auto; }
.small-text { font-size: 13px; margin: 0; }
.tiny { font-size: 12.5px; }
.error { min-height: 18px; color: var(--danger); font-size: 14px; }
.icon { width: 20px; height: 20px; flex: none; }

/* Buttons & inputs */
button, .primary, .ghost {
  font: inherit;
  cursor: pointer;
  border: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:disabled { opacity: .5; cursor: default; }
.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  border-radius: 12px;
  padding: 0 18px;
  height: 44px;
}
.primary:hover { filter: brightness(1.06); }
.primary.big { height: 52px; font-size: 16px; }
.ghost {
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0 12px;
  height: 36px;
  border: 1px solid var(--line);
}
.ghost:hover { border-color: #3b3846; }
.small { height: 34px; font-size: 13.5px; padding: 0 12px; }
.small .icon { width: 16px; height: 16px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); }
.icon-btn.danger { color: var(--danger); }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  height: 46px;
  padding: 0 14px;
  min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Toasts */
.toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 50; pointer-events: none; width: min(92vw, 460px);
}
.toast {
  background: #2a2733; color: var(--text); border: 1px solid #3a3645;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  animation: toast-in .2s ease-out;
  transition: opacity .35s, transform .35s;
}
.toast.error { border-color: #6a2b35; }
.toast.alert { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Home */
.page-home { background: radial-gradient(circle at 20% -10%, #2c2210 0, var(--bg) 50%) fixed; }
.home { width: min(680px, 100%); margin: 0 auto; padding: 28px 16px 60px; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand h1 { font-size: 26px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.brand #logout { margin-left: auto; }
#login { max-width: 380px; margin: 40px auto 0; text-align: center; }
#login h2 { margin-bottom: 8px; }
#login p { margin: 0 0 18px; font-size: 14px; }
.pin { height: 58px; font-size: 26px; letter-spacing: .5em; text-align: center; padding-left: .5em; }
.create { display: flex; gap: 10px; margin-bottom: 8px; }
.create input { flex: 1; }
.rooms { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 10px; }
.room-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 14px 18px;
}
.room-main { flex: 1; min-width: 0; display: flex; flex-direction: column; color: var(--text); text-decoration: none; }
.room-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-main .muted { font-size: 13px; }
.live { color: var(--ok); }
.room-actions { display: flex; align-items: center; gap: 6px; }
.room-actions .primary { height: 34px; font-size: 13.5px; }
@media (max-width: 560px) {
  .room-item { flex-wrap: wrap; }
  .room-actions { width: 100%; }
  .room-actions .ghost { flex: 1; }
  .create { flex-direction: column; }
}

/* Join */
.page-room { overflow: hidden; }
.join {
  min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% -20%, #2c2210 0, var(--bg) 60%);
}
.join .card { width: min(400px, 100%); }
.join h1 { font-size: 24px; margin-bottom: 4px; overflow-wrap: anywhere; }

/* Room layout */
.room {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top side" "stage side" "controls side";
}
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  min-width: 0;
}
.top-icon { display: flex; }
.topbar h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { font-size: 13px; color: var(--accent); white-space: nowrap; }
#invite { margin-left: auto; flex: none; }

.stage {
  grid-area: stage;
  position: relative;
  margin: 0 16px;
  border-radius: 18px;
  background: #000;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 0;
}
.stage video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.stage:fullscreen { margin: 0; border-radius: 0; }
.stage-empty {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 50% 30%, #1f1b28 0, #0b0a0f 70%);
  text-align: center;
}
.stage-empty-inner { max-width: 430px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stage-empty h2 { font-size: 20px; }
.stage-empty p { margin: 0; }
.stage-label {
  position: absolute; top: 12px; left: 12px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  padding: 5px 11px; border-radius: 999px; font-size: 13px;
  pointer-events: none;
  transition: opacity .3s;
}
.stage-label.faded { opacity: 0; }
.stage:hover .stage-label.faded { opacity: 1; }
.stage-btn { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.45); }
.stage-btn:hover { background: rgba(0,0,0,.7); }
.stage:fullscreen .stage-label, .stage:fullscreen .stage-btn { opacity: 0; }
.stage:fullscreen:hover .stage-label, .stage:fullscreen:hover .stage-btn { opacity: 1; }
.stage-toasts {
  position: absolute; left: 14px; bottom: 14px; z-index: 5;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  max-width: min(70%, 460px); pointer-events: none;
}
.stage-toasts .toast { text-align: left; background: rgba(20,18,26,.85); backdrop-filter: blur(6px); }
.stage-toasts .toast.alert { background: var(--accent); }
.tap-audio { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); z-index: 6; }

/* Controls */
.controls {
  grid-area: controls;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 8px; padding: 12px 16px;
}
.ctrl {
  height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  font-size: 14px; font-weight: 600;
}
.ctrl:hover { border-color: #403c4c; }
.ctrl .l-short { display: none; }
.ctrl.off { color: var(--danger); }
.ctrl.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.ctrl.danger { color: var(--danger); }
.share-group { display: inline-flex; }
.share-group .ctrl { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.share-group select {
  height: 44px; border-radius: 0 12px 12px 0; border-left: 0; padding: 0 8px; font-size: 13px;
  background: var(--panel-2); color: var(--muted);
}
.vol-wrap { position: relative; }
.vol-pop {
  position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; width: 240px; display: flex; flex-direction: column; gap: 12px; z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.vol-pop label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.vol-pop input { height: auto; padding: 0; border: 0; background: none; accent-color: var(--accent); }

/* Side: people + chat */
.side {
  grid-area: side;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
.people {
  list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 4px;
  border-bottom: 1px solid var(--line); max-height: 34%; overflow-y: auto; flex: none;
}
.people li { display: flex; align-items: center; gap: 10px; padding: 5px 6px; border-radius: 10px; min-width: 0; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  background: hsl(var(--h) 45% 30%); color: hsl(var(--h) 90% 88%);
  box-shadow: 0 0 0 2px transparent; transition: box-shadow .15s;
}
.people li.speaking .avatar { box-shadow: 0 0 0 2px var(--ok), 0 0 12px rgba(74,222,128,.45); }
.person-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.badge { color: var(--accent); display: flex; }
.badge .icon, .mic-state .icon { width: 17px; height: 17px; }
.mic-state { display: flex; color: var(--muted); }
.mic-state.off { color: var(--danger); opacity: .8; }

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages {
  list-style: none; margin: 0; padding: 12px 12px 4px; flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.messages > :first-child { margin-top: auto; }
.msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 8px; max-width: 100%; }
.msg.grouped { margin-top: 2px; }
.msg.mine { align-items: flex-end; }
.meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; margin: 0 4px 3px; }
.who { font-weight: 700; }
.meta time { color: var(--muted); }
.bubble {
  background: var(--panel-2); padding: 7px 12px; border-radius: 14px; max-width: 92%;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.mine .bubble { background: #3a2f12; }
.msg.system { align-items: center; color: var(--muted); font-size: 12.5px; margin: 6px 0; text-align: center; }
.msg.system.pause { color: var(--accent); font-weight: 600; }
.voice { display: flex; align-items: center; gap: 10px; width: 240px; max-width: 100%; padding: 6px 12px 6px 6px; }
.vp-play {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); flex: none;
}
.vp-play .icon { width: 16px; height: 16px; }
.vp-bar { flex: 1; height: 6px; border-radius: 3px; background: #3a3746; cursor: pointer; position: relative; }
.vp-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); border-radius: 3px; }
.vp-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

.composer {
  display: flex; align-items: center; gap: 6px; padding: 10px;
  border-top: 1px solid var(--line);
}
.composer input { flex: 1; height: 42px; border-radius: 21px; }
.composer .icon-btn { width: 42px; height: 42px; border-radius: 50%; flex: none; }
#rec.recording { background: var(--danger); color: #fff; }
.recorder { flex: 1; display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 12px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* Overlay */
.overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(8,7,11,.8); backdrop-filter: blur(6px);
}
.overlay .card { width: min(380px, 100%); }
.overlay p { margin: 0; }

/* Phones & small tablets */
@media (max-width: 900px) {
  .room {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "top" "stage" "controls" "side";
  }
  .topbar { padding: 8px 12px; }
  .stage { margin: 0; border-radius: 0; aspect-ratio: 16 / 9; max-height: 45dvh; width: 100%; }
  .stage-empty h2 { font-size: 16px; }
  .stage-empty .tiny { display: none; }
  .controls { gap: 6px; padding: 8px; flex-wrap: nowrap; justify-content: space-between; }
  .ctrl { padding: 0 4px; flex: 1; min-width: 0; height: 54px; flex-direction: column; gap: 2px; font-size: 11px; font-weight: 500; }
  .ctrl span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .ctrl .l-long { display: none; }
  .ctrl .l-short { display: block; }
  .stage-empty { padding: 12px; }
  .stage-empty-inner { gap: 8px; }
  .stage-empty p { font-size: 13px; }
  .stage-empty-inner:has(#share-cta:not([hidden])) #stage-hint { display: none; }
  #share-cta { height: 38px; font-size: 14px; }
  .share-group, .vol-wrap { flex: 1; display: flex; }
  .share-group .ctrl, .vol-wrap .ctrl { flex: 1; }
  .share-group select { display: none; }
  .share-group .ctrl { border-radius: 12px; }
  .vol-pop { left: auto; right: -40px; transform: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .people { flex-direction: row; overflow-x: auto; max-height: none; padding: 8px 10px; gap: 6px; }
  .people li { flex: none; background: var(--panel-2); padding: 4px 10px 4px 4px; border-radius: 999px; }
  .people .avatar { width: 26px; height: 26px; font-size: 11px; }
  .person-name { font-size: 13px; max-width: 120px; }
  .composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
}
