:root {
  /* Tema Halloween: malam ungu + labu oranye */
  --accent: #FF7A1A;
  --ink: #1E1030;
  --bg: #1E1030;
  --surface: #2B1A40;
  --text: #F7EBDD;
  --muted: #B9A6CF;
  --border: #45305F;
  --mine: #FF7A1A;
  --mine-text: #1E1030;
  --theirs: #3A2556;
  --theirs-text: #F7EBDD;
  --error: #FF6B6B;
  --shadow: 0 2px 6px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

button, input { font: inherit; }
input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
input::placeholder { color: var(--muted); }
input:focus { border-color: var(--accent); }
button {
  padding: 12px 20px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 800;
  transition: transform .08s, filter .15s;
}
button:active { transform: scale(.96); }
button:disabled { opacity: .6; cursor: default; }
.primary { background: var(--accent); color: var(--ink); }
.primary:hover { filter: brightness(.97); }
.secondary { background: transparent; color: var(--text); border-color: var(--accent); }
.secondary:hover { background: var(--accent); color: var(--ink); }
input { background: var(--bg); }

/* ---------- Lobby ---------- */
.lobby {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; padding: 32px 16px;
  position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 82% 12%, #FFF3C4 0 46px, rgba(255, 220, 140, .25) 47px 70px, transparent 71px),
    linear-gradient(180deg, #2A1250 0%, #1E1030 60%, #140A22 100%);
}
.lobby > :not(.bats) { position: relative; z-index: 1; }
.bats { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.bat { position: absolute; width: 44px; color: #5B3A85; animation: flap 3.4s ease-in-out infinite; }
.bat:nth-child(1) { top: 9%; left: 10%; }
.bat:nth-child(2) { top: 20%; right: 22%; width: 30px; animation-delay: -1.2s; }
.bat:nth-child(3) { bottom: 14%; left: 16%; width: 34px; animation-delay: -2s; }
.bat:nth-child(4) { bottom: 22%; right: 10%; width: 40px; animation-delay: -.6s; }
.ghost { position: absolute; width: 56px; opacity: .9; animation: float 4s ease-in-out infinite; filter: drop-shadow(0 0 12px rgba(244, 238, 255, .35)); }
.g1 { top: 30%; left: 6%; }
.g2 { top: 6%; left: 42%; width: 38px; opacity: .55; animation-delay: -1.5s; }
.g3 { top: 44%; right: 7%; width: 46px; opacity: .75; animation-delay: -2.6s; transform: scaleX(-1); }
.pumpkin { position: absolute; bottom: 12px; width: 90px; filter: drop-shadow(0 0 18px rgba(255, 122, 26, .45)); }
.p1 { left: 4%; }
.p2 { left: calc(4% + 70px); width: 60px; }
.p3 { right: 5%; width: 80px; }
@keyframes float { 50% { translate: 0 -14px; } }
.mascot-row { display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.side-pumpkin { width: 64px; margin-bottom: 4px; filter: drop-shadow(0 0 14px rgba(255, 122, 26, .5)); }
.side-ghost { width: 50px; align-self: flex-start; margin-top: 10px; animation: float 3s ease-in-out infinite; }
.header-pumpkin { width: 30px; flex: none; }
.chat-body { position: relative; }
.chat-deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.deco-ghost { position: absolute; top: 18%; right: 8%; width: 90px; opacity: .08; animation: float 5s ease-in-out infinite; }
.deco-pumpkin { position: absolute; bottom: 10px; left: 12px; width: 110px; opacity: .1; }
.deco-pumpkin.small { left: 110px; width: 64px; }
.messages { position: relative; z-index: 1; }
@media (max-width: 640px) {
  .chat { --side: 0px; }
  .p2, .g2 { display: none; }
  .pumpkin { width: 64px; }
  .ghost { width: 40px; }
}
@keyframes flap { 50% { transform: translateY(-10px) scaleX(.85); } }
.brand { text-align: center; color: var(--text); }
.logo { width: 140px; height: auto; filter: drop-shadow(0 6px 0 rgba(0,0,0,.08)); animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.brand h1 { margin: 8px 0 4px; font-size: 34px; font-weight: 900; letter-spacing: -.5px; }
.brand p { margin: 0; font-weight: 700; opacity: .75; }

.card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 10px 0 rgba(0,0,0,.25), 0 0 60px rgba(255, 122, 26, .15);
}
.card label { display: block; font-size: 14px; font-weight: 800; margin: 14px 4px 6px; }
.card label:first-child { margin-top: 0; }
.row { display: flex; gap: 8px; }
.card #createBtn { width: 100%; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; border-radius: 2px; background: var(--border); }
.error { color: var(--error); font-size: 14px; min-height: 1.2em; margin: 12px 4px 0; }

/* ---------- Chat ---------- */
.chat {
  height: 100%; display: flex; flex-direction: column;
  --col: 760px;   /* lebar maksimal kolom chat */
  --side: 190px;  /* lebar sidebar online (0 kalau disembunyikan) */
  /* jarak kiri supaya kolom chat ada di tengah area pesan */
  --gutter: max(12px, calc((100% - var(--side) - var(--col)) / 2));
}
.chat.users-hidden { --side: 0px; }
.chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #FF8C33, #F26A0F); color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  position: relative; z-index: 1;
}
.icon-btn {
  width: 42px; height: 42px; padding: 0;
  display: grid; place-items: center;
  background: transparent; color: var(--ink);
}
.icon-btn:hover { background: rgba(0,0,0,.07); }
.header-mascot { width: 40px; height: 40px; flex: none; }
.header-title { flex: 1; text-align: center; line-height: 1.2; }
.room-title { font-weight: 900; font-size: 18px; }
.room-sub {
  font-size: 12px; font-weight: 700; color: var(--ink); opacity: .75;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border: 0; background: transparent; border-radius: 999px;
}
.room-sub:hover { opacity: 1; background: rgba(0,0,0,.1); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 2px rgba(255,255,255,.6); }

.chat-body { flex: 1; display: flex; min-height: 0; width: 100%; }
.messages {
  flex: 1; overflow-y: auto; padding: 16px var(--gutter);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cg fill='%23ffffff' fill-opacity='.05'%3E%3Cpath d='M30 40c4-6 10-6 12-2 2-4 8-4 12 2-4-1-7 1-8 4-1-2-3-3-4-3s-3 1-4 3c-1-3-4-5-8-4z'/%3E%3Ccircle cx='120' cy='30' r='2'/%3E%3Ccircle cx='90' cy='120' r='1.5'/%3E%3Ccircle cx='20' cy='130' r='2'/%3E%3Cpath d='M110 95c4-6 10-6 12-2 2-4 8-4 12 2-4-1-7 1-8 4-1-2-3-3-4-3s-3 1-4 3c-1-3-4-5-8-4z'/%3E%3C/g%3E%3C/svg%3E");
  display: flex; flex-direction: column; gap: 3px;
}

.users { position: relative; z-index: 1; width: 190px; flex: none; background: rgba(0,0,0,.15); padding: 14px 12px; overflow-y: auto; border-left: 2px solid var(--border); }
.users-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; }
.users h2 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0; letter-spacing: .5px; font-weight: 800; }
.users-close {
  width: 24px; height: 24px; padding: 0; display: grid; place-items: center;
  background: transparent; color: var(--muted); font-size: 12px; border-radius: 8px;
}
.users-close:hover { background: rgba(255,255,255,.08); color: var(--text); }
.users ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.users li { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; min-width: 0; }
.users li span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Avatar */
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 900; font-size: 16px; color: #fff;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
}
.users .avatar { width: 28px; height: 28px; font-size: 13px; border-width: 1px; }
.chat.users-hidden .users { display: none; }
#usersBtn { position: relative; }
#usersBtn[aria-pressed="true"] { background: rgba(0,0,0,.12); }

/* Pesan */
.msg { display: flex; align-items: flex-start; gap: 8px; max-width: 80%; align-self: flex-start; margin-top: 10px; }
.msg.grouped { margin-top: 0; }
.msg.grouped .avatar { visibility: hidden; height: 0; }
.msg .content { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.msg .name { font-size: 13px; font-weight: 800; margin: 0 0 3px 6px; color: var(--muted); }
.msg.grouped .name { display: none; }
.msg .line { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.msg .bubble {
  padding: 10px 14px; border-radius: 20px;
  background: var(--theirs); color: var(--theirs-text);
  box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4;
  min-width: 0;
  animation: pop .18s ease-out;
}
.msg:not(.grouped) .bubble { border-top-left-radius: 6px; }
.msg .time { flex: none; font-size: 11px; color: var(--muted); font-weight: 700; padding-bottom: 2px; }

.msg.mine { align-self: flex-end; }
.msg.mine .content { align-items: flex-end; }
.msg.mine .line { flex-direction: row-reverse; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); }
.msg.mine:not(.grouped) .bubble { border-top-left-radius: 20px; border-top-right-radius: 6px; }

@keyframes pop { from { transform: scale(.85); opacity: 0; } }

/* Tombol balas: muncul saat pesan di-hover (di HP selalu tampil samar) */
.reply-btn {
  flex: none; width: 28px; height: 28px; padding: 0; align-self: center;
  display: grid; place-items: center; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 16px; font-weight: 900;
  opacity: 0; transition: opacity .15s, background .15s;
}
.msg:hover .reply-btn, .reply-btn:focus-visible { opacity: 1; }
.reply-btn:hover { background: rgba(255,255,255,.1); color: var(--text); }
@media (hover: none) { .reply-btn { opacity: .55; } }

/* Kutipan pesan yang dibalas */
.quote {
  display: block; width: 100%; min-width: 120px; text-align: left;
  margin: 0 0 6px; padding: 6px 10px; border-radius: 12px;
  background: rgba(0,0,0,.18); border: 0; border-left: 4px solid var(--accent);
  color: inherit; font: inherit; cursor: pointer;
}
.msg.mine .quote { background: rgba(0,0,0,.12); border-left-color: var(--ink); }
.bubble.has-media .quote { margin: 0 0 4px; }
.quote-name { font-size: 12px; font-weight: 900; opacity: .9; }
.quote-text {
  font-size: 13px; font-weight: 600; opacity: .8;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  white-space: normal;
}
.msg.flash .bubble { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: var(--shadow); } }

/* Bar "Membalas ..." di atas kolom ketik */
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 0 calc(var(--gutter) + var(--side)) 8px var(--gutter); padding: 8px 8px 8px 12px;
  background: var(--surface); border: 2px solid var(--border); border-left: 5px solid var(--accent); border-radius: 16px;
}
.reply-bar-body { flex: 1; min-width: 0; }
.reply-bar-title { font-size: 13px; color: var(--muted); }
.reply-bar-title b { color: var(--accent); }
.reply-bar-text { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.system .system-time { opacity: .65; margin-left: 6px; font-weight: 600; }
.system {
  align-self: center; margin: 10px 0;
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); padding: 5px 12px; border-radius: 999px;
  box-shadow: var(--shadow); text-align: center; max-width: 90%;
}

