:root {
    /* Paleta Campfire */
    --carvao: #141110;
    --chama: #FF6A13;
    --ambar: #FFB020;
    --brasa: #E8441A;
    --cinza-claro: #F4EEE6;

    --bg: var(--carvao);
    --bg-2: #1e1916;
    --bg-3: #241e1a;
    --bg-4: #312822;
    --bg-hover: #3e332b;
    --border: #00000066;
    --text: var(--cinza-claro);
    --muted: #b3a597;
    --accent: var(--chama);
    --accent-hover: #ff8236;
    --on-accent: var(--carvao);
    --danger: var(--brasa);
    --danger-hover: #c7350f;
    --error-text: #ff8a66;
    --radius: 10px;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0 0 16px; }
.error { color: var(--error-text); min-height: 1.2em; margin: 12px 0 0; }
.row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Botoes e campos ---------- */
.btn {
    border: 0;
    border-radius: 6px;
    padding: 11px 18px;
    font: inherit;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-4); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.input {
    width: 100%;
    padding: 11px 12px;
    margin-bottom: 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    outline: none;
}
.input:focus { border-color: var(--accent); }

.check { display: flex; align-items: flex-start; gap: 10px; margin: -2px 0 16px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; flex: none; }
.check small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: none;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 16px;
}
.icon-btn:hover { background: var(--bg-4); color: var(--text); }

