/* Desktop alignment and centered authentication — Bading Tambayan */
@media (min-width: 901px) {

  /* The real Lounge is anchored by #hangout and .hangout-layout.
     Keep the complete Lounge and every section on one centered desktop column. */
  #hangout,
  .hangout-layout {
    box-sizing: border-box;
    width: min(1280px, calc(100vw - 80px)) !important;
    max-width: 1280px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .hangout-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    justify-items: stretch;
    align-items: stretch;
    gap: 20px;
  }

  .hangout-layout > *,
  .hangout-layout .lounge-section,
  .hangout-layout .lounge-welcome,
  .hangout-layout #publicCommunity,
  .hangout-layout #onlineTambayan {
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /* Keep the live chat centered and full-width within the Lounge column. */
  #onlineTambayan {
    display: block;
    position: relative;
    left: auto !important;
    right: auto !important;
    float: none !important;
    width: min(1280px, calc(100vw - 80px)) !important;
    max-width: 1280px !important;
    margin: 30px auto 44px !important;
  }

  #onlineTambayan .online-panel,
  #onlineTambayan .online-room {
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  body {
    overflow-x: hidden;
  }

  #home.shell {
    width: min(100% - 64px, 1280px);
    max-width: 1280px;
    margin-inline: auto;
    padding: 28px 0 64px;
  }

  #home > section,
  #home > .section-heading,
  #home > .stats-grid,
  #home > .world-grid,
  #home > footer {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  /* Center the whole chat section and the opened room independently. */
  #onlineTambayan {
    display: block;
    box-sizing: border-box;
    position: relative;
    left: auto !important;
    right: auto !important;
    float: none !important;
    width: min(1280px, calc(100vw - 80px)) !important;
    max-width: 1280px !important;
    margin: 30px auto 44px !important;
    justify-self: center;
    align-self: center;
  }

  #onlineTambayan .online-panel,
  #onlineTambayan .online-room {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  #onlineTambayan .online-room {
    min-width: 0;
  }

  #onlineTambayan .online-panel {
    width: 100%;
    margin-inline: auto;
  }

  #onlineTambayan .online-room {
    width: 100%;
  }

  #onlineTambayan .online-columns {
    grid-template-columns: minmax(0, 2.25fr) minmax(230px, .75fr);
    align-items: stretch;
  }

  #onlineTambayan .online-box {
    min-width: 0;
  }

  #onlineTambayan .online-messages {
    height: clamp(420px, 58vh, 680px);
    min-height: 420px;
  }
}

/* Keep the login/welcome gate centered in the viewport, not at page top. */
#authGate {
  position: fixed !important;
  inset: 0 !important;
  min-height: 100vh;
  min-height: 100dvh;
  display: none;
  place-items: center !important;
  align-content: center !important;
  justify-content: center !important;
  padding: 28px 20px !important;
}

html.auth-locked #authGate,
html.auth-checking #authGate {
  display: grid !important;
}

#authGate .auth-gate-card {
  width: min(100%, 460px);
  margin: auto !important;
  align-self: center;
  justify-self: center;
}

/* Give the email/password login its own full-screen layer.
   It must not inherit the homepage's centered content layout. */
dialog#accountDialog {
  position: fixed !important;
  inset: 0 !important;
  box-sizing: border-box;
  width: min(460px, calc(100vw - 36px)) !important;
  max-width: 460px !important;
  height: fit-content;
  max-height: min(88vh, 760px);
  margin: auto !important;
  padding: 32px 28px !important;
  overflow-y: auto;
  z-index: 100000;
  border-radius: 24px;
  box-shadow: 0 28px 90px rgba(0,0,0,.6);
}

dialog#accountDialog::backdrop {
  background: rgba(8, 5, 20, .92);
  backdrop-filter: blur(12px);
}

/* Never leave a closed login dialog or its backdrop over the homepage. */
dialog#accountDialog:not([open]) {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

dialog#accountDialog[open] {
  visibility: visible;
  pointer-events: auto;
}

@media (max-width: 560px) {
  dialog#accountDialog {
    width: min(460px, calc(100vw - 24px)) !important;
    padding: 24px 18px !important;
  }
}

