:root {
  --ink: #f6efe2;
  --muted: #ccbda4;
  --glass: rgba(30, 22, 16, .66);
  --glass-strong: rgba(32, 23, 16, .95);
  --surface: rgba(255, 245, 225, .07);
  --surface-hover: rgba(233, 194, 122, .18);
  --line: rgba(233, 194, 122, .28);
  --line-strong: rgba(233, 194, 122, .56);
  --accent: #e9c27a;
  --accent-strong: #f4d38e;
  --lam: #5b86ab;
  --ok: #5bc27e;
  --danger: #e06b5c;
  --serif: "Lora", "Be Vietnam Pro", Georgia, serif;
  font-family: "Be Vietnam Pro", "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c150f; color: var(--ink); }

/* Chuẩn hóa mặc định cho MỌI nút bấm & ô nhập: chấm dứt hoàn toàn lỗi nền trắng chữ trắng trong mini-game */
button {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .15s, border-color .15s, color .15s, transform .12s, opacity .15s;
}
button:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--line-strong); color: var(--accent-strong); }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .48; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
input, select {
  font: inherit;
  color: var(--ink);
  background: rgba(20, 14, 10, .86);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}

/* Custom scrollbar đồng bộ tông nâu trà & vàng đồng */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: rgba(20, 14, 10, .35); border-radius: 99px; }
::-webkit-scrollbar-thumb { background: rgba(233, 194, 122, .35); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(233, 194, 122, .6); }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: rgba(24, 18, 12, .88); color: #f7efe2;
  border: 1px solid rgba(233, 194, 122, .42);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  will-change: transform;
}
.tag[data-badge]::before {
  content: attr(data-badge); margin-right: 6px; padding: 1px 6px; border-radius: 999px;
  background: #3d6b8c; color: #f6efe2; font-size: 10.5px; font-weight: 700;
  border: 1px solid rgba(233, 194, 122, .35);
}
.tag[style*="--team-color"] { border-left: 5px solid var(--team-color); }
.tag.npc { background: rgba(42, 31, 22, .72); color: #ebd5a7; font-weight: 500; }
.tag.speaking { z-index: 9; }
.chat-bubble {
  position: absolute; bottom: calc(100% + 9px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 230px; padding: 6px 11px; border-radius: 13px;
  background: rgba(252, 247, 236, .96); color: #261a10;
  border: 1px solid rgba(233, 194, 122, .78);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .42);
  font-size: 12.5px; font-weight: 600; line-height: 1.35; text-align: center;
  white-space: normal; word-break: break-word;
  opacity: 1; transition: opacity .3s ease, transform .2s ease;
  animation: bubble-pop .18s ease-out;
}
.chat-bubble::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: rgba(252, 247, 236, .96);
}
.chat-bubble.fading { opacity: 0; }
@keyframes bubble-pop { from { opacity: 0; transform: translate(-50%, 6px) scale(.94); } }

