:root {
  --bg: #000;
  --panel: #0b0b0d;
  --panel-2: #1c1c1e;
  --bubble-me: #2563eb;
  --bubble-her: #1c1c1e;
  --text: #f2f2f7;
  --muted: #8e8e93;
  --hairline: #26262a;
  --accent: #2563eb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; }

/* ---------- header ---------- */
header {
  background: rgba(11, 11, 13, .92);
  backdrop-filter: blur(14px);
  border-bottom: .5px solid var(--hairline);
  position: sticky; top: 0; z-index: 10;
}
.bar {
  max-width: 540px; margin: 0 auto; width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  box-sizing: border-box;
}
.hdr-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hdr-name { display: flex; flex-direction: column; line-height: 1.15; }
.name { font-weight: 600; font-size: 15px; }
.sub { font-size: 11px; color: var(--muted); }
.hdr-right { display: flex; gap: 6px; align-items: center; }
select {
  background: var(--panel-2); color: var(--text); border: none;
  border-radius: 8px; padding: 5px 6px; font-size: 11px; max-width: 118px; outline: none;
}
.iconbtn {
  background: var(--panel-2); border: none; color: var(--text);
  border-radius: 8px; padding: 5px 9px; font-size: 13px; cursor: pointer;
}

/* playstyle-vælger */
.style-row {
  max-width: 540px; margin: 0 auto; width: 100%;
  padding: 6px 12px 10px;
  display: flex; flex-wrap: wrap; gap: 6px;
  box-sizing: border-box;
}
.style-chip {
  background: var(--panel-2); border: 1px solid transparent; color: var(--muted);
  border-radius: 16px; padding: 5px 11px; font-size: 12px; cursor: pointer;
}
.style-chip.active { color: var(--text); border-color: var(--accent); background: rgba(37, 99, 235, .18); }
.iconbtn.style-chip { padding: 5px 9px; font-size: 11px; }

/* menu */
.menu {
  max-width: 540px; margin: 0 auto; width: 100%;
  padding: 4px 12px 10px; display: flex; flex-direction: column; gap: 4px;
  box-sizing: border-box;
}
.menu button {
  text-align: left; background: var(--panel-2); border: none; color: var(--text);
  padding: 10px 14px; border-radius: 12px; font-size: 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px;
}
.menu button small { color: var(--muted); font-size: 11px; }
.menu button.danger { background: #3a1a22; }

/* ---------- avatar ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #3a2f52, #7a5a3f);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; color: #f3ead9;
  overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 72px; height: 72px; margin: 0 auto 14px; font-size: 28px; }

/* ---------- chat ---------- */
main {
  flex: 1; overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; max-width: 540px; margin: 0 auto;
  scrollbar-width: none;
}
main::-webkit-scrollbar { display: none; }

.pill {
  align-self: center; color: var(--muted); font-size: 11px;
  background: rgba(60, 60, 67, .35); padding: 3px 10px; border-radius: 20px;
  margin: 10px 0 6px;
}

.msg { max-width: 78%; padding: 8px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; line-height: 1.38; }
.msg.me {
  align-self: flex-end; background: var(--bubble-me);
  border-bottom-right-radius: 6px; color: #fff;
  margin-top: 8px;
}
.msg.her {
  align-self: flex-start; background: var(--bubble-her);
  border-bottom-left-radius: 6px;
}
.msg.me em, .msg.her em { font-style: italic; opacity: .75; }
.msg.system {
  align-self: center; background: none; color: var(--muted);
  font-size: 12px; font-style: italic; padding: 4px;
}

/* beskeder med avatar: konstant indrykning, avatar absolut placeret ved nederste besked */
.msg-wrap { display: block; position: relative; padding-left: 31px; align-self: flex-start; max-width: 88%; margin-top: 2px; }
.msg-wrap.gap { margin-top: 8px; }
.msg-wrap .mini-avatar { position: absolute; left: 0; bottom: 2px; width: 24px; height: 24px; border-radius: 50%; overflow: hidden; background: #2a2138; display: flex; align-items: center; justify-content: center; font-size: 11px; color: #f3ead9; font-weight: 600; }
.msg-wrap .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-wrap .msg { max-width: 100%; display: inline-block; }
.msg-wrap .msg.her { max-width: 100%; }

/* seen-indikator (Messenger-stil): avatar ved hans sidste besked hun har set */
.seen-row {
  display: flex; justify-content: flex-end; align-items: center; gap: 7px;
  margin-top: 3px; padding-right: 2px;
  animation: msgIn .2s ease-out;
}
.seen-row .seen-label { font-size: 10px; color: var(--muted); }
.seen-row .mini-avatar { position: static; width: 18px; height: 18px; font-size: 9px; }

/* animation ved nye beskeder */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(7px) scale(.97); }
  to { opacity: 1; transform: none; }
}
.msg-wrap, .msg.me, .narr, .me-line, .pill, .bubble-time { animation: msgIn .2s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .msg-wrap, .msg.me, .narr, .me-line, .pill, .bubble-time { animation: none; }
}

.msg.typing-msg { padding: 13px 17px; display: flex; gap: 5px; align-items: center; }
.tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .45; animation: blink 1.2s infinite; }
.tdot:nth-child(2) { animation-delay: .2s; }
.tdot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 40% { opacity: 1; } }

