/* Hänget – kvällsblått vardagsrum med en tänd lampa */

:root {
  --bg: #1d2230;
  --stage: #151925;
  --panel: #232938;
  --panel-2: #2c3345;
  --panel-3: #363e53;
  --line: #353d52;
  --text: #ece7db;
  --muted: #9ba2b3;
  --faint: #6f7790;
  --lamp: #f2b84b;
  --lamp-ink: #2a1f08;
  --lamp-glow: rgba(242, 184, 75, 0.35);
  --live: #ef5b5b;
  --ok: #59c08f;
  --warn: #f0a04b;

  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Figtree', 'Segoe UI', system-ui, sans-serif;

  --r-s: 8px;
  --r-m: 12px;
  --r-l: 18px;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--lamp); }
h1, h2 { font-family: var(--font-display); margin: 0; }

:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

.ico {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}
.ico.s { width: 16px; height: 16px; }

/* ---------- Knappar och fält ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: var(--r-m);
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--lamp); color: var(--lamp-ink); border-color: var(--lamp); }
.btn.primary:hover { background: #f6c869; }
.btn.big { padding: 13px 18px; font-size: 16px; width: 100%; }
.btn.small { padding: 6px 12px; font-size: 14px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: var(--r-s);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn.off { color: var(--live); }
.icon-btn.s { width: 30px; height: 30px; }

.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
input:not([type]), input[type=password], input[type=text], select, textarea {
  width: 100%;
  background: var(--stage);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  padding: 10px 12px;
}
input:not([type]):focus, input[type=password]:focus, select:focus, textarea:focus { border-color: var(--lamp); outline: none; }
input[type=range] { accent-color: var(--lamp); width: 100%; }
input[type=checkbox], input[type=radio] { accent-color: var(--lamp); }

.check { display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; }

fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-size: 13px; color: var(--muted); font-weight: 500; padding: 0; margin-bottom: 8px; }
.hint { font-size: 13px; color: var(--faint); margin: 6px 0 0; }

/* ---------- Inloggning ---------- */

.join {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(60vmax 50vmax at 50% -10%, rgba(242, 184, 75, .10), transparent 60%),
    var(--bg);
}
.join-card { width: min(380px, 100%); text-align: center; }
.join-rejoin { display: none; }
[data-rejoin] .join-rejoin { display: block; }
[data-rejoin] #join-online, [data-rejoin] #join-form, [data-rejoin] #join-note { display: none; }
.lamp {
  width: 64px; height: 64px; margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #ffe2a3 0 22%, var(--lamp) 40%, rgba(242,184,75,0) 72%);
  box-shadow: 0 0 60px 18px var(--lamp-glow);
  animation: lamp-on 1.4s ease-out both;
}
@keyframes lamp-on {
  0% { opacity: 0; transform: scale(.6); }
  35% { opacity: .9; }
  45% { opacity: .35; }
  60%, 100% { opacity: 1; transform: none; }
}
.join h1 { font-size: 44px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; }
.join-sub { color: var(--muted); margin: 6px 0 28px; }
.join form { text-align: left; }
.join-error { color: var(--live); min-height: 1.5em; margin: 10px 0 0; font-size: 14px; }
.join-note { color: var(--faint); font-size: 13px; margin-top: 18px; }

/* ---------- Layout ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 320px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "banner banner banner"
    "people stage chat";
}
.banners { grid-area: banner; }
.banner {
  background: var(--warn); color: #2b1a05;
  padding: 8px 16px; font-weight: 600; text-align: center;
}
.audio-unlock { display: block; width: 100%; border: 0; font: inherit; font-weight: 700; cursor: pointer; }
.audio-unlock[hidden] { display: none; }
.panel { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.people { grid-area: people; border-right: 1px solid var(--line); }
.stage { grid-area: stage; background: var(--stage); min-width: 0; min-height: 0; position: relative; display: flex; }
.chat { grid-area: chat; border-left: 1px solid var(--line); }
.tabbar { display: none; }

/* ---------- Deltagare ---------- */

