/* UI Layer & Exit Fix v161
   One blocking dialog at a time, explicit layer hierarchy, and a visible match exit action. */
body.ui-layer-v161{
  --ui-z-hud:48;
  --ui-z-float:110;
  --ui-z-notice:180;
  --ui-z-modal:760;
  --ui-z-cinema:920;
  --ui-z-critical:1100;
}

/* The legacy reference theme hid the quit button completely. Restore it as a clear game action. */
.ui-layer-v161.reference-v120 .quit-btn{
  display:flex!important;
  position:fixed!important;
  top:18px!important;
  left:clamp(225px,17vw,305px)!important;
  right:auto!important;
  z-index:var(--ui-z-float)!important;
  height:48px!important;
  min-width:104px!important;
  padding:0 14px!important;
  align-items:center!important;
  justify-content:center!important;
  gap:7px!important;
  border:2px solid #f0c14a!important;
  border-radius:14px!important;
  background:linear-gradient(180deg,#6d2630,#3c101a)!important;
  color:#fff3c4!important;
  box-shadow:0 5px 0 #27090f,0 10px 22px #00101f80,inset 0 1px #ffffff24!important;
  font:900 11px Cairo,sans-serif!important;
  cursor:pointer!important;
}
.ui-layer-v161.reference-v120 .quit-btn:hover{filter:brightness(1.12);transform:translateY(-1px)}
.ui-layer-v161.reference-v120 .quit-btn:active{transform:translateY(3px);box-shadow:0 2px 0 #27090f,0 5px 12px #00101f66!important}
.ui-layer-v161.reference-v120 .quit-btn::before{content:"🚪";font-size:18px;line-height:1}

/* Also expose Exit in the familiar bottom utility strip. */
.ui-layer-v161 .ref-bottom-right .ref-quit-game-v161{
  border-color:#e7a346!important;
  background:linear-gradient(180deg,#702937,#3a111b)!important;
  box-shadow:0 4px 0 #280a10,0 8px 14px #00172866!important;
}
.ui-layer-v161 .ref-bottom-right .ref-quit-game-v161 i{color:#ffcf7c!important}

/* A deliberate hierarchy: supplementary cards must never sit above decision dialogs. */
.ui-layer-v161 .popup{z-index:var(--ui-z-modal)!important}
.ui-layer-v161 .rulebook{z-index:calc(var(--ui-z-modal) + 10)!important}
.ui-layer-v161 #marketCinema140{z-index:var(--ui-z-notice)!important}
.ui-layer-v161 .city-focus160,.ui-layer-v161 .city-route150{z-index:calc(var(--ui-z-notice) + 10)!important}
.ui-layer-v161 .property-reveal130{z-index:calc(var(--ui-z-notice) + 5)!important}
.ui-layer-v161 .cinematic-banner{z-index:var(--ui-z-notice)!important}
.ui-layer-v161 .cine-money-layer{z-index:calc(var(--ui-z-notice) + 20)!important}
.ui-layer-v161 .dice-cinema130{z-index:var(--ui-z-cinema)!important}
.ui-layer-v161 .victory-cinema130{z-index:calc(var(--ui-z-cinema) + 40)!important}
.ui-layer-v161 .vs-screen130{z-index:var(--ui-z-critical)!important}

/* Single-modal rule: while a real decision dialog is open, hide every secondary floating panel. */
body.ui-popup-open-v161 #marketCinema140,
body.ui-popup-open-v161 .city-focus160,
body.ui-popup-open-v161 .city-route150,
body.ui-popup-open-v161 .property-reveal130,
body.ui-popup-open-v161 .cinematic-banner,
body.ui-popup-open-v161 .market-ticker,
body.ui-popup-open-v161 .map-identity140,
body.ui-popup-open-v161 .map-shape150,
body.ui-popup-open-v161 .ref-mini-pop,
body.ui-popup-open-v161 .camera-dock,
body.ui-popup-open-v161 .camera-hint3d,
body.ui-popup-open-v161 .tile-lens3d,
body.ui-popup-open-v161 .emote-menu,
body.ui-popup-open-v161 .emote-fab,
body.ui-popup-open-v161 .classic-chat-shell,
body.ui-popup-open-v161 .cine-money-layer,
body.ui-popup-open-v161 #cityFocusCard{
  opacity:0!important;
  visibility:hidden!important;
  pointer-events:none!important;
}

/* Keep the online state available but move it behind the modal and mute it visually. */
body.ui-popup-open-v161 .online-badge{opacity:.18!important;pointer-events:none!important}

/* Modal itself: one clean card, never a second dialog peeking from behind it. */
.ui-layer-v161 .popup:not(.pick-board){
  background:rgba(0,17,29,.72)!important;
  backdrop-filter:blur(10px) saturate(.82)!important;
  padding:18px!important;
}
.ui-layer-v161 .popup:not(.pick-board)>.pop{
  max-height:min(82svh,720px)!important;
  overflow:auto!important;
  overscroll-behavior:contain;
  scrollbar-width:thin;
}
.ui-layer-v161 .popup>.pop::-webkit-scrollbar{width:7px}
.ui-layer-v161 .popup>.pop::-webkit-scrollbar-thumb{background:#b88734;border-radius:99px}

/* Auction should use the same cream modal language instead of appearing as a second navy window. */
.ui-layer-v161.reference-v120 .auction-pop,
.ui-layer-v161.reference-v120 .trade-pop{
  padding:7px 10px 12px;
  color:#4b3314!important;
}
.ui-layer-v161.reference-v120 .auction-pop .pop-icon,
.ui-layer-v161.reference-v120 .trade-pop .pop-icon{
  width:66px;height:66px;margin:0 auto 8px;display:grid;place-items:center;border-radius:20px;
  background:#fff7da;border:1px solid #d8ae57;font-size:30px;box-shadow:0 5px 12px #79541522;
}
.ui-layer-v161.reference-v120 .auction-pop h3,
.ui-layer-v161.reference-v120 .trade-pop h3{font-size:22px!important;margin:4px 0 7px!important;color:#5a3814!important}
.ui-layer-v161.reference-v120 .auction-pop p,
.ui-layer-v161.reference-v120 .trade-pop p{color:#6d4b20!important;margin:6px 0!important}
.ui-layer-v161.reference-v120 .auction-pop .actions,
.ui-layer-v161.reference-v120 .trade-pop .actions{display:grid!important;grid-template-columns:1fr 1fr!important;gap:9px!important;margin-top:12px!important}
.ui-layer-v161.reference-v120 .auction-pop .actions button,
.ui-layer-v161.reference-v120 .trade-pop .actions button{min-height:48px;border-radius:10px!important;font:900 12px Cairo,sans-serif!important}
.ui-layer-v161.reference-v120 .auction-pop .actions .ghost,
.ui-layer-v161.reference-v120 .trade-pop .actions .ghost{background:linear-gradient(#3ba5e7,#1575b8)!important;border:2px solid #0a568a!important;color:#fff!important;box-shadow:0 4px 0 #084e7c!important}

/* Custom exit confirmation — clear destructive action without browser confirm(). */
.quit-confirm-v161{padding:2px 4px 4px;text-align:center}
.quit-confirm-v161 .quit-icon-v161{width:76px;height:76px;margin:0 auto 8px;border-radius:24px;display:grid;place-items:center;font-size:34px;background:linear-gradient(#fff4d4,#f0d59a);border:1px solid #c58a2b;box-shadow:0 8px 18px #7d53192c}
.quit-confirm-v161 h3{font-size:24px!important;margin:4px 0 6px!important;color:#563412!important}
.quit-confirm-v161>p{font-size:12px!important;color:#6b4a24!important;line-height:1.7!important}
.quit-warning-v161{margin:10px 0!important;padding:9px 12px!important;border:1px dashed #c88a32!important;border-radius:12px!important;background:#fff8e6!important;color:#8b4f1e!important;font-weight:800!important}
.quit-actions-v161{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:13px;padding-top:12px;border-top:1px solid #d8b16c}
.quit-actions-v161 button{min-height:50px;border-radius:11px;font:900 12px Cairo,sans-serif;cursor:pointer}
.quit-actions-v161 .quit-cancel-v161{border:2px solid #0d5d91;background:linear-gradient(#45afea,#187aba);color:#fff;box-shadow:0 4px 0 #074a74}
.quit-actions-v161 .quit-confirm-btn-v161{border:2px solid #8e252f;background:linear-gradient(#d84f58,#9b2530);color:#fff;box-shadow:0 4px 0 #65141d}

/* Rulebook/major scenes also get exclusivity. */
body.ui-major-open-v161 .ref-mini-pop,
body.ui-major-open-v161 .camera-dock,
body.ui-major-open-v161 .emote-menu,
body.ui-major-open-v161 .classic-chat-shell{display:none!important}

@media (max-width:1320px){
  .ui-layer-v161.reference-v120 .quit-btn{left:220px!important;top:16px!important;min-width:90px!important;height:44px!important;font-size:10px!important}
  .ui-layer-v161.reference-v120 .quit-btn::before{font-size:16px}
}
@media (max-width:980px){
  /* Bottom utility strip is hidden on tablet/mobile, so the fixed exit remains visible. */
  .ui-layer-v161.reference-v120 .quit-btn{display:flex!important;top:5px!important;left:7px!important;min-width:74px!important;height:38px!important;padding:0 9px!important;border-radius:11px!important;font-size:9px!important}
  .ui-layer-v161.reference-v120 .quit-btn::before{font-size:14px}
}
@media (max-width:620px){
  .ui-layer-v161 .popup:not(.pick-board){padding:8px!important;align-items:center!important}
  .ui-layer-v161 .popup:not(.pick-board)>.pop{width:min(96vw,500px)!important;max-height:86svh!important;border-radius:13px!important}
  .quit-actions-v161{grid-template-columns:1fr}
  .ui-layer-v161.reference-v120 .auction-pop .actions,
  .ui-layer-v161.reference-v120 .trade-pop .actions{grid-template-columns:1fr!important}
}
@media (max-width:1420px) and (min-width:981px){
  .ui-layer-v161 .ref-bottom-right .ref-quit-game-v161{display:none!important}
}