.card {
    background: var(--bg-2);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.card h2 { margin: 0 0 6px; }
.card-narrow { width: min(420px, 92vw); }

.logo { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 34px; color: var(--text); text-decoration: none; }
.logo-small { font-size: 18px; gap: 8px; margin-bottom: 0; }
.card .logo-small { margin-bottom: 18px; }

/* ---------- Pagina inicial ---------- */
.home-wrap {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    background: radial-gradient(circle at 20% 10%, #ff6a1326 0%, transparent 45%),
                radial-gradient(circle at 85% 90%, #e8441a2e 0%, transparent 40%);
}
.home-header { text-align: center; margin-bottom: 36px; }
.home-header .logo { justify-content: center; }
.tagline { color: var(--muted); font-size: 17px; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; width: min(760px, 100%); }
.home-cards .card { display: flex; flex-direction: column; }
.home-cards .card .muted { flex: 1; }

.room-list-section { width: min(760px, 100%); margin-top: 16px; }
.section-title { font-size: 18px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.section-count {
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--bg-4);
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.section-count:empty { display: none; }
.section-count.full { background: rgba(232, 68, 26, .2); color: var(--error-text); }
.limit-hint { color: var(--error-text); font-size: 13px; margin: 10px 0 0; }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.room-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--bg-2);
    border: 1px solid transparent;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
a.room-item:hover { border-color: var(--accent); background: var(--bg-3); }
.room-item.full { cursor: default; opacity: .7; }
.room-lock { margin-right: 6px; font-size: 14px; }
.room-info { flex: 1; min-width: 0; }
.room-name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-people { color: var(--muted); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-count {
    flex: none;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bg-4);
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.room-count.live { background: rgba(255, 106, 19, .18); color: var(--ambar); }
.room-item .btn { flex: none; min-width: 84px; }
.room-list-empty { color: var(--muted); text-align: center; padding: 18px; border: 1px dashed var(--bg-hover); border-radius: var(--radius); margin: 0; }

/* ---------- Overlays ---------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .7);
    backdrop-filter: blur(4px);
}

/* ---------- Sala ---------- */
.app { display: flex; flex-direction: column; height: 100%; }

/* Tres colunas: as laterais dividem o espaco igualmente, entao os controles ficam no centro exato da janela */
.topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-right { justify-content: flex-end; gap: 8px; }
.topbar-sep { width: 1px; height: 24px; margin: 0 4px; background: var(--bg-hover); flex: none; }
.invite { display: flex; align-items: center; gap: 8px; min-width: 0; }
.invite .btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.invite .btn svg { width: 18px; height: 18px; flex: none; }
/* fora da tela, mas ainda selecionavel para a copia de reserva (execCommand) */
.invite-link { position: absolute; left: -9999px; width: 1px; opacity: 0; }
.invite-host {
    background: var(--bg);
    color: var(--text);
    border: 0;
    border-radius: 6px;
    padding: 7px 10px;
    font: inherit;
    font-size: 13px;
    min-width: 0;
    max-width: 160px;
}
.room-title {
    min-width: 0;
    padding-left: 14px;
    border-left: 1px solid var(--bg-hover);
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* contador compacto: icone + numero, o texto completo fica no tooltip */
.people-count { display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; color: var(--muted); font-size: 14px; cursor: default; }
.people-count svg { width: 20px; height: 20px; }

.body { flex: 1; display: flex; min-height: 0; }

.stage {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 8px;
    overflow: hidden;
}
/* Cameras e telas compartilhadas na mesma grade: o tamanho dos quadros e calculado no JS (--tile-w) para preencher o espaco livre */
.grid {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 12px;
    overflow: hidden;
}
.grid .tile { flex: none; width: var(--tile-w, 320px); }

/* Destaque: um quadro ocupa a area central e os demais viram uma coluna a direita */
.spotlight { display: none; }
.stage.spotlighting { flex-direction: row; gap: 8px; }
.stage.spotlighting .spotlight { display: flex; flex: 1; min-width: 0; min-height: 0; }
.spotlight .tile { width: 100%; height: 100%; aspect-ratio: auto; }
.spotlight .tile video { object-fit: contain; }
.stage.spotlighting .grid {
    flex: 0 0 220px;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-content: stretch;
    gap: 8px;
    overflow-y: auto;
}
.stage.spotlighting .grid:empty { display: none; }
.tile-tools .spotlight-btn.active { background: var(--accent); color: var(--on-accent); }

.tile {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--bg-2);
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid transparent;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.screen { background: #000; }
.tile.screen video { object-fit: contain; }
.tile.self video.mirror { transform: scaleX(-1); }

.tile .avatar {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-2);
}
.tile .avatar span {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 700;
    color: var(--carvao);
}
.tile.has-video .avatar { display: none; }

/* nome no topo: a parte de baixo fica livre para a barra de controles flutuante */
.tile .label {
    position: absolute;
    left: 8px;
    top: 8px;
    max-width: calc(100% - 56px);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, .6);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile .mic-off { display: none; color: var(--error-text); }
.tile.mic-muted .mic-off { display: inline; }
.tile .status { color: var(--muted); font-size: 12px; }

/* Volume e tela cheia: canto superior direito, aparecem ao passar o mouse no quadro */
.tile-tools {
    position: absolute;
    right: 8px;
    top: 8px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px;
    border-radius: 8px;
    background: rgba(20, 17, 16, .75);
    opacity: 0;
    transition: opacity .15s;
}
.tile:hover .tile-tools, .tile-tools:focus-within { opacity: 1; }
.tile-tools .icon-btn { width: 30px; height: 30px; color: var(--text); font-size: 15px; }
.tile-tools .icon-btn:hover { background: var(--bg-hover); }

.volume { display: flex; align-items: center; gap: 2px; padding-right: 6px; }
/* acima de 100% o trilho muda de cor para indicar que o som esta sendo amplificado */
.volume.boosted { --accent: var(--ambar); }
.volume input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 90px;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--accent) var(--fill, 100%), var(--bg-hover) var(--fill, 100%));
    cursor: pointer;
}
.volume input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--cinza-claro);
    border: 2px solid var(--accent);
}
.volume input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--cinza-claro);
    border: 2px solid var(--accent);
}

/* ---------- Chat ---------- */
.chat {
    width: 340px;
    flex: none;
    display: flex;
    flex-direction: column;
    background: var(--bg-3);
    border-left: 1px solid var(--border);
    position: relative;
}
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 8px 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
}
.messages { flex: 1; overflow-y: auto; padding: 12px 0; }