.room-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 18px 18px 12px;
}
.room-head h2 { font-size: 22px; font-weight: 750; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.members { list-style: none; margin: 0; padding: 4px 10px; overflow-y: auto; flex: 1; }
.member {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px; border-radius: var(--r-m);
  cursor: pointer;
}
.member.self { cursor: default; }
.member:not(.self):hover { background: var(--panel-2); }
.m-text { flex: 1; min-width: 0; display: grid; }
.m-name { font-family: var(--font-display); font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.you { color: var(--faint); font-family: var(--font-body); font-weight: 400; font-size: 13px; }
.m-sub { font-size: 12px; color: var(--warn); }
.conn-connecting .m-sub, .conn-new .m-sub { color: var(--muted); }
.conn-failed .m-sub { color: var(--live); }
.m-icons { display: flex; align-items: center; gap: 6px; color: var(--live); }
.vol-tag { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.avatar {
  --c: #5b8def;
  flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c);
  color: #fff;
  font-family: var(--font-display); font-weight: 700; font-size: 14px;
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 2px transparent;
  transition: box-shadow .12s ease-out;
}
.avatar.small { width: 30px; height: 30px; font-size: 12px; }

/* Lampan tänds runt den som pratar */
.member.speaking .avatar {
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--lamp), 0 0 22px 6px var(--lamp-glow);
}

.tag {
  font-size: 11.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  white-space: nowrap;
}
.tag.live { background: var(--live); color: #fff; }

/* Min panel längst ner */
.me-dock { padding: 12px; border-top: 1px solid var(--line); background: #20263300; display: grid; gap: 10px; }
.share-btn { width: 100%; background: var(--panel-2); }
.share-btn .ico { color: var(--lamp); }
.share-btn.live { background: var(--live); border-color: var(--live); color: #fff; }
.share-btn.live .ico { color: #fff; }
.me-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.me-id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-btns { display: flex; }

/* ---------- Scenen ---------- */

.stage-empty {
  margin: auto; max-width: 380px; padding: 24px; text-align: center;
}
.stage-empty-title { font-family: var(--font-display); font-size: 24px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.01em; }
.stage-empty-text { color: var(--muted); margin: 0; }

.tiles {
  flex: 1; min-height: 0;
  display: grid; gap: 10px; padding: 10px;
  grid-template-columns: 1fr;
  grid-auto-rows: minmax(0, 1fr);
}
.tiles:empty { display: none; }

.tiles:not(.has-focus) { place-items: center; place-content: center; }
.tiles:not(.has-focus) .tile { width: var(--tw, 100%); height: var(--th, 100%); }

.tiles.has-focus {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-template-rows: minmax(0, 1fr) 120px;
  grid-auto-rows: 120px;
}
.tiles.has-focus .tile.focused { grid-column: 1 / -1; order: -1; }

.tile {
  position: relative; min-height: 0;
  background: #0d1018;
  border-radius: var(--r-m);
  overflow: hidden;
  cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #0d1018; }
.tile:fullscreen { border-radius: 0; cursor: default; }
.tile-wait {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 14px;
}
.tile.has-video .tile-wait { display: none; }

.tile-top, .tile-bottom {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
  transition: opacity .2s;
}
.tile-top { top: 0; background: linear-gradient(rgba(10,12,18,.7), transparent); }
.tile-bottom { bottom: 0; justify-content: space-between; background: linear-gradient(transparent, rgba(10,12,18,.8)); }
.tile-name { font-family: var(--font-display); font-weight: 650; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.tile-stats { font-size: 12px; color: #c9cdd8; font-variant-numeric: tabular-nums; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.tile.limited .tile-stats { color: var(--warn); }
.tile-ctrls { display: flex; align-items: center; gap: 4px; pointer-events: auto; }
.tile-ctrls .icon-btn { color: #dfe2ea; }
.tile-vol { display: flex; align-items: center; gap: 6px; color: #dfe2ea; }
.tile-vol input { width: 90px; }

/* Visa kontroller bara när man hovrar (på enheter med mus) */
@media (hover: hover) {
  .tile:not(:hover) .tile-bottom .tile-ctrls { opacity: 0; }
  .tile:fullscreen:not(:hover) .tile-top, .tile:fullscreen:not(:hover) .tile-bottom { opacity: 0; }
}
.tiles.has-focus .tile:not(.focused) .tile-bottom { display: none; }
.tiles.has-focus .tile:not(.focused) .tile-top { padding: 6px 8px; }
.tiles.has-focus .tile:not(.focused) .tag { display: none; }

/* ---------- Chatt ---------- */

.chat-head { padding: 18px 18px 8px; }
.chat-head h2 { font-size: 18px; font-weight: 700; }
.messages { list-style: none; margin: 0; padding: 8px 16px 12px; overflow-y: auto; flex: 1; }
.msg { margin-top: 12px; }
.msg.grouped { margin-top: 2px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-name { font-family: var(--font-display); font-weight: 650; color: color-mix(in srgb, var(--c) 55%, white); }
.msg-head time { font-size: 12px; color: var(--faint); }
.msg-text { margin: 1px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.system { color: var(--faint); font-size: 13px; margin-top: 10px; white-space: pre; }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  margin: 0 12px 12px; padding: 6px 6px 6px 12px;
  background: var(--stage); border: 1px solid var(--line); border-radius: var(--r-m);
}
.composer:focus-within { border-color: var(--lamp); }
.composer textarea {
  border: 0; background: transparent; padding: 7px 0; resize: none;
  max-height: 160px; line-height: 1.4;
}
.composer textarea:focus { outline: none; }
.composer .send { color: var(--lamp); }

/* ---------- Dialoger ---------- */

.dialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.dialog::backdrop { background: rgba(8, 10, 16, .6); backdrop-filter: blur(2px); }
.dialog h2 { font-size: 22px; font-weight: 750; margin-bottom: 18px; letter-spacing: -0.01em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.preset-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.preset {
  position: relative;
  display: grid; gap: 2px; text-align: center;
  padding: 10px 6px;
  border: 1px solid var(--line); border-radius: var(--r-m);
  background: var(--stage);
  cursor: pointer;
}
.preset input { position: absolute; opacity: 0; pointer-events: none; }
.preset-res { font-family: var(--font-display); font-weight: 700; font-size: 15px; line-height: 1.15; }
.preset-fps { font-size: 12px; color: var(--muted); }
.preset:has(input:checked) { border-color: var(--lamp); background: rgba(242,184,75,.09); }
.preset:has(input:checked) .preset-fps { color: var(--lamp); }
.preset:has(input:focus-visible) { outline: 2px solid var(--lamp); outline-offset: 2px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--stage); border: 1px solid var(--line); border-radius: var(--r-m); padding: 3px; }
.seg label { position: relative; text-align: center; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 8px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg input:checked + span { background: var(--panel-3); color: var(--text); }
.seg input:focus-visible + span { outline: 2px solid var(--lamp); }

.row-2 { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: end; }
.row-2 .check { margin-bottom: 18px; }
.upload-est { font-size: 13.5px; color: var(--muted); background: var(--stage); border-radius: var(--r-s); padding: 10px 12px; margin: 0 0 8px; }
.upload-est strong { color: var(--text); }

.meter { position: relative; height: 10px; background: var(--stage); border-radius: 5px; overflow: hidden; margin: 8px 0 10px; }
.meter-fill { height: 100%; background: var(--faint); transform-origin: left; transform: scaleX(0); transition: transform .06s linear, background .1s; }
.meter-fill.above { background: var(--ok); }
.meter-marker { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--lamp); }
.hint.tight { margin: -8px 0 14px; }
.field.slim { margin-bottom: 4px; }
.vad { margin-bottom: 18px; }
.dialog { overflow-y: auto; }

/* ---------- Popover och toasts ---------- */

.popover {
  position: fixed; z-index: 50;
  width: 240px; padding: 14px 14px 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-m);
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
}
.pop-title { font-family: var(--font-display); font-weight: 700; margin: 0 0 10px; }
.pop-meta { font-size: 12.5px; color: var(--muted); margin: -4px 0 0; }

.toasts { position: fixed; z-index: 60; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100% - 24px)); }
.toast {
  background: var(--panel-3); border: 1px solid var(--line); border-radius: var(--r-m);
  padding: 10px 14px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  transition: opacity .4s, transform .4s;
}
.toast.warn { border-color: var(--warn); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- Mobil / smalt fönster ---------- */

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "banner" "main" "tabs";
  }
  .people, .stage, .chat { grid-area: main; border: 0; }
  .app[data-tab="stage"] .people, .app[data-tab="stage"] .chat,
  .app[data-tab="people"] .stage, .app[data-tab="people"] .chat,
  .app[data-tab="chat"] .stage, .app[data-tab="chat"] .people { display: none; }
  .tabbar {
    grid-area: tabs; display: grid; grid-template-columns: repeat(3, 1fr);
    background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar button {
    border: 0; background: none; padding: 12px 0 13px; font-weight: 600; color: var(--muted); cursor: pointer;
    position: relative;
  }
  .tabbar button.active { color: var(--lamp); }
  .tab-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--live); color: #fff; font-size: 11px; line-height: 18px; }
  .preset-grid { grid-template-columns: repeat(3, 1fr); }
  .row-2 { grid-template-columns: 1fr; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
