:root {
  --bg: #0f0e24; --panel: #1d1840; --panel2: #2b2358; --line: #3b3370;
  --text: #f5f0e6; --muted: #9b93c9; --soft: #c9c2ee;
  --gold: #ffcc33; --pink: #ff5d8f; --teal: #4fd1c5; --green: #7ee081;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: 'VT323', monospace; font-size: 22px; line-height: 1.15; }
button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; left: -9999px; }

.app { max-width: 1680px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px; padding: 10px 20px; background: var(--panel); border-bottom: 4px solid #000; }
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 46px; color: var(--gold); text-shadow: 4px 4px 0 var(--pink), 8px 8px 0 #000; letter-spacing: 2px; }
.sub { color: var(--muted); }
.anon { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 12px; background: #000; border: 2px solid var(--teal); color: var(--teal); font-size: 20px; }
.anon .tag { padding: 0 6px; background: var(--teal); color: #000; }
.spacer { flex: 1; }
.online { display: flex; align-items: center; gap: 8px; }
.online .dot { width: 12px; height: 12px; background: var(--green); }
.mebox { display: flex; align-items: center; gap: 10px; padding: 6px 14px; background: var(--panel2); border: 4px solid var(--gold); box-shadow: 4px 4px 0 #000; }
.me-text { display: flex; flex-direction: column; }
.small { font-size: 16px; color: var(--muted); }
.me-nick { font-size: 24px; color: var(--gold); }

/* Layout: laptop / màn lớn = bản đồ trái, chat phải */
.main { flex: 1; display: flex; align-items: flex-start; gap: 20px; padding: 20px; min-height: 0; }
.left { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.chat { flex: 0 0 clamp(320px, 30vw, 420px); min-width: 0; height: calc(100dvh - var(--head, 90px) - 48px); min-height: 440px; max-height: 920px; display: flex; flex-direction: column; background: var(--panel); border: 4px solid #000; box-shadow: 0 0 0 4px var(--line), 6px 6px 0 4px #000; }
.mobnav { display: none; }

/* Map: tự co giãn theo khung, nhỏ quá thì cho kéo ngang */
.map-wrap { position: relative; width: fit-content; max-width: 100%; border: 4px solid #000; box-shadow: 0 0 0 4px var(--line), 6px 6px 0 4px #000; overflow-x: auto; overflow-y: hidden; background: #17132f; -webkit-overflow-scrolling: touch; }
.map-sizer { position: relative; }
.map { position: absolute; left: 0; top: 0; width: 812px; height: 532px; transform-origin: 0 0; cursor: crosshair; }
.room { position: absolute; border: 4px solid rgba(0,0,0,.6); }
.room-label { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; padding: 2px 10px 4px; background: #000; border: 2px solid; white-space: nowrap; pointer-events: none; }
.room-label .r1 { display: flex; gap: 8px; font-size: 22px; }
.room-label .cnt { color: var(--muted); }
.room-label .joke { font-size: 16px; color: var(--soft); }
.room.mine { outline: 3px dashed var(--gold); outline-offset: -8px; }

.pl { position: absolute; width: 140px; margin-left: -70px; transform: translateY(-100%); display: flex; flex-direction: column; align-items: center; gap: 2px; transition: left .7s linear, top .7s linear; pointer-events: none; z-index: 2; }
.pl .bubble { max-width: 200px; padding: 3px 8px; background: var(--text); color: #1b1530; border: 3px solid #000; font-size: 18px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .name { pointer-events: auto; padding: 0 6px; background: rgba(0,0,0,.75); border: 0; font-size: 17px; white-space: nowrap; text-decoration: underline dotted; }
.pl.me .name { text-decoration: none; cursor: default; }
.pl svg { image-rendering: pixelated; }
.pl .hit { pointer-events: auto; cursor: pointer; }
.pl.me .hit { cursor: default; }
/* Phòng đông: ẩn tên, rê chuột / chạm vào nhân vật mới hiện */
.pl.quiet .name { visibility: hidden; }
.pl.quiet:hover .name, .pl.quiet.peek .name { visibility: visible; }
.pl.quiet:hover, .pl.quiet.peek { z-index: 4; }
.arrow { width: 16px; height: 10px; }

.hint { font-size: 18px; color: var(--muted); }
.swipe { font-size: 18px; color: var(--gold); text-align: center; }
.fbstrip { position: relative; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; font-size: 18px; color: var(--muted); }
.mini { min-height: 34px; padding: 0 10px; background: #17132f; color: var(--soft); border: 2px solid var(--line); font-size: 18px; }
.mini.on-up { background: var(--green); color: #000; }
.mini.on-down { background: var(--pink); color: #000; }
.fbpop { position: absolute; right: 0; bottom: 44px; z-index: 5; width: min(380px, 100%); padding: 14px; background: var(--panel); border: 4px solid #000; box-shadow: 0 0 0 2px var(--soft), 6px 6px 0 2px #000; display: flex; flex-direction: column; gap: 10px; color: var(--text); }
textarea, input[type=text] { width: 100%; padding: 8px 10px; background: var(--bg); color: var(--text); border: 2px solid var(--line); font-size: 20px; }
textarea { resize: none; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }

.btn { min-height: 44px; padding: 0 16px; background: var(--gold); color: #000; border: 4px solid #000; box-shadow: inset -4px -4px 0 #c9951a; font-size: 22px; }
.btn.ghost { background: var(--panel2); color: var(--muted); box-shadow: none; }
.btn.big { align-self: center; min-height: 56px; padding: 0 32px; font-size: 26px; box-shadow: inset -4px -4px 0 #c9951a, 4px 4px 0 #000; }

/* Chat */
.tabs { display: flex; border-bottom: 4px solid #000; }
.tab { flex: 1; min-height: 52px; border: 0; border-right: 4px solid #000; background: var(--panel2); color: var(--muted); font-size: 22px; }
.tab:last-child { border-right: 0; }
.tab.active { background: var(--gold); color: #000; }
.badge { padding: 0 5px; background: var(--pink); color: #000; }
.subtitle { padding: 8px 14px; background: #000; font-size: 18px; color: var(--muted); }
.peers { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 2px solid #000; }
.peer { min-height: 32px; padding: 0 8px; background: var(--panel2); color: var(--soft); border: 2px solid #000; font-size: 18px; }
.peer.active { background: var(--teal); color: #000; }
.peer.gone { opacity: .5; text-decoration: line-through; }
.msgs { flex: 1; min-height: 200px; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; gap: 2px; }
.msg .who { display: flex; align-items: center; gap: 6px; font-size: 18px; }
.msg .from { padding: 0; background: none; border: 0; font-size: 18px; color: inherit; text-decoration: underline dotted; }
.msg .from.me { text-decoration: none; cursor: default; }
.msg .rep { margin-left: auto; width: 26px; height: 24px; padding: 0; background: transparent; border: 2px solid var(--line); color: var(--muted); font-size: 16px; opacity: .6; }
.msg .rep:hover, .msg .rep:focus { opacity: 1; color: var(--pink); border-color: var(--pink); }
.msg .text { font-size: 22px; overflow-wrap: anywhere; }
.sys { font-size: 18px; color: var(--green); text-align: center; }
.sys.warn { color: var(--pink); }
.composer { display: flex; gap: 8px; padding: 12px 12px 6px; border-top: 4px solid #000; }
.composer input { height: 48px; border: 4px solid #000; outline: 2px solid var(--line); font-size: 22px; }
.foot { padding: 0 12px 10px; font-size: 16px; color: var(--muted); }

/* Dialogs */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8,6,24,.88); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.dialog { width: min(880px, 100%); padding: 22px 26px; background: var(--panel); border: 4px solid var(--gold); box-shadow: 0 0 0 4px #000, 12px 12px 0 4px #000; display: flex; flex-direction: column; gap: 16px; }
.dialog.narrow { width: min(560px, 100%); gap: 10px; }
.dialog h1 { margin: 0; font-size: 42px; font-weight: normal; color: var(--gold); text-shadow: 3px 3px 0 var(--pink), 6px 6px 0 #000; }
.dialog p { margin: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.x { width: 44px; height: 44px; flex-shrink: 0; background: var(--panel2); color: var(--text); border: 4px solid #000; font-size: 26px; }
.cols { display: flex; flex-wrap: wrap; gap: 24px; }
.cols > div { flex: 1 1 320px; display: flex; flex-direction: column; gap: 10px; }
.pill { align-self: flex-start; padding: 0 8px; color: #000; }
.pill.pink { background: var(--pink); } .pill.teal { background: var(--teal); }
.list, .guide { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: 21px; }
.list li { position: relative; padding-left: 20px; }
.list li::before { content: ''; position: absolute; left: 0; top: 7px; width: 10px; height: 10px; background: var(--gold); }
.list li.red { color: var(--pink); } .list li.red::before { background: var(--pink); }
.guide li { display: flex; gap: 10px; }
.guide b { flex-shrink: 0; height: 22px; padding: 0 6px; background: var(--gold); color: #000; font-weight: normal; }
.pinkt { color: var(--pink) !important; text-shadow: 3px 3px 0 #000 !important; }
.code { color: var(--gold); font-weight: normal; font-size: 28px; }
.muted { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; padding: 10px 18px; background: #000; border: 3px solid var(--gold); color: var(--gold); }

/* Laptop nhỏ: header gọn lại */
@media (max-width: 1400px) {
  .sub { display: none; }
  .logo { font-size: 40px; }
  .mebox { padding: 4px 12px; }
}

/* iPad dọc, cửa sổ thu nhỏ: bản đồ trên, chat dưới */
@media (max-width: 959px) {
  .main { flex-direction: column; align-items: stretch; }
  .left { flex: none; }
  .chat { flex: none; height: calc(100dvh - var(--head, 90px) - var(--maph, 500px) - 150px); min-height: 380px; max-height: none; }
  .online .lbl { display: none; }
}

/* Điện thoại: 1 màn hình 1 việc, chuyển bằng thanh dưới cùng */
@media (max-width: 640px) {
  html, body { font-size: 20px; }
  .top { padding: 8px 12px; gap: 8px 12px; }
  .logo { font-size: 30px; text-shadow: 3px 3px 0 var(--pink), 5px 5px 0 #000; }
  .anon { font-size: 17px; min-height: 36px; padding: 2px 8px; }
  .mebox { order: 5; width: 100%; padding: 4px 10px; box-shadow: none; border-width: 3px; }
  .me-nick { font-size: 22px; }
  .main { padding: 12px 12px 72px; gap: 12px; }
  .hint { display: none; }
  .app[data-view="map"] .chat { display: none; }
  .app[data-view="chat"] .left { display: none; }
  .chat { height: calc(100dvh - var(--head, 120px) - 96px); min-height: 360px; box-shadow: 0 0 0 3px var(--line); }
  .map-wrap { box-shadow: 0 0 0 3px var(--line); }
  .mobnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-top: 4px solid #000; background: var(--panel); padding-bottom: env(safe-area-inset-bottom); }
  .mobnav button { flex: 1; min-height: 56px; border: 0; background: var(--panel2); color: var(--muted); font-size: 24px; }
  .mobnav button + button { border-left: 4px solid #000; }
  .mobnav button.active { background: var(--gold); color: #000; }
  .tab { min-height: 46px; font-size: 20px; }
  .composer input { font-size: 16px; } /* tránh iPhone tự phóng to khi gõ */
  .fbstrip { justify-content: flex-start; }
  .dialog { padding: 16px; }
  .dialog h1 { font-size: 32px; }
  .list, .guide { font-size: 19px; }
}

/* ---- Báo cáo, danh sách nhắn riêng ---- */
.mini.danger { color: var(--pink); border-color: var(--pink); }
.mini.danger:hover { background: var(--pink); color: #000; }
.btn.danger { background: var(--pink); box-shadow: inset -4px -4px 0 #b83a64; }
.subtitle { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.subtitle .mini { min-height: 30px; font-size: 16px; flex-shrink: 0; }
.dmbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 2px solid #000; background: #17132f; }
.dmbar input { flex: 1 1 160px; height: 38px; font-size: 18px; }
.dmwith { color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sect { font-size: 16px; color: var(--muted); margin-top: 4px; }
.conv { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 10px; background: var(--panel2); border: 2px solid #000; color: var(--text); text-align: left; font-size: 20px; }
.conv:hover, .conv:focus-visible { border-color: var(--gold); }
.conv .cinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .last { font-size: 16px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .where { font-size: 16px; color: var(--muted); }
.conv.gone { opacity: .55; }
.msg .from:hover { text-decoration-style: solid; }
.replist { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 6px; background: var(--bg); border: 2px solid var(--line); }
.replist .conv { min-height: 40px; font-size: 19px; }
.replist .conv[aria-selected="true"] { background: var(--pink); color: #000; }
.replist .conv[aria-selected="true"] .where { color: #000; }
.reasons { border: 2px solid var(--line); padding: 8px 12px; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.reasons legend { padding: 0 6px; }
.reasons label { display: flex; align-items: center; gap: 6px; min-height: 32px; font-size: 20px; }
.reasons input { width: 18px; height: 18px; accent-color: var(--pink); }