.typing { font-size: 12px; font-weight: 700; color: var(--muted); height: 18px; padding: 0 calc(var(--gutter) + var(--side) + 8px) 0 calc(var(--gutter) + 8px); }

.composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px calc(var(--gutter) + var(--side)) 10px var(--gutter);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, .35);
}
.composer input { background: var(--bg); border-color: transparent; }
.composer input:focus { border-color: var(--accent); }
.send {
  flex: none; width: 46px; height: 46px; padding: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--ink);
}

/* Media di dalam bubble */
/* Lebar bubble = lebar gambar; teks di bawahnya ikut membungkus */
.msg .bubble.has-media { padding: 4px; width: min-content; }
.msg .bubble.has-media .text { padding: 6px 10px 6px; }
.media {
  display: block; width: auto; height: auto;
  /* pakai vw, bukan %, supaya bubble tidak melebar mengikuti ukuran asli gambar */
  max-width: min(300px, 62vw); max-height: 340px;
  border-radius: 16px; background: rgba(0,0,0,.25);
}
video.media { width: min(300px, 62vw); }
img.media { cursor: zoom-in; }
.msg:not(.grouped) .media { border-top-left-radius: 4px; }
.msg.mine:not(.grouped) .media { border-top-left-radius: 16px; border-top-right-radius: 4px; }