/* ── Cổng vào (#gate): đặt lệch sang trái trên màn hình rộng để thấy trọn nhân vật 3D đổi áo ngay giữa Sân Chùa ── */
.gate {
  position: fixed; inset: 0; display: grid; align-items: center; justify-items: center; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(24, 17, 12, .2), rgba(14, 10, 7, .64));
  z-index: 10;
}
@media (min-width: 860px) {
  .gate {
    justify-items: start;
    padding-left: clamp(28px, 6vw, 84px);
    background: linear-gradient(95deg, rgba(16, 11, 7, .74) 0%, rgba(16, 11, 7, .36) 44%, rgba(16, 11, 7, .06) 100%);
  }
}
.gate[hidden] { display: none; }
.gate-card {
  position: relative;
  width: min(390px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 26px 24px; border-radius: 22px; background: rgba(28, 20, 14, .94);
  border: 1px solid rgba(233, 194, 122, .36);
  box-shadow: 0 22px 52px rgba(0, 0, 0, .52), inset 0 1px 0 rgba(255, 240, 200, .14);
  text-align: center;
}
.gate-sound {
  position: absolute; top: 14px; right: 14px;
  min-width: 36px; min-height: 36px; padding: 0;
  border: 1px solid var(--line); background: rgba(255, 245, 225, .07);
}
.gate-emblem {
  display: inline-flex; align-items: center; gap: 7px; margin-bottom: 8px; padding: 4px 12px; border-radius: 999px;
  background: rgba(233, 194, 122, .11); border: 1px solid rgba(233, 194, 122, .26);
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; color: var(--accent);
}
.gate-emblem svg { width: 18px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.gate h1 { margin: 0 0 6px; font-family: var(--serif); font-size: 32px; font-weight: 700; letter-spacing: .03em; color: var(--accent-strong); }
.gate-tagline { margin: 0 0 14px; color: var(--muted); font-family: var(--serif); font-style: italic; font-size: 14px; line-height: 1.5; }
.gate-auth { margin: 0 0 12px; }
.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px; width: 100%;
  padding: 9px 14px; border-radius: 12px; text-decoration: none;
  background: #ffffff; color: #202124; font-size: 13.5px; font-weight: 600;
  border: 1px solid rgba(255, 255, 255, .85); box-shadow: 0 4px 12px rgba(0, 0, 0, .28);
  transition: filter .15s, transform .12s;
}
.google-btn:hover { filter: brightness(.95); }
.google-btn:active { transform: scale(.98); }
.google-btn svg { width: 18px; height: 18px; flex: none; }
.gate-user {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 11px; border-radius: 12px;
  background: rgba(91, 194, 126, .14); border: 1px solid rgba(91, 194, 126, .42);
}
.gate-user-email {
  font-size: 12.5px; color: #d6f5df; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gate-logout {
  flex: none; padding: 4px 10px; border-radius: 8px; font-size: 12px;
  border-color: rgba(233, 194, 122, .35); color: var(--muted);
}
.field { display: grid; gap: 6px; text-align: left; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field input, .field select { padding: 11px 13px; border-radius: 12px; font-size: 15px; width: 100%; }
.primary {
  width: 100%; padding: 12px 16px; border: 1px solid rgba(255, 236, 190, .5); border-radius: 13px;
  background: linear-gradient(180deg, #f0d598 0%, #cf9f52 100%); color: #24180e;
  font-weight: 700; font-size: 15.5px; box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
}
.primary:hover:not(:disabled) { filter: brightness(1.06); background: linear-gradient(180deg, #f4dca3 0%, #d6a75a 100%); color: #24180e; border-color: rgba(255, 240, 200, .7); }
.primary:disabled { opacity: .55; cursor: wait; }
.gate-hint { margin: 14px 0 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.outfits { border: 0; padding: 0; margin: 0 0 14px; }
.outfits legend { padding: 0; margin-bottom: 7px; }
.outfit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.outfit-btn {
  padding: 9px 10px; border-radius: 11px; font-size: 13px; font-weight: 600;
  background: rgba(255, 245, 225, .06); border: 1px solid var(--line); color: var(--ink);
  text-align: center;
}
.outfit-btn[aria-pressed="true"] {
  background: rgba(233, 194, 122, .24); border-color: var(--accent-strong);
  color: var(--accent-strong); box-shadow: 0 0 0 2px rgba(233, 194, 122, .28);
}
.gate-places { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.gate-places a { font-size: 13px; color: var(--ink); padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; }
.gate-places a[aria-current="page"] { background: rgba(233, 194, 122, .22); border-color: var(--accent); color: var(--accent); }

/* ── Thanh công cụ trên & dưới (Nâu trà trầm & vàng đồng cổ) ── */
.hud-top {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  pointer-events: none; z-index: 15;
}
.hud-top > * { pointer-events: auto; }
.hud-left { display: flex; align-items: center; gap: 8px; }
.pill {
  display: flex; align-items: center; gap: 9px; padding: 6px 14px; border-radius: 999px;
  background: rgba(28, 20, 14, .88); border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0, 0, 0, .34);
}
#room-btn b { font-family: var(--serif); font-size: 16px; color: var(--accent-strong); letter-spacing: .02em; }
.zone-pill { padding: 2px 9px; border-radius: 999px; background: rgba(233, 194, 122, .16); border: 1px solid rgba(233, 194, 122, .3); font-size: 12px; font-weight: 600; color: #f4e1ba; }
#room-btn small { color: var(--muted); padding-left: 9px; border-left: 1px solid var(--line); }
.tools { padding: 4px 6px; gap: 2px; }
.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 40px; min-height: 40px; padding: 0 11px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink);
}
.tool:hover:not(:disabled) { background: rgba(233, 194, 122, .16); color: var(--accent-strong); }
.tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.tool-label { font-size: 12.5px; font-weight: 600; }
[data-sound-toggle][aria-pressed="true"] .sound-mute { display: none; }
[data-sound-toggle][aria-pressed="false"] .sound-wave { display: none; }
[data-sound-toggle][aria-pressed="false"] { color: var(--muted); }
#fullscreen-btn[aria-pressed="false"] .fs-exit { display: none; }
#fullscreen-btn[aria-pressed="true"] .fs-enter { display: none; }
#fullscreen-btn[aria-pressed="true"] { color: var(--accent-strong); }

.hint {
  position: fixed; bottom: max(92px, calc(env(safe-area-inset-bottom) + 84px)); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 24px); margin: 0; padding: 6px 15px; border-radius: 999px;
  background: rgba(30, 22, 16, .76); border: 1px solid var(--line);
  text-align: center; font-size: 12.5px; color: var(--ink); pointer-events: none; transition: opacity .25s;
}
body:has(.spot-bar:not([hidden])) .hint { opacity: 0; }
.toast {
  position: fixed; top: max(66px, calc(env(safe-area-inset-top) + 54px)); left: 50%; transform: translateX(-50%);
  z-index: 25; margin: 0; padding: 7px 18px; border-radius: 999px;
  background: rgba(34, 24, 17, .92); border: 1px solid rgba(233, 194, 122, .45); color: var(--accent-strong);
  font-family: var(--serif); font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .38);
  opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap;
}
.toast.on { opacity: 1; }

/* ── Thanh Hành Động đáy gọn gàng: gom thanh ngữ cảnh & thanh chính trên cùng dải thấp để không che nhân vật ── */
.hud-bottom, .hud-actions {
  position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 16px); z-index: 14;
}
.hud-actions { display: flex; flex-wrap: nowrap; align-items: flex-end; justify-content: center; gap: 8px; }
.hud-bottom, .hud-bar {
  display: flex; gap: 3px; padding: 5px 7px; border-radius: 22px;
  background: rgba(28, 20, 14, .88); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  overflow-x: auto; max-width: calc(100vw - 16px); scrollbar-width: none;
}
.hud-bar::-webkit-scrollbar { display: none; }
.spot-bar { position: relative; border-color: rgba(233, 194, 122, .65); background: rgba(42, 30, 20, .82); animation: spot-in .22s ease-out; overflow: visible; }
.spot-bar::before {
  content: attr(data-name); position: absolute; bottom: calc(100% + 5px); left: 50%; transform: translateX(-50%);
  padding: 2px 11px; border-radius: 999px; background: rgba(32, 23, 16, .95);
  border: 1px solid rgba(233, 194, 122, .56); box-shadow: 0 4px 12px rgba(0, 0, 0, .36);
  font-family: var(--serif); font-size: 11.5px; font-weight: 600; color: var(--accent-strong); white-space: nowrap;
}
@keyframes spot-in { from { opacity: 0; transform: translateY(6px); } }
.hud-bottom[hidden], .hud-actions[hidden], .hud-bar[hidden], .hud-top[hidden], .hint[hidden] { display: none; }
.act {
  position: relative; display: grid; justify-items: center; gap: 2px; flex: 0 0 auto;
  min-width: 74px; padding: 7px 10px 6px; border: 0; border-radius: 16px;
  background: transparent; font-size: 12px; font-weight: 500;
}
.act:hover:not(:disabled) { background: rgba(233, 194, 122, .16); }
.act.cooling { opacity: .62; }
.act[data-wait]:not([data-wait=""])::after {
  content: attr(data-wait); position: absolute; top: 3px; left: 6px;
  padding: 1px 5px; border-radius: 999px; background: rgba(184, 58, 42, .92);
  color: #fff; font-size: 10px; font-weight: 700; line-height: 1.2;
}
.act[aria-pressed="true"] { background: rgba(233, 194, 122, .24); box-shadow: inset 0 0 0 1px rgba(233, 194, 122, .52); color: var(--accent-strong); }
.act .ico { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; color: var(--accent-strong); }
.act .ico svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.act kbd { position: absolute; top: 4px; right: 8px; font: 10px/1 inherit; color: var(--muted); }
.act .count { font-size: 10.5px; color: var(--accent); min-height: 1em; font-weight: 600; }

/* ── Trò chơi vòng tròn & Bảng Quản trò có nút thu gọn ── */
.tag.wrong { background: #b83a2a; color: #fff; border-color: #ff8a7a; }
.game-call {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%); margin: 0; padding: 10px 22px; border-radius: 16px;
  background: var(--glass-strong); border: 1px solid var(--line-strong);
  font-family: var(--serif); font-size: 21px; font-weight: 700; text-align: center; pointer-events: none; z-index: 16;
}
.game-call:empty { display: none; }
.game-call[data-kind="go"] { color: var(--accent-strong); }
.game-call[data-kind="trap"] { color: #ff8a7a; }
.game-harmony {
  position: fixed; top: 138px; left: 50%; transform: translateX(-50%);
  width: min(280px, 70vw); height: 8px; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--v, 0%), rgba(255, 255, 255, .15) var(--v, 0%));
}
.game-me { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); margin: 0; font-size: 13px; color: var(--ink); text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
.game-bar.off { opacity: .5; }
.game-bar .act[data-ok="true"] { background: rgba(91, 194, 126, .42); }
.game-bar .act[data-ok="false"] { background: rgba(224, 107, 92, .45); }
.game-answer { display: flex; gap: 8px; align-items: center; padding: 4px; }
.game-answer input { min-width: 180px; }
.game-answer .primary { width: auto; padding: 9px 16px; font-size: 14px; }

.host-panel {
  position: fixed; top: max(66px, calc(env(safe-area-inset-top) + 54px)); right: max(12px, env(safe-area-inset-right));
  width: 212px; max-width: calc(100vw - 24px); padding: 10px 12px; border-radius: 16px;
  background: rgba(28, 20, 14, .92); border: 1px solid var(--line); box-shadow: 0 10px 26px rgba(0, 0, 0, .42);
  font-size: 12.5px; z-index: 16;
}
.host-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.host-head b { font-family: var(--serif); font-size: 14px; color: var(--accent-strong); }
.host-toggle { width: 28px; height: 28px; padding: 0; border-radius: 8px; font-size: 16px; line-height: 1; display: inline-grid; place-items: center; }
.host-body { display: grid; gap: 6px; margin-top: 8px; }
.host-panel.collapsed { width: auto; padding: 7px 10px; }
.host-panel.collapsed .host-body { display: none; }
.host-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.host-panel select, .host-panel button:not(.host-toggle) { width: 100%; min-width: 0; padding: 7px 9px; font-size: 12.5px; }
.host-panel .primary { padding: 8px 10px; font-size: 13.5px; }
.host-panel label { display: grid; gap: 4px; color: var(--muted); }

/* ── Hộp thoại đồng bộ (Header cố định, nội dung cuộn mượt không cắt chữ) ── */
dialog[open] {
  display: flex; flex-direction: column;
  width: min(440px, calc(100vw - 24px)); max-height: 86dvh; padding: 18px 20px;
  border: 1px solid rgba(233, 194, 122, .38); border-radius: 20px;
  background: var(--glass-strong); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, .6);
  overflow: hidden;
}
dialog::backdrop { background: rgba(10, 7, 4, .72); }
dialog header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex: none; }
dialog h2 { margin: 0; font-family: var(--serif); font-size: 20px; color: var(--accent-strong); letter-spacing: .02em; }
dialog .close { font-size: 20px; line-height: 1; min-width: 36px; min-height: 36px; padding: 0; }
dialog ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; overflow-y: auto; }
dialog li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; background: var(--surface); border: 1px solid rgba(233, 194, 122, .14); }
dialog li button { all: unset; display: flex; justify-content: space-between; width: 100%; cursor: pointer; }
.room-new { margin-top: 12px; flex: none; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 10px; line-height: 1.45; flex: none; }