/* ---------- prosa-læser-tilstand ---------- */
body.mode-prosa main {
  background: #101216;
  padding: 24px 18px 12px;
}
body.mode-prosa .narr {
  align-self: stretch; max-width: 660px; margin: 0 auto 1.2em;
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 17.5px; line-height: 1.75; color: #e9e6df;
  background: none; padding: 0; border-radius: 0; white-space: pre-wrap;
}
body.mode-prosa .narr em { font-style: italic; color: #b9b3a6; }
body.mode-prosa .me-line {
  align-self: stretch; max-width: 660px; margin: 0 auto 1.2em;
  font-family: Georgia, serif; font-size: 15px; line-height: 1.6;
  color: var(--muted); font-style: italic;
  border-left: 2px solid #2c2f3a; padding-left: 12px;
  background: none; border-radius: 0;
}
body.mode-prosa .pill { margin: 18px 0; }

/* panel-tabs */
.panel-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.ptab {
  flex: 1; padding: 9px; border-radius: 10px; border: none; cursor: pointer;
  background: var(--panel-2); color: var(--muted); font-size: 13px; font-weight: 500;
}
.ptab.active { background: rgba(37, 99, 235, .22); color: var(--text); }

/* settings */
.setting { margin-bottom: 12px; }
.setting label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.setting-select {
  width: 100%; background: var(--panel-2); color: var(--text); border: none;
  border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none;
}
.setting select {
  width: 100%; background: var(--panel-2); color: var(--text); border: none;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; outline: none;
}

/* ---------- startskærm ---------- */
.start-screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 20px; gap: 6px; text-align: center; max-width: 540px; margin: 0 auto; width: 100%;
}
.start-screen .avatar.big { margin-bottom: 4px; }
.start-sub { color: var(--muted); font-size: 13px; max-width: 300px; margin-bottom: 14px; }
.chips-big { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-bottom: 16px; }
.style-chip.big { padding: 9px 15px; font-size: 14px; border-radius: 20px; }
.start-note { color: var(--muted); font-size: 12px; max-width: 320px; min-height: 2em; line-height: 1.5; }
.start-screen .open { max-width: 300px; }

/* ---------- starter ---------- */
.starter { padding: 10px 14px 4px; max-width: 540px; margin: 0 auto; width: 100%; box-sizing: border-box; }
.open {
  width: 100%; padding: 13px; border-radius: 14px; border: none; cursor: pointer;
  background: var(--panel-2); color: var(--text); font-size: 14px; font-weight: 500;
}
.open:active { transform: scale(.99); }

