:root {
  --bg: #111418;
  --panel: #1c2128;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --accent: #3b82f6;
  --danger: #dc2626;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

.btn {
  font: inherit;
  padding: 10px 18px;
  border: 1px solid #3a424d;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.1); }

.error { color: #f87171; }

/* ---------- Startsidan ---------- */

body.start {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.start-card {
  max-width: 420px;
  width: 100%;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
}
.start-card h1 { margin: 0 0 8px; font-size: 1.6rem; }
.start-card p { color: var(--muted); margin: 0 0 20px; }

/* ---------- Samtalssidan ---------- */

body.room {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
}

.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.local-wrap {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: min(28vw, 220px); /* ändras av storleksgreppet (room.js) */
  aspect-ratio: 4 / 3;
  z-index: 2;
}

.local-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: #222;
  transform: scaleX(-1); /* spegelvänd egen bild, som i en spegel */
}

/* Greppet sitter i övre vänstra hörnet eftersom rutan är fäst nere till
   höger - man drar ut den mot mitten av bilden. */
.resize-handle {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 32px;
  height: 32px;
  cursor: nwse-resize;
  touch-action: none;
}
.resize-handle::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  width: 12px;
  height: 12px;
  border-top: 3px solid rgba(255, 255, 255, 0.85);
  border-left: 3px solid rgba(255, 255, 255, 0.85);
  border-top-left-radius: 4px;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
}
.resize-handle:focus-visible { outline: 2px solid var(--accent); border-radius: 6px; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  text-align: center;
  background: rgba(17, 20, 24, 0.85);
  z-index: 1;
}
.status { margin: 0; font-size: 1.15rem; }

.share-panel {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
}
.share-panel p { margin: 0 0 10px; color: var(--muted); }
.share-row { display: flex; gap: 8px; }
.share-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid #3a424d;
  background: var(--bg);
  color: var(--text);
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
}
.ctrl {
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid #3a424d;
  background: #2a313a;
  color: var(--text);
  cursor: pointer;
}
.ctrl[aria-pressed="true"] { background: #4b5563; color: #fca5a5; }
.ctrl-hangup { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.ctrl:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 480px) {
  .ctrl { padding: 9px 12px; font-size: 0.9rem; }
  .local-wrap { width: 32vw; }
}

/* ---------- Chatten ----------
   Panelen svävar över bilden och trycker aldrig ner något. Meddelandena
   är vanliga textnoder med rätt lang-attribut, så webbläsarens egen
   sidöversättning kan översätta dem allteftersom de kommer in - därför
   får ingenting här translate="no". */

.chat-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: var(--chat-width, 340px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid #3a424d;
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

/* Egen videoruta kliver åt sidan i stället för att hamna under panelen. */
body.chat-open .local-wrap { right: calc(var(--chat-width, 340px) + 24px); }

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 12px 14px;
  border-bottom: 1px solid #3a424d;
}
.chat-title { margin: 0; font-size: 1rem; font-weight: 600; flex: 1; }
.chat-lang-label { font-size: 0.8rem; color: var(--muted); }
.chat-lang {
  font: inherit;
  font-size: 0.82rem;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #3a424d;
  background: var(--panel);
  color: var(--text);
}
.chat-icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid #3a424d;
  background: #2a313a;
  color: var(--text);
  cursor: pointer;
}
.chat-icon-btn:hover { border-color: var(--muted); }

.chat-tip {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  background: var(--panel);
  border-bottom: 1px solid #3a424d;
  color: var(--muted);
}
.chat-tip svg { flex: none; margin-top: 2px; }
.chat-tip p { margin: 0; font-size: 0.8rem; flex: 1; }
.chat-tip strong { color: var(--text); font-weight: 600; }
.chat-tip-close {
  flex: none;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.chat-tip-close:hover { color: var(--text); }

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-empty { margin: auto 0; text-align: center; color: var(--muted); font-size: 0.85rem; }

.chat-msg { max-width: 85%; align-self: flex-start; }
.chat-msg.mine { align-self: flex-end; }
.chat-bubble {
  background: var(--panel);
  border: 1px solid #3a424d;
  border-radius: var(--radius);
  padding: 9px 12px;
}
.chat-msg.mine .chat-bubble { background: #2a313a; }
.chat-bubble p { margin: 0; font-size: 0.92rem; overflow-wrap: anywhere; white-space: pre-wrap; }

.chat-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 0 2px;
}
.chat-msg.mine .chat-meta { justify-content: flex-end; }
.chat-time { font-size: 0.72rem; color: var(--muted); }
.chat-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}
.chat-copy:hover { color: var(--text); }

.chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px 12px;
  border-top: 1px solid #3a424d;
}
.chat-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.chat-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid #3a424d;
  background: var(--panel);
  color: var(--text);
  resize: none;
}
.chat-input:disabled { opacity: 0.5; }
.chat-send {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.chat-send:hover { filter: brightness(1.1); }
.chat-send:disabled { opacity: 0.5; cursor: default; filter: none; }

/* Olästa: en siffra, inte bara en färgprick. */
.chat-unread {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

/* Senaste meddelandet tonar in över bilden när panelen är stängd. */
.chat-toast {
  position: absolute;
  top: 12px;
  right: 12px;
  max-width: min(360px, calc(100% - 24px));
  z-index: 3;
  background: var(--bg);
  border: 1px solid #3a424d;
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  padding: 10px 12px;
}
.chat-toast p { margin: 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.chat-toast .chat-time { display: block; margin-top: 5px; }

@media (max-width: 480px) {
  /* På mobil blir panelen ett ark över nederkanten: bilden syns kvar. */
  .chat-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 64%;
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
  }
  body.chat-open .local-wrap {
    top: 12px;
    bottom: auto;
    right: 12px;
  }
  .chat-copy { min-height: 44px; }
  .chat-icon-btn,
  .chat-send { width: 44px; height: 44px; }
}