/* ── Bản đồ 2 cột: SVG đúng tỷ lệ dọc + Danh sách lọc tìm kiếm nhanh không trùng lặp ── */
dialog.map-dlg[open] { width: min(860px, calc(100vw - 24px)); max-height: 88dvh; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(240px, 0.92fr); gap: 16px; min-height: 0; flex: 1; overflow: hidden; }
.map-canvas-wrap { display: grid; place-items: center; min-height: 0; overflow: hidden; }
.map-svg {
  display: block; width: 100%; height: 100%; max-height: 64dvh; aspect-ratio: 3 / 4.3;
  border-radius: 16px; background: #263320; border: 1px solid rgba(233, 194, 122, .34);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, .4);
}
.map-sidebar { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.map-search { width: 100%; margin-bottom: 8px; padding: 9px 12px; font-size: 13.5px; flex: none; }
.map-svg .area { fill: #35462c; stroke: rgba(233, 194, 122, .3); stroke-width: .7; }
.map-svg .map-courtyard { fill: rgba(214, 198, 168, .22); stroke: rgba(233, 194, 122, .4); stroke-width: .6; stroke-dasharray: 2 1; }
.map-svg .zone-rect { stroke-width: .8; }
.map-svg .zone-sacred { fill: rgba(164, 62, 42, .56); stroke: #e9c27a; }
.map-svg .zone-study { fill: rgba(126, 82, 46, .52); stroke: #deb875; }
.map-svg .zone-camp { fill: rgba(74, 112, 62, .48); stroke: #a8cf8c; }
.map-svg .zone-water { fill: #245c58; stroke: #7ec8c2; }
.map-svg .map-roof-inner { fill: rgba(196, 78, 52, .48); stroke: #f2cf88; stroke-width: .5; pointer-events: none; }
.map-svg .zone-label { fill: rgba(248, 239, 222, .88); font-family: var(--serif); font-size: 5.4px; font-weight: 700; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #1a120b; stroke-width: 1.4px; }
.map-svg .map-paths path { fill: none; stroke: rgba(218, 202, 172, .65); stroke-width: 2.6; stroke-linecap: round; }
.map-svg .map-paths .map-axis { stroke: rgba(233, 194, 122, .82); stroke-width: 1.6; stroke-dasharray: 3 2; }
.map-svg .map-burner { fill: #c8963e; stroke: #f6efe2; stroke-width: .5; }
.map-svg .map-circle { fill: none; stroke: rgba(233, 194, 122, .5); stroke-width: .8; stroke-dasharray: 2.5 1.8; }
.map-svg .map-bridge { fill: #a2412c; stroke: #e9c27a; stroke-width: .6; }
.map-svg .pin { cursor: pointer; outline: none; }
.map-svg .pin circle { fill: var(--accent-strong); stroke: #24180e; stroke-width: .9; transition: r .15s, fill .15s; }
.map-svg .pin text { fill: #fff6e2; font-size: 5px; font-weight: 600; text-anchor: middle; paint-order: stroke; stroke: #1a120b; stroke-width: 1.5px; pointer-events: none; opacity: 0; transition: opacity .15s; }
.map-svg .pin:hover text, .map-svg .pin:focus-visible text { opacity: 1; }
.map-svg .pin:hover circle, .map-svg .pin:focus-visible circle { fill: #fff; r: 4.5; }
#map-me { fill: #ffe9a6; stroke: #c43c29; stroke-width: 1.3; }
.map-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; flex: none; }
.map-filters button { padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.map-filters button[aria-pressed="true"] { background: rgba(233, 194, 122, .24); border-color: var(--accent); color: var(--accent-strong); }
dialog .map-list { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; padding: 2px 4px 10px 0; overflow-y: auto; flex: 1; }
dialog .map-list li { padding: 0; background: none; border: 0; }
dialog .map-list button, .map-list a { display: inline-block; width: auto; cursor: pointer; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 13px; text-decoration: none; }
dialog .map-list button:hover, .map-list a:hover, dialog .map-list button[aria-pressed="true"] { background: rgba(233, 194, 122, .24); border-color: var(--accent); color: var(--accent-strong); }

/* ── Sổ tay Tu Học & Nhiệm vụ (Header + Tabs cố định, danh sách cuộn riêng) ── */
#quests-dlg[open] { width: min(620px, calc(100vw - 24px)); max-height: 86dvh; }
.quest-summary {
  padding: 9px 14px; border-radius: 12px; background: rgba(233, 194, 122, .12); border: 1px solid rgba(233, 194, 122, .28);
  font-family: var(--serif); color: var(--accent-strong); font-weight: 600; margin: 4px 0 8px; flex: none;
}
.quest-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 12px; flex: none; }
.quest-tabs button { flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.quest-tabs button[aria-pressed="true"] { background: rgba(233, 194, 122, .25); border-color: var(--accent); color: var(--accent-strong); }
.quest-list { display: grid; gap: 9px; overflow-y: auto; padding-right: 4px; flex: 1; min-height: 0; align-content: start; }
.quest { padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 245, 225, .04); }
.quest.done { border-color: rgba(233, 194, 122, .58); background: rgba(233, 194, 122, .1); }
.quest.upcoming { opacity: .65; }
.quest-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-family: var(--serif); font-size: 15.5px; }
.quest-head span { color: var(--accent-strong); white-space: nowrap; font-family: inherit; font-weight: 600; font-size: 13.5px; }
.quest p { margin: 5px 0 9px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.quest-progress { height: 6px; background: rgba(255, 245, 225, .12); border-radius: 99px; overflow: hidden; }
.quest-progress i { display: block; height: 100%; background: linear-gradient(90deg, #cf9f52, #f4d38e); border-radius: 99px; }
.quest-actions { display: flex; gap: 8px; margin-top: 9px; align-items: center; flex-wrap: wrap; }
.quest-actions button { padding: 6px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--accent-strong); background: rgba(233, 194, 122, .14); }
.quest-actions .quest-claim { background: linear-gradient(180deg, #f0d598, #cf9f52); color: #24180e; border-color: transparent; }
.quest-reward { margin-left: auto; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: rgba(91, 134, 171, .24); border: 1px solid rgba(126, 169, 204, .4); color: #c7e1f7; }
.quest-claimed { color: var(--ok); font-size: 12.5px; font-weight: 600; }

/* ── Thẻ chữ / câu kệ ── */
.card-text { margin: 10px 0 12px; text-align: center; line-height: 1.55; white-space: pre-line; }
.card-chu { font: 700 44px/1.2 var(--serif); color: #f3d68c; letter-spacing: .02em; }
.card-ke { font: italic 17px/1.6 var(--serif); }
.card-source { font-size: 12px; text-align: center; }

/* ── Mini-games (Semaphore SVG, Morse Keyer, Quiz, Thắt gút, Mật thư, Dấu đi đường, Bài học) ── */
.mini-dlg[open] { width: min(640px, calc(100vw - 24px)); max-height: 86dvh; }
.mini-dlg #mini-body { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding-right: 4px; flex: 1; min-height: 0; }
.mini-dlg #mini-status { margin: 8px 0 0; min-height: 1.3em; font-weight: 600; color: var(--accent-strong); flex: none; }
.mini-progress { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.mini-prompt { margin: 0; font-size: 15.5px; font-weight: 600; color: var(--ink); line-height: 1.5; }
.mini-form { display: grid; gap: 10px; margin: 4px 0; }
.mini-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mini-row > button { flex: 1 1 auto; min-height: 42px; font-weight: 600; }
.mini-choice {
  display: block; width: 100%; padding: 12px 14px; text-align: left;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 14.5px; line-height: 1.45;
}
.mini-choice.is-correct { background: rgba(91, 194, 126, .22); border-color: var(--ok); color: #d8fbe3; }
.mini-choice.is-wrong { background: rgba(224, 107, 92, .24); border-color: var(--danger); color: #ffe0dc; }

/* Semaphore SVG minh họa người cầm cờ & lưới chữ cái A–Z */
.sema-stage {
  display: grid; place-items: center; padding: 12px; border-radius: 16px;
  background: radial-gradient(circle at center, rgba(233, 194, 122, .1), rgba(20, 14, 10, .6));
  border: 1px solid var(--line);
}
.sema-svg { width: min(220px, 65vw); height: auto; display: block; }
.sema-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 7px; }
.sema-key { min-height: 44px; padding: 0; font-weight: 700; font-size: 15px; display: grid; place-items: center; border-radius: 10px; }
.sema-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sema-selects label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }

/* Morse & Mật thư & Thư viện */
.morse-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 24px; letter-spacing: .16em; text-align: center; padding: 10px 14px; border-radius: 12px; background: rgba(18, 13, 9, .78); border: 1px solid var(--line); color: var(--accent-strong); }
.morse-light { display: inline-block; width: 22px; height: 22px; border-radius: 50%; background: #3b332c; border: 2px solid var(--line); flex: none; transition: background .08s, box-shadow .08s; }
.morse-light.lit { background: #ffed79; border-color: #fff; box-shadow: 0 0 18px #ffed79, 0 0 6px #fff; }
.matthu-card { padding: 14px; margin: 0 0 10px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 245, 225, .04); display: grid; gap: 8px; }
.matthu-card h3 { margin: 0; font-family: var(--serif); font-size: 16px; color: var(--accent-strong); }
.matthu-card p { margin: 0; font-size: 14px; line-height: 1.55; }
.matthu-card small { color: var(--muted); font-size: 12px; }
.matthu-card img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; background: rgba(0, 0, 0, .3); }
.matthu-card form { display: flex; gap: 8px; flex-wrap: wrap; }
.matthu-card input { min-width: 140px; flex: 1; }
.matthu-card form .primary { width: auto; padding: 9px 18px; }
.knot-svg { width: 100%; max-height: 130px; border-radius: 12px; background: rgba(18, 13, 9, .65); border: 1px solid var(--line); }

/* ── Đoàn Quán: thanh xếp hàng / Quản đoàn, banner hiệu lệnh & hộp thoại 8 khung tranh ── */
.dq-banner {
  position: fixed; top: max(110px, calc(env(safe-area-inset-top) + 96px)); left: 50%; transform: translateX(-50%);
  z-index: 24; margin: 0; padding: 9px 22px; border-radius: 999px;
  background: rgba(34, 24, 16, .95); border: 1px solid rgba(233, 194, 122, .68);
  color: var(--accent-strong); font-family: var(--serif); font-size: 16px; font-weight: 700;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .48); pointer-events: none; white-space: nowrap;
}
.dq-bar {
  position: fixed; bottom: max(112px, calc(env(safe-area-inset-bottom) + 104px)); left: 50%; transform: translateX(-50%);
  z-index: 15; display: flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px;
  background: rgba(28, 20, 14, .92); border: 1px solid rgba(233, 194, 122, .45);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .42); max-width: calc(100vw - 20px); overflow-x: auto; scrollbar-width: none;
}
.dq-bar::-webkit-scrollbar { display: none; }
.dq-btn { flex: 0 0 auto; min-height: 36px; padding: 6px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.dq-btn.dq-primary { background: rgba(91, 134, 171, .32); border-color: rgba(145, 190, 228, .65); color: #e8f4ff; }
.dq-btn.dq-active { background: rgba(233, 194, 122, .26); border-color: var(--accent-strong); color: var(--accent-strong); }
.dq-sep { width: 1px; height: 22px; background: var(--line); flex: none; }

dialog.gallery-dlg[open] { width: min(560px, calc(100vw - 24px)); max-height: 88dvh; }
.gallery-preview-wrap {
  display: grid; place-items: center; margin-bottom: 10px; border-radius: 14px; overflow: hidden;
  background: rgba(14, 10, 7, .8); border: 1px solid var(--line); max-height: 44dvh; flex: none;
}
.gallery-preview-wrap img { display: block; max-width: 100%; max-height: 44dvh; object-fit: contain; }
.gallery-meta { margin: 0 0 10px; font-size: 13.5px; color: var(--accent-strong); font-weight: 500; }
.gallery-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.gallery-tools .danger-btn { border-color: rgba(224, 107, 92, .55); color: #ffb3a8; }
.gallery-status { margin: 8px 0 0; min-height: 1.2em; font-size: 13px; color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .map-layout { grid-template-columns: 1fr; overflow-y: auto; }
  .map-canvas-wrap { max-height: 38dvh; }
  .map-svg { max-height: 36dvh; }
  .map-sidebar { overflow: visible; }
  dialog .map-list { overflow: visible; }
}
@media (max-width: 640px) {
  .tool-label, .zone-pill { display: none; }
  .hud-actions { flex-direction: column; align-items: center; gap: 6px; }
}
@media (max-width: 520px) {
  .act { min-width: 62px; padding: 7px 7px 6px; font-size: 11.5px; }
  .act kbd { display: none; }
  #room-btn small { display: none; }
  .hint { bottom: 84px; font-size: 11.5px; }
  .game-call { top: 68px; font-size: 17px; }
  .game-harmony { top: 118px; }
  .host-panel { top: max(62px, calc(env(safe-area-inset-top) + 50px)); right: 8px; width: 184px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.cf-bar {
  bottom: max(124px, calc(env(safe-area-inset-bottom) + 116px));
}
.cf-bar .cf-ignite {
  background: linear-gradient(135deg, #c94618, #e87a1e);
  color: #fff8e8;
  border-color: rgba(255, 212, 128, 0.72);
  font-weight: 700;
}
.cf-bar .cf-firework {
  background: linear-gradient(135deg, #7d2c8f, #d95b2b);
  color: #fff6e0;
  border-color: rgba(255, 224, 140, 0.7);
}
.cf-bar .cf-torch {
  background: rgba(168, 86, 22, 0.88);
  color: #ffeab0;
  border-color: rgba(255, 198, 92, 0.65);
}

/* ── Khung Chat Phòng góc dưới bên trái ── */
.chat-box {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(304px, calc(100vw - 24px));
  z-index: 16;
  display: flex; flex-direction: column;
  border-radius: 16px;
  background: rgba(26, 19, 13, .9);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .46);
  overflow: hidden;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 5px 12px;
  border-bottom: 1px solid rgba(233, 194, 122, .16);
  background: rgba(36, 26, 18, .65);
}
.chat-head b { font-family: var(--serif); font-size: 13px; color: var(--accent-strong); letter-spacing: .01em; }
.chat-toggle {
  width: 24px; height: 24px; padding: 0; border-radius: 7px;
  font-size: 15px; line-height: 1; display: inline-grid; place-items: center;
}
.chat-list {
  list-style: none; margin: 0; padding: 7px 10px;
  height: 136px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12.5px; line-height: 1.38;
}
.chat-msg { color: var(--ink); word-break: break-word; }
.chat-msg b { color: var(--accent-strong); font-weight: 700; }
.chat-msg.me b { color: #91d5ff; }
.chat-sys { color: var(--muted); font-style: italic; font-size: 12px; }
.chat-form {
  display: flex; gap: 6px; padding: 6px 8px;
  border-top: 1px solid rgba(233, 194, 122, .16);
  background: rgba(18, 13, 9, .62);
}
.chat-form input {
  flex: 1; min-width: 0; padding: 6px 10px; border-radius: 10px;
  font-size: 12.5px; background: rgba(16, 11, 8, .9);
}
.chat-send {
  flex: none; padding: 6px 11px; border-radius: 10px;
  font-size: 12.5px; font-weight: 600;
  background: rgba(233, 194, 122, .2); border-color: rgba(233, 194, 122, .5); color: var(--accent-strong);
}
.chat-fab {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 16;
  width: 46px; height: 46px; padding: 0; border-radius: 999px;
  background: rgba(30, 22, 15, .92); border: 1px solid var(--line-strong);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .44);
  display: inline-grid; place-items: center; font-size: 19px;
}
.chat-unread {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #d9412e; color: #fff; font-size: 10.5px; font-weight: 700;
  display: inline-grid; place-items: center;
}
@media (max-width: 1120px) {
  .chat-box { bottom: max(92px, calc(env(safe-area-inset-bottom) + 84px)); }
}

/* ── Lớp nhắc xoay ngang điện thoại (#orientation-guard) ── */
.orientation-guard {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 13, 9, .95);
  text-align: center;
}
.orientation-card {
  width: min(360px, 100%);
  padding: 24px 20px;
  border-radius: 22px;
  background: rgba(30, 21, 15, .98);
  border: 1px solid var(--line-strong);
  box-shadow: 0 22px 54px rgba(0, 0, 0, .65);
  display: grid;
  gap: 12px;
  justify-items: center;
}
.orientation-icon {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: rgba(233, 194, 122, .14);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  animation: tilt-phone 2.2s ease-in-out infinite;
}
.orientation-icon svg {
  width: 36px;
  height: 36px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes tilt-phone {
  0%, 20% { transform: rotate(0deg); }
  55%, 80% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}
.orientation-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
  color: var(--accent-strong);
}
.orientation-card p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
}
.orientation-actions {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}
.ghost-btn {
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  background: rgba(255, 245, 225, .05);
  border-color: rgba(233, 194, 122, .22);
}

/* ── Cần gạt tròn 360° cảm ứng (#touch-joystick) ── */
.touch-joystick {
  position: fixed;
  left: max(18px, calc(env(safe-area-inset-left) + 12px));
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 10px));
  width: 116px;
  height: 116px;
  z-index: 16;
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.joy-base {
  position: relative;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(28, 20, 14, .48) 0%, rgba(22, 16, 11, .78) 100%);
  border: 2px solid rgba(233, 194, 122, .42);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .42), inset 0 0 14px rgba(233, 194, 122, .12);
  display: grid;
  place-items: center;
  transition: border-color .15s, transform .15s;
}
.joy-sprint-ring {
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px dashed rgba(244, 211, 142, 0);
  pointer-events: none;
  transition: border-color .15s, transform .15s;
}
.touch-joystick.active .joy-base {
  border-color: rgba(244, 211, 142, .75);
}
.touch-joystick.sprinting .joy-sprint-ring {
  border-color: rgba(255, 196, 86, .88);
  transform: scale(1.04);
}
.joy-stick {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #f7e1a8 0%, #cf9d4e 74%, #9c6e27 100%);
  border: 1.5px solid rgba(255, 246, 220, .85);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .5);
  will-change: transform;
  pointer-events: none;
}
.touch-joystick.sprinting .joy-stick {
  background: radial-gradient(circle at 35% 32%, #fff2c6 0%, #f09d38 72%, #b85618 100%);
}

/* ── Giao diện chuẩn Game Mobile Màn hình ngang (is-touch & chiều cao thấp <= 540px) — Desktop giữ nguyên 100% ── */
html.is-touch {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
html.is-touch input, html.is-touch textarea {
  user-select: text;
  -webkit-user-select: text;
  font-size: 16px; /* Ngăn iOS Safari tự phóng to lệch khung khi chạm ô nhập */
}
html.is-touch .act kbd {
  display: none;
}

/* Thanh trên gọn sát mép an toàn tai thỏ trên Mobile */
html.is-touch .hud-top {
  top: max(8px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
}
html.is-touch .pill {
  padding: 4px 11px;
  gap: 6px;
}
html.is-touch #room-btn b { font-size: 14.5px; }
html.is-touch .zone-pill { font-size: 11px; padding: 2px 7px; }
html.is-touch #room-btn small,
html.is-touch .tool-label {
  display: none;
}
html.is-touch .tools { padding: 2px 4px; }
html.is-touch .tool { min-width: 36px; min-height: 36px; padding: 0 8px; }

/* Mobile: Cụm nút Hành động chuyển sang GÓC DƯỚI BÊN PHẢI (ngay tầm ngón cái phải, không đụng Joystick trái, không che giữa màn hình) */
html.is-touch .hud-actions {
  left: auto;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: calc(100vw - 162px);
}
html.is-touch .hud-bar {
  padding: 4px 6px;
  border-radius: 18px;
  max-width: calc(100vw - 162px);
  touch-action: pan-x;
}
html.is-touch .spot-bar::before {
  left: auto;
  right: 8px;
  transform: none;
  font-size: 10.5px;
  padding: 1px 9px;
}
html.is-touch .act {
  min-width: 60px;
  min-height: 46px;
  padding: 5px 8px 4px;
  font-size: 11px;
  border-radius: 13px;
}
html.is-touch .act .ico { width: 18px; height: 18px; }
html.is-touch .act .ico svg { width: 17px; height: 17px; }

/* Mobile: Nút Chat 💬 & Khung Chat neo ở CẠNH TRÊN TRÁI (ngay dưới #room-btn) để không bao giờ đè lên Joystick và không bị bàn phím ảo che! */
html.is-touch .chat-fab {
  top: max(50px, calc(env(safe-area-inset-top) + 44px));
  bottom: auto;
  left: max(12px, env(safe-area-inset-left));
  width: 40px;
  height: 40px;
  font-size: 17px;
}
html.is-touch .chat-box {
  top: max(50px, calc(env(safe-area-inset-top) + 44px));
  bottom: auto;
  left: max(12px, env(safe-area-inset-left));
  width: min(296px, calc(100vw - 28px));
  z-index: 24;
}
html.is-touch .chat-list {
  height: 92px;
  font-size: 12px;
}
html.is-touch .chat-form input {
  padding: 5px 9px;
  font-size: 16px;
}

/* Mobile: Bảng Quản trò thu gọn góc trên phải (ngay dưới thanh công cụ) */
html.is-touch .host-panel {
  top: max(50px, calc(env(safe-area-inset-top) + 44px));
  right: max(12px, env(safe-area-inset-right));
  width: 196px;
  max-height: calc(100dvh - 62px);
  overflow-y: auto;
  z-index: 23;
}
html.is-touch .host-panel.collapsed {
  width: auto;
  padding: 6px 10px;
}

/* Mobile: Thanh ngữ cảnh Lửa Trại (#cf-bar) & Đoàn Quán (#dq-bar) thu mảnh đặt gọn sát cạnh trên giữa (giữa nút Chat & Quản trò) */
html.is-touch .dq-bar,
html.is-touch .cf-bar {
  top: max(50px, calc(env(safe-area-inset-top) + 44px));
  bottom: auto;
  padding: 4px 7px;
  gap: 5px;
  max-width: calc(100vw - 236px);
  touch-action: pan-x;
}
html.is-touch .dq-btn {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 11.5px;
}
html.is-touch .toast {
  top: max(90px, calc(env(safe-area-inset-top) + 84px));
  font-size: 12.5px;
  padding: 5px 14px;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
}
html.is-touch .dq-banner {
  top: max(90px, calc(env(safe-area-inset-top) + 84px));
  font-size: 13px;
  padding: 6px 15px;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
}
html.is-touch .hint {
  bottom: max(68px, calc(env(safe-area-inset-bottom) + 60px));
  font-size: 11px;
  padding: 4px 12px;
  max-width: calc(100vw - 170px);
}

/* Màn hình ngang chiều cao thấp (Mobile Landscape: height <= 520px) — tối ưu Cổng vào 2 cột & Hộp thoại không cần cuộn thừa */
@media (max-height: 520px) and (orientation: landscape) {
  .gate {
    justify-items: start;
    padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
    background: linear-gradient(95deg, rgba(16, 11, 7, .78) 0%, rgba(16, 11, 7, .38) 52%, rgba(16, 11, 7, .08) 100%);
  }
  .gate-card {
    width: min(540px, calc(100vw - 32px));
    max-height: calc(100dvh - 16px);
    padding: 12px 16px;
    border-radius: 18px;
  }
  .gate-emblem { margin-bottom: 3px; padding: 2px 9px; font-size: 9.5px; }
  .gate h1 { font-size: 21px; margin: 0 0 2px; }
  .gate-tagline { font-size: 12px; margin: 0 0 6px; line-height: 1.3; }
  .gate-auth { margin: 0 0 6px; }
  .google-btn { padding: 6px 12px; font-size: 12.5px; border-radius: 10px; }
  .gate-user { padding: 5px 10px; border-radius: 10px; }
  .gate-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 6px 12px;
    align-items: start;
  }
  .gate-form > .field:first-child { grid-column: 1; grid-row: 1; margin-bottom: 0; }
  .gate-form > .field[for="gate-team"] { grid-column: 1; grid-row: 2; margin-bottom: 0; }
  .gate-form > .outfits { grid-column: 2; grid-row: 1 / span 2; margin-bottom: 0; }
  .gate-form > #gate-enter { grid-column: 1 / -1; grid-row: 3; padding: 9px 14px; font-size: 14.5px; margin-top: 2px; }
  .field { gap: 3px; font-size: 12px; }
  .field input, .field select { padding: 7px 10px; font-size: 16px; border-radius: 10px; }
  .outfits legend { margin-bottom: 4px; font-size: 12px; }
  .outfit-grid { gap: 6px; }
  .outfit-btn { padding: 7px 8px; font-size: 12px; border-radius: 9px; }
  .gate-hint { display: none; }

  dialog[open] {
    max-height: 92dvh;
    padding: 12px 16px;
    border-radius: 16px;
  }
  dialog header { margin-bottom: 6px; }
  dialog h2 { font-size: 17px; }
  dialog .muted { font-size: 12px; margin-bottom: 6px; }

  dialog.map-dlg[open] {
    width: min(760px, calc(100vw - 24px));
    max-height: 92dvh;
  }
  .map-layout {
    grid-template-columns: minmax(0, 0.85fr) minmax(200px, 1.15fr);
    gap: 12px;
    overflow: hidden;
  }
  .map-canvas-wrap { max-height: 72dvh; }
  .map-svg { max-height: 70dvh; }
  .map-sidebar { overflow: hidden; }
  dialog .map-list { overflow-y: auto; }

  .sema-stage { padding: 6px; }
  .sema-svg { width: 112px; }
  .sema-grid { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 5px; }
  .sema-key { min-height: 36px; font-size: 13.5px; }
  .game-call { top: 48px; padding: 6px 16px; font-size: 16px; }
  .game-harmony { top: 90px; }
  .game-me { bottom: 68px; font-size: 12px; }
}

[hidden] { display: none !important; }