@media (max-width: 900px) {
  #home.shell {
    width: auto;
    max-width: 1180px;
    padding-left: 22px;
    padding-right: 22px;
  }
}


/* Fully remove the initial gate after session restoration.
   This prevents a translucent card/shadow from lingering over the homepage. */
/* Once session checking finishes without an account, replace the welcome gate
   with the real email/password dialog opened by multiplayer.js. */
html.auth-locked:not(.auth-checking) #authGate {
  display: none !important;
}

html:not(.auth-locked):not(.auth-checking) #authGate {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

html:not(.auth-locked):not(.auth-checking) #authGate .auth-gate-card {
  visibility: hidden !important;
  opacity: 0 !important;
  box-shadow: none !important;
}


/* Keep the welcome/login gate completely out of view while restoring a session.
   The page stays covered until auth finishes, without flashing the login card. */
html.auth-locked.auth-checking #authGate {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

html.auth-locked.auth-checking body::before {
  content: "Restoring your Tambayan... 💜";
  position: fixed;
  inset: 0;
  z-index: 100001;
  display: grid;
  place-items: center;
  padding: 24px;
  box-sizing: border-box;
  background: #100d20;
  color: #d0c5dc;
  font: 500 15px/1.5 system-ui, sans-serif;
  text-align: center;
}


/* TOUCH-DEVICE MOBILE MODE
   Android Chrome's "Desktop site" can report a wide CSS viewport even on a phone.
   Use the physical input capabilities as an additional signal so touch phones
   keep the mobile layout regardless of that browser toggle. */
@media (pointer: coarse) and (hover: none), (max-device-width: 900px) {
  html body {
    overflow-x: hidden !important;
  }

  html body .topbar {
    min-height: 62px !important;
    height: auto !important;
    padding: 9px 14px !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }

  html body .topbar .brand {
    font-size: 11px !important;
    gap: 7px !important;
  }

  html body .topbar .brand-mark {
    font-size: 25px !important;
  }

  html body .top-actions {
    gap: 6px !important;
    flex-wrap: wrap !important;
  }

  html body #home.shell,
  html body .shell {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 20px 14px 50px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  html body #home .hero,
  html body .hero {
    min-height: 0 !important;
    padding: 27px 22px !important;
  }

  html body .hero-copy {
    max-width: 100% !important;
  }

  html body .hero-orbit {
    position: absolute !important;
    right: -100px !important;
    bottom: -70px !important;
    opacity: .35 !important;
    transform: scale(.75) !important;
  }

  html body .stats-grid,
  html body #view-home > .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  html body .world-grid,
  html body #view-home .world-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 9px !important;
  }

  html body .game-grid,
  html body .tool-grid,
  html body .diary-layout,
  html body .hangout-layout,
  html body .shop-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html body .shop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html body .comfort-panel {
    padding: 20px !important;
    gap: 15px !important;
    align-items: flex-start !important;
  }

  html body .comfort-art {
    width: 65px !important;
    height: 65px !important;
    flex: 0 0 65px !important;
    font-size: 32px !important;
  }

  html body .section-heading {
    align-items: flex-start !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }

  html body #hangout,
  html body .hangout-layout,
  html body .hangout-layout > *,
  html body .hangout-layout #onlineTambayan,
  html body #onlineTambayan {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  html body .hangout-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html body #onlineTambayan .online-columns {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html body #onlineTambayan .online-room,
  html body #onlineTambayan .online-box,
  html body #onlineTambayan .online-messages {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  html body #onlineTambayan .online-messages {
    height: min(64vh, 620px) !important;
    min-height: 420px !important;
  }

  html body .diary-list-head {
    align-items: flex-start !important;
    flex-direction: column !important;
  }

  html body .diary-list-head input {
    width: 100% !important;
    max-width: none !important;
  }

  html body .theme-panel > div {
    align-items: flex-start !important;
    flex-direction: column !important;
  }

  html body .achievements-panel {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html body .hangout-form input:first-child,
  html body .hangout-form input:nth-child(2) {
    width: 100% !important;
    flex-basis: 100% !important;
  }

  html body #onlineTambayan .online-compose {
    width: 100% !important;
    max-width: 100% !important;
  }
}