/* Gambar/GIF/video tanpa teks: tampil polos tanpa bubble (upload & link sama) */
.msg .bubble.only-media { background: transparent; box-shadow: none; padding: 0; }
.bubble.only-media .media { box-shadow: 0 4px 14px rgba(0,0,0,.35); margin: 0; }
.media-gone { padding: 12px 14px; font-size: 13px; opacity: .8; }

/* Tombol & pratinjau lampiran */
.attach {
  flex: none; width: 46px; height: 46px; padding: 0;
  display: grid; place-items: center;
  background: transparent; color: var(--accent);
}
.attach:hover { background: rgba(255, 122, 26, .12); }
.attach-preview {
  display: flex; align-items: center; gap: 12px;
  margin: 0 calc(var(--gutter) + var(--side)) 8px var(--gutter); padding: 8px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 18px;
}
.attach-thumb { flex: none; width: 56px; height: 56px; border-radius: 12px; overflow: hidden; background: var(--bg); }
.attach-thumb img, .attach-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-info { flex: 1; min-width: 0; }
.attach-name { font-weight: 800; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-status { font-size: 12px; color: var(--muted); }
.progress { height: 6px; border-radius: 6px; background: var(--bg); margin-top: 6px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.icon-btn.small { width: 36px; height: 36px; color: var(--muted); font-size: 16px; }
.icon-btn.small:hover { background: rgba(255,255,255,.08); }

.drop-overlay {
  position: fixed; inset: 12px; z-index: 20;
  display: grid; place-items: center;
  border: 3px dashed var(--accent); border-radius: 24px;
  background: rgba(30, 16, 48, .85); color: var(--accent);
  font-size: 22px; font-weight: 900; pointer-events: none;
}
.lightbox {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 16px;
  background: rgba(10, 4, 20, .92); cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

/* Kolom kode rahasia */
.secret-field { position: relative; flex: 1; min-width: 0; }
.secret-field input { padding-right: 46px; letter-spacing: 2px; }
.peek {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; padding: 0; background: transparent; font-size: 16px; opacity: .7;
}
.peek:hover { opacity: 1; }
.peek:active { transform: translateY(-50%) scale(.92); }

/* Emoji */
.emoji-panel {
  margin: 0 calc(var(--gutter) + var(--side)) 8px var(--gutter);
  max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 2px solid var(--border); border-radius: 18px;
  padding: 8px 10px 10px;
}
.emoji-panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 8px 4px 4px; font-weight: 800; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
.emoji-grid button {
  padding: 0; height: 40px; font-size: 24px; background: transparent; border-radius: 10px; font-weight: 400;
}
.emoji-grid button:hover { background: rgba(255,255,255,.08); }
.msg .bubble.jumbo { background: transparent; box-shadow: none; font-size: 42px; padding: 0 4px; line-height: 1.15; }

/* Link & preview gambar dari link */
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.msg:not(.mine) .bubble a { color: #FFB066; }
.bubble .link-media { margin-top: 6px; }
.bubble .text + .link-media, .bubble .link-media + .text { margin-top: 6px; }


/* Dialog share */
.modal {
  position: fixed; inset: 0; z-index: 35;
  display: grid; place-items: center; padding: 16px;
  background: rgba(10, 4, 20, .75);
}
.modal-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 24px; padding: 20px;
}
.modal-card h2 { margin: 0 0 6px; font-size: 20px; font-weight: 900; }
.modal-hint { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.share-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 16px; padding: 8px 8px 8px 14px; margin-bottom: 10px; }
.share-label { font-size: 12px; font-weight: 800; color: var(--muted); width: 36px; flex: none; }
.share-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.share-value.mono { font-family: ui-monospace, monospace; font-size: 16px; letter-spacing: 3px; font-weight: 700; }
.small { padding: 7px 14px; font-size: 14px; }
.block { width: 100%; margin-top: 6px; }

.toast {
  z-index: 40;
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--accent); color: var(--ink);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  /* Di HP sidebar jadi laci yang menimpa chat */
  .users {
    position: absolute; right: 0; top: 0; bottom: 0; z-index: 5;
    width: 200px; background: var(--surface);
    box-shadow: -8px 0 24px rgba(0,0,0,.4);
  }
  .msg { max-width: 88%; }
}