.msg { padding: 2px 16px; }
.msg:hover { background: var(--bg-2); }
.msg.first { margin-top: 12px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 600; }
.msg-time { color: var(--muted); font-size: 11px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.4; }
.msg-text a { color: var(--ambar); }
.msg-image-gone { color: var(--muted); font-size: 13px; font-style: italic; }
.msg-image {
    display: block;
    max-width: 100%;
    max-height: 260px;
    margin: 4px 0;
    border-radius: 8px;
    cursor: zoom-in;
}
.msg-system { color: var(--muted); font-size: 13px; text-align: center; padding: 6px 16px; }

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    margin: 12px;
    padding: 4px;
    background: var(--bg-4);
    border-radius: 8px;
}
.chat-form textarea {
    flex: 1;
    resize: none;
    max-height: 140px;
    padding: 8px 4px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1.35;
}
.drop-hint {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 106, 19, .88);
    font-weight: 700;
    font-size: 18px;
    color: var(--on-accent);
    pointer-events: none;
}

/* ---------- Controles ---------- */
/* Botoes quadrados so com icone, na barra superior; o nome aparece no tooltip (title) */
.controls { display: flex; align-items: center; gap: 6px; }
.ctrl {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: var(--bg-4);
    color: var(--text);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.ctrl svg { width: 22px; height: 22px; }
.ctrl:hover { background: var(--bg-hover); }
.ctrl .on { display: none; }
.ctrl.active .on { display: block; }
.ctrl.active .off { display: none; }
.ctrl.active { background: rgba(255, 106, 19, .22); color: var(--accent); }
.ctrl.active:hover { background: var(--accent); color: var(--on-accent); }
#btn-mic:not(.active), #btn-cam:not(.active) { background: rgba(232, 68, 26, .18); color: var(--error-text); }
#btn-mic:not(.active):hover, #btn-cam:not(.active):hover { background: rgba(232, 68, 26, .32); }
#btn-output select {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
    cursor: pointer;
    /* cores da lista que abre */
    background: var(--bg-3);
    color: var(--text);
    font: inherit;
}
.ctrl-danger { background: var(--danger); color: var(--text); }
.ctrl-danger:hover { background: var(--danger-hover); }
.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    padding: 1px 5px;
    border-radius: 9px;
    background: var(--danger);
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
}

/* ---------- Lightbox e toasts ---------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .85);
    cursor: zoom-out;
}
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 6px; }

.toasts {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}
.toast {
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--bg-4);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
    animation: toast-in .2s ease-out;
}
.toast.error-toast { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Anexos do chat (antes de enviar) ---------- */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 12px -4px; padding-top: 8px; }
.attachment { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    background: rgba(20, 17, 16, .85);
    color: var(--text);
    font-size: 11px;
    cursor: pointer;
}
.attachment-remove:hover { background: var(--danger); }
.icon-send:disabled { opacity: .5; cursor: default; }

/* ---------- Previas de mensagens novas (chat fechado) ---------- */
.chat-previews {
    position: fixed;
    right: 16px;
    top: 64px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(320px, calc(100vw - 32px));
}
.chat-preview {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border: 1px solid var(--bg-hover);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    background: var(--bg-2);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .45);
    animation: preview-in .2s ease-out;
}
.chat-preview:hover { background: var(--bg-3); }
.chat-preview-author { font-weight: 700; font-size: 13px; }
.chat-preview-text {
    font-size: 14px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}
@keyframes preview-in { from { opacity: 0; transform: translateX(16px); } }

/* ---------- Telas pequenas ---------- */
@media (max-width: 860px) {
    .chat { position: absolute; right: 0; top: 0; bottom: 0; width: min(360px, 100%); z-index: 20; }
    .body { position: relative; }
    .topbar { gap: 8px; padding: 8px 10px; }
    .logo-small span, .invite .btn span { display: none; }
    .invite .btn { padding: 6px 8px; }
    .room-title { padding-left: 0; border-left: 0; }
    /* destaque em tela estreita: faixa dos demais quadros embaixo, rolando na horizontal */
    .stage.spotlighting { flex-direction: column; }
    .stage.spotlighting .grid { flex: 0 0 96px; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
}