/* ---------- composer ---------- */
#composer {
  background: rgba(11, 11, 13, .92);
  backdrop-filter: blur(14px);
  border-top: .5px solid var(--hairline);
}
#composer .bar.row { padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); gap: 8px; align-items: flex-end; }
#composer textarea {
  flex: 1; background: var(--panel-2); border: none; color: var(--text);
  border-radius: 20px; padding: 11px 16px; font-size: 16px; outline: none;
  resize: none; max-height: 130px; overflow-y: auto;
  font-family: inherit; line-height: 1.35;
}
#sendBtn {
  width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 17px; flex-shrink: 0;
}
#sendBtn:disabled { background: #2c2c2e; }
.stop {
  width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
  background: #6b2737; color: #fff; font-size: 12px; flex-shrink: 0;
}
/* billedbobler */
.msg.img-msg { padding: 3px; background: var(--bubble-her); }
.msg-img { max-width: 100%; border-radius: 15px; display: block; cursor: pointer; }
body.mode-prosa .narr .msg-img { max-width: 420px; margin: .8em 0; }

.hidden { display: none !important; }

/* ---------- panel (messenger-agtig info-side) ---------- */
.panel {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(2px);
}
.panel-inner {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(400px, 100%);
  background: var(--panel);
  border-left: .5px solid var(--hairline);
  overflow-y: auto;
  padding: 20px 18px 40px;
  animation: slideIn .22s ease-out;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
.panel .close { position: absolute; top: 12px; right: 14px; }
.panel-profile { text-align: center; margin: 8px 0 22px; }
.pname { font-weight: 600; font-size: 17px; margin-top: 10px; }
.psub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.panel h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 20px 0 10px;
}
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.media-item { position: relative; border-radius: 10px; overflow: hidden; aspect-ratio: 1; cursor: pointer; background: var(--panel-2); }
.media-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item .cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 7px 5px; font-size: 10px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.media-empty { color: var(--muted); font-size: 12px; }
.media-lightbox {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px;
  cursor: pointer; padding: 20px;
}
.media-lightbox img { max-width: 100%; max-height: 78vh; border-radius: 10px; }
.media-lightbox .lb-cap { color: var(--muted); font-size: 13px; }

.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  background: var(--panel-2); border-radius: 12px; padding: 10px 12px; cursor: pointer;
}
.history-item .hi-date { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.history-item .hi-preview { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .hi-actions { display: flex; gap: 8px; margin-top: 7px; }
.history-item .hi-actions button {
  background: none; border: .5px solid var(--hairline); color: var(--muted);
  border-radius: 8px; padding: 3px 10px; font-size: 11px; cursor: pointer;
}
.history-item .hi-actions button:hover { color: var(--text); }
.history-empty { color: var(--muted); font-size: 12px; }
.panel-note { color: var(--muted); font-size: 11px; margin-top: 10px; font-style: italic; }

/* visnings-tilstand for arkiveret session */
.readonly-banner {
  position: sticky; top: 0; z-index: 5;
  background: #2c2f3a; color: var(--text); font-size: 12px;
  padding: 7px 14px; display: flex; justify-content: space-between; align-items: center;
}
.readonly-banner button { background: none; border: none; color: #9db8e8; cursor: pointer; font-size: 12px; }

/* timestamps */
.bubble-time { align-self: flex-end; color: var(--muted); font-size: 10px; margin: 2px 6px 6px 0; }
.bubble-time.left { align-self: flex-start; margin: 2px 0 6px 31px; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.authbox { text-align: center; }
.authbox p { margin-bottom: 12px; color: var(--muted); }
.authbox input {
  background: var(--panel-2); border: none; color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none; width: 220px;
}
.authbox button {
  display: block; margin: 12px auto 0; padding: 10px 22px; border-radius: 12px;
  border: none; background: var(--accent); color: #fff; cursor: pointer;
}