/* JavaScript-detected touch phone mode.
   This remains active even if Android Chrome requests the desktop website. */
html.touch-mobile,
html.touch-mobile body {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
}
html.touch-mobile body .topbar {
  height: auto !important;
  min-height: 62px !important;
  padding: 9px 14px !important;
  gap: 8px !important;
  flex-wrap: wrap !important;
}
html.touch-mobile body .topbar .brand { font-size: 11px !important; gap: 7px !important; }
html.touch-mobile body .topbar .brand-mark { font-size: 25px !important; }
html.touch-mobile body .top-actions { gap: 6px !important; flex-wrap: wrap !important; }
html.touch-mobile body #home.shell,
html.touch-mobile body .shell {
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  padding: 20px 14px 50px !important;
  margin-inline: auto !important;
}
html.touch-mobile body .hero { min-height: 0 !important; padding: 27px 22px !important; }
html.touch-mobile body .hero-copy { max-width: 100% !important; }
html.touch-mobile body .hero-orbit {
  position: absolute !important; right: -100px !important; bottom: -70px !important;
  opacity: .35 !important; transform: scale(.75) !important;
}
html.touch-mobile body .stats-grid,
html.touch-mobile body #view-home > .stats-grid {
  grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 8px !important;
}
html.touch-mobile body .world-grid,
html.touch-mobile body #view-home .world-grid {
  grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 9px !important;
}
html.touch-mobile body .game-grid,
html.touch-mobile body .tool-grid,
html.touch-mobile body .diary-layout,
html.touch-mobile body .hangout-layout,
html.touch-mobile body .shop-layout {
  grid-template-columns: minmax(0,1fr) !important;
}
html.touch-mobile body .shop-grid { grid-template-columns: repeat(2,minmax(0,1fr)) !important; }
html.touch-mobile body .comfort-panel { padding: 20px !important; gap: 15px !important; align-items: flex-start !important; }
html.touch-mobile body .comfort-art { width: 65px !important; height: 65px !important; flex: 0 0 65px !important; font-size: 32px !important; }
html.touch-mobile body .section-heading { align-items: flex-start !important; gap: 8px !important; flex-wrap: wrap !important; }
html.touch-mobile body #hangout,
html.touch-mobile body .hangout-layout,
html.touch-mobile body .hangout-layout > *,
html.touch-mobile body .hangout-layout #onlineTambayan,
html.touch-mobile body #onlineTambayan {
  box-sizing: border-box !important; width: 100% !important; max-width: 100% !important;
  min-width: 0 !important; margin-left: auto !important; margin-right: auto !important;
}
html.touch-mobile body .hangout-layout { display: grid !important; grid-template-columns: minmax(0,1fr) !important; }
html.touch-mobile body #onlineTambayan .online-columns { grid-template-columns: minmax(0,1fr) !important; }
html.touch-mobile body #onlineTambayan .online-room,
html.touch-mobile body #onlineTambayan .online-box,
html.touch-mobile body #onlineTambayan .online-messages { min-width: 0 !important; max-width: 100% !important; }
html.touch-mobile body #onlineTambayan .online-messages { height: min(64vh,620px) !important; min-height: 420px !important; }
html.touch-mobile body .diary-list-head { align-items: flex-start !important; flex-direction: column !important; }
html.touch-mobile body .diary-list-head input { width: 100% !important; max-width: none !important; }
html.touch-mobile body .theme-panel > div { align-items: flex-start !important; flex-direction: column !important; }
html.touch-mobile body .achievements-panel { grid-template-columns: minmax(0,1fr) !important; }
html.touch-mobile body .hangout-form input:first-child,
html.touch-mobile body .hangout-form input:nth-child(2) { width: 100% !important; flex-basis: 100% !important; }
html.touch-mobile body #onlineTambayan .online-compose { width: 100% !important; max-width: 100% !important; }
html.touch-mobile body .world-card { min-width: 0 !important; }
html.touch-mobile body img, html.touch-mobile body video, html.touch-mobile body canvas { max-width: 100%; }
