/*
 * Veleno Mobile First V5
 * Final mobile usability layer. Loaded after all previous theme/mobile files.
 */
:root{
  --vm5-page-gap:clamp(12px,3.8vw,18px);
  --vm5-section-gap:clamp(14px,4vw,22px);
  --vm5-touch:52px;
  --vm5-radius:14px;
  --vm5-red:#e21b37;
  --vm5-bg:#050405;
}

@media (max-width:767px){
  html{width:100%;max-width:100%;overflow-x:hidden!important;scroll-padding-top:10px;}
  body.veleno-v8-body,body{
    width:100%;max-width:100%;min-width:0!important;
    margin:0!important;padding:0!important;
    overflow-x:hidden!important;
    overscroll-behavior-x:none;
  }

  /* Remove legacy empty bands before/around the header and banner. */
  body>header:first-of-type,
  body>.header:first-of-type,
  #header,.site-header,.page-header,.veleno-header,
  .navbar-necro-apocalypse,
  .navbar-necro-apocalypse>.container,
  .navbar-necro-apocalypse>.container-fluid{
    margin-top:0!important;padding-top:0!important;
  }
  .navbar-necro-apocalypse{top:0!important;}
  body>.navbar-necro-apocalypse+*,
  .navbar-necro-apocalypse+*,
  .veleno-header+*,.site-header+*{margin-top:0!important;padding-top:0!important;}
  .veleno-main-chamber>div[style*="clear:both"]:first-child,
  .veleno-main-chamber>div:first-child:empty,
  .veleno-main-chamber>p:empty{display:none!important;}
  .veleno-main-chamber>.visible-xs:empty{display:none!important;}

  /* Consistent page geometry. */
  body>.container,body>.container-fluid,
  .veleno-v8-body>.container,.veleno-v8-body>.container-fluid{
    width:100%!important;max-width:100%!important;
    margin:0!important;padding-inline:var(--vm5-page-gap)!important;
  }
  .row,.row-offcanvas{min-width:0!important;margin-inline:calc(var(--vm5-page-gap) * -1)!important;}
  .row>[class*="col-"],.row-offcanvas>[class*="col-"]{
    min-width:0!important;padding-inline:var(--vm5-page-gap)!important;
  }
  .veleno-main-chamber{
    width:100%!important;max-width:100%!important;min-width:0!important;
    float:none!important;left:auto!important;right:auto!important;
    margin:0!important;padding-top:0!important;
  }
  main,.main-content,#content,.content,.page-content{
    min-width:0!important;max-width:100%!important;
    margin-inline:0!important;padding-inline:0!important;
  }
  .panel,.card,.well,.jumbotron,.bl-panel,
  [class*="-card"],[class*="-panel"],[class*="-shell"]{
    max-width:100%;min-width:0;
  }
  .panel,.well,.bl-panel,.forum-directory-card,.forum-thread-card,.forum-message-card,
  .files-lib-card,.files-dir-card,.files-item{
    margin-bottom:var(--vm5-section-gap)!important;
  }
  .panel-body,.modal-body,.well,
  .forum-directory-card,.forum-thread-card,.forum-message-card,
  .files-lib-card,.files-dir-card,.files-item{
    padding:clamp(14px,4vw,20px)!important;
  }

  /* True fullscreen mobile menu, no side drawer residue. */
  .navbar-necro-apocalypse #navbar.navbar-collapse{
    position:fixed!important;inset:0!important;
    width:100vw!important;max-width:100vw!important;
    height:100dvh!important;max-height:100dvh!important;
    transform:translate3d(0,-12px,0)!important;
    opacity:0!important;visibility:hidden!important;pointer-events:none!important;
    padding:calc(82px + env(safe-area-inset-top))
            calc(var(--vm5-page-gap) + env(safe-area-inset-right))
            calc(26px + env(safe-area-inset-bottom))
            calc(var(--vm5-page-gap) + env(safe-area-inset-left))!important;
    overflow-x:hidden!important;overflow-y:auto!important;
    -webkit-overflow-scrolling:touch!important;
    background:radial-gradient(circle at 18% 0,rgba(145,0,26,.22),transparent 34%),linear-gradient(180deg,#070405 0%,#030303 100%)!important;
    transition:opacity .24s ease,transform .3s cubic-bezier(.2,.8,.2,1),visibility 0s linear .3s!important;
  }
  .navbar-necro-apocalypse #navbar.navbar-collapse.in,
  .navbar-necro-apocalypse #navbar.navbar-collapse.show,
  .navbar-necro-apocalypse #navbar.navbar-collapse.collapsing{
    transform:translate3d(0,0,0)!important;
    opacity:1!important;visibility:visible!important;pointer-events:auto!important;
    transition-delay:0s!important;
  }
  body.veleno-mobile-menu-open{position:fixed!important;inset:0!important;width:100%!important;overflow:hidden!important;}
  #navbar .veleno-cinema-menu-row{display:block!important;}
  #navbar .veleno-primary-menu,#navbar .veleno-auth-menu{gap:10px!important;}
  #navbar .navbar-nav>li>a,#navbar .dropdown-menu>li>a{
    min-height:var(--vm5-touch)!important;padding:13px 15px!important;
    border-radius:12px!important;font-size:15px!important;line-height:1.25!important;
  }
  #navbar .dropdown-menu{padding-left:10px!important;}
  #navbar .dropdown-menu>li>a{min-height:48px!important;}
  .navbar-necro-apocalypse .navbar-header{
    top:calc(10px + env(safe-area-inset-top))!important;
    left:calc(10px + env(safe-area-inset-left))!important;
  }
  .navbar-necro-apocalypse .navbar-toggle{
    width:56px!important;height:56px!important;min-width:56px!important;min-height:56px!important;
  }

  /* All 2x2 and custom grids become one column on narrow phones later. */
  .files-lib-grid,.files-dir-grid,.userlist-grid,.avatar-settings-grid,
  .avatar-chat-layout,[class*="grid-2"],[class*="two-column"],
  [style*="grid-template-columns"]{min-width:0!important;}

  /* Touch controls. Exclude tiny decorative/close controls. */
  button:not(.close):not(.veleno-mobile-close),
  input[type="button"],input[type="submit"],input[type="reset"],
  .btn,.files-btn,.avatar-chat-send,.avatar-chat-upload-button,
  .pagination>li>a,.pagination>li>span{
    min-height:var(--vm5-touch)!important;
    padding-block:12px!important;
    touch-action:manipulation;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,textarea,.form-control{
    min-height:48px!important;font-size:16px!important;
    max-width:100%!important;min-width:0!important;
  }
  textarea{min-height:120px!important;resize:vertical!important;}
  label{line-height:1.35;}
  .btn-group,.btn-toolbar,.form-inline,.form-horizontal .form-group{
    max-width:100%!important;min-width:0!important;
  }
  .btn-toolbar{display:flex!important;flex-wrap:wrap!important;gap:8px!important;margin:0!important;}
  .btn-toolbar:before,.btn-toolbar:after{display:none!important;}

  /* Prevent every remaining accidental overflow without clipping useful content. */
  img,svg,video,canvas,iframe,object,embed{max-width:100%!important;}
  img,video{height:auto;}
  iframe,object,embed{width:100%!important;}
  pre,code,.ansi,.terminal,.xterm,.xterm-screen,[class*="terminal"],[class*="console"]{
    max-width:100%!important;white-space:pre-wrap;overflow-wrap:anywhere;
  }
  pre,.ansi,.terminal,.xterm,[class*="terminal"],[class*="console"]{
    overflow:auto!important;-webkit-overflow-scrolling:touch!important;
  }
  p,li,td,th,a,span,h1,h2,h3,h4,h5,h6{overflow-wrap:anywhere;}
  [style*="width:"][style*="px"], [width]{max-width:100%!important;}
  [style*="min-width:"][style*="px"]{min-width:0!important;}

  /* Tables retain data structure and scroll naturally. */
  .table-responsive,.veleno-mobile-table-wrap{
    width:100%!important;max-width:100%!important;
    overflow-x:auto!important;overflow-y:visible!important;
    -webkit-overflow-scrolling:touch!important;
    border:0!important;margin-bottom:var(--vm5-section-gap)!important;
  }
  table{max-width:none;}
  .table-responsive>table,.veleno-mobile-table-wrap>table{min-width:620px!important;margin-bottom:0!important;}

  /* Modals, popups and windows: viewport-safe even with virtual keyboard. */
  .modal{padding:0!important;overflow-x:hidden!important;overflow-y:auto!important;}
  .modal-dialog,.avatar-settings-modal-dialog,.avatar-chat-modal-card,.avatar-chat-users-modal-card{
    width:auto!important;max-width:none!important;
    min-width:0!important;
    margin:calc(10px + env(safe-area-inset-top)) var(--vm5-page-gap) calc(10px + env(safe-area-inset-bottom))!important;
  }
  .modal-content,[role="dialog"],.popup,.dialog,.window{
    max-width:calc(100vw - (var(--vm5-page-gap) * 2))!important;
    max-height:calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom))!important;
    overflow:hidden!important;border-radius:var(--vm5-radius)!important;
  }
  .modal-body,.avatar-settings-modal-body{
    max-height:calc(100dvh - 150px - env(safe-area-inset-top) - env(safe-area-inset-bottom))!important;
    overflow-y:auto!important;-webkit-overflow-scrolling:touch!important;
  }
  .modal-header,.modal-footer{padding:14px!important;}
  .modal-footer{display:flex!important;flex-wrap:wrap!important;gap:8px!important;}
  .modal-footer .btn{flex:1 1 140px!important;margin:0!important;}

  /* Forum: readable cards, actions and editor on phone. */
  .forum-thread-card,.forum-message-card,.forum-directory-card{width:100%!important;}
  .forum-thread-title-row,.forum-message-title-row,.forum-sub-heading,
  .forum-thread-latest,.forum-message-meta-line{
    display:flex!important;flex-wrap:wrap!important;gap:8px!important;align-items:flex-start!important;
  }
  .forum-thread-avatar,.forum-message-avatar{flex:0 0 44px!important;width:44px!important;height:44px!important;}
  .forum-thread-body,.forum-item-content,.forum-thread-title-wrap,.forum-thread-latest-copy{
    flex:1 1 190px!important;min-width:0!important;
  }
  .forum-thread-stats,.forum-group-badges,.forum-sub-meta-badges,.forum-message-actions{
    display:flex!important;flex-wrap:wrap!important;gap:8px!important;width:100%!important;
  }
  .forum-message-actions .btn{flex:1 1 110px!important;}
  #forum-editor,.forum-editor,[class*="forum-compose"]{width:100%!important;max-width:100%!important;}

  /* File manager: single readable list and full-width actions. */
  .files-sort-bar,.files-item-header,.files-item-actions{
    display:flex!important;flex-wrap:wrap!important;gap:9px!important;align-items:center!important;
  }
  .files-item-name,.files-item-desc,.files-item-meta{min-width:0!important;width:100%!important;}
  .files-item-actions{width:100%!important;}
  .files-item-actions .files-btn,.files-item-actions .btn{flex:1 1 130px!important;}
  .files-preview,.files-preview-modal{max-width:100vw!important;}

  /* Avatar chat / chat: viewport-based layout, message area remains usable. */
  .avatar-chat-shell,.avatar-chat-web,.avatar-chat-main,.avatar-chat-content{
    width:100%!important;max-width:100%!important;min-width:0!important;
  }
  .avatar-chat-layout{display:flex!important;flex-direction:column!important;}
  .avatar-chat-sidebar{width:100%!important;max-width:100%!important;order:2;}
  .avatar-chat-chatpanel{width:100%!important;min-width:0!important;order:1;}
  .avatar-chat-messages,[class*="chat-messages"],#chat-messages{
    min-height:38dvh!important;max-height:56dvh!important;
    overflow-y:auto!important;-webkit-overflow-scrolling:touch!important;
  }
  .avatar-chat-compose-row,.avatar-chat-form,[class*="chat-compose"]{
    display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;gap:8px!important;
    width:100%!important;
  }
  .avatar-chat-input{min-width:0!important;width:100%!important;}
  .avatar-chat-send{min-width:56px!important;padding-inline:14px!important;}
  .avatar-chat-nav-actions,.avatar-chat-status-actions,.avatar-chat-compose-tools{
    display:flex!important;flex-wrap:wrap!important;gap:8px!important;
  }

  /* Terminal / telnet: avoid fixed desktop canvas dimensions. */
  #fTelnetContainer,#fTelnet,#terminal,.terminal-container,.web-terminal,
  [id*="terminal"],[class*="terminal-wrap"]{
    width:100%!important;max-width:100%!important;min-width:0!important;
    height:min(68dvh,620px)!important;min-height:360px!important;
    overflow:auto!important;-webkit-overflow-scrolling:touch!important;
  }
  #fTelnetContainer canvas,#fTelnet canvas,[class*="terminal"] canvas{
    max-width:none!important;transform-origin:top left;
  }

  /* Heavy atmosphere is desktop-only. */
  body.veleno-mobile-lite .fog,body.veleno-mobile-lite [class*="fog"],
  body.veleno-mobile-lite .particles,body.veleno-mobile-lite [class*="particle"],
  body.veleno-mobile-lite .rain,body.veleno-mobile-lite [class*="rain"],
  body.veleno-mobile-lite .smoke,body.veleno-mobile-lite [class*="smoke"],
  body.veleno-mobile-lite .scanlines,body.veleno-mobile-lite [class*="scanline"],
  body.veleno-mobile-lite .cinematic-overlay,
  body.veleno-mobile-lite #visualizer,body.veleno-mobile-lite canvas[data-effect]{display:none!important;}
  body.veleno-mobile-lite *,body.veleno-mobile-lite *::before,body.veleno-mobile-lite *::after{
    animation-duration:.001ms!important;animation-iteration-count:1!important;
    transition-duration:.14s!important;
  }
}

@media (max-width:479px){
  :root{--vm5-page-gap:12px;--vm5-section-gap:14px;--vm5-touch:54px;}
  .files-lib-grid,.files-dir-grid,.userlist-grid,.avatar-settings-grid,
  [class*="grid-2"],[class*="two-column"],
  [style*="grid-template-columns"]{
    display:grid!important;grid-template-columns:minmax(0,1fr)!important;
    gap:var(--vm5-section-gap)!important;
  }
  .row>[class*="col-xs-6"],.row>[class*="col-sm-6"],.row>[class*="col-md-6"],
  .row-offcanvas>[class*="col-xs-6"],.row-offcanvas>[class*="col-sm-6"]{
    width:100%!important;float:none!important;
  }
  .btn-group:not(.input-group-btn){display:flex!important;flex-direction:column!important;width:100%!important;}
  .btn-group:not(.input-group-btn)>.btn{width:100%!important;margin:0 0 8px!important;border-radius:10px!important;}
  .files-item-actions,.forum-message-actions{display:grid!important;grid-template-columns:1fr!important;}
  .files-item-actions .btn,.forum-message-actions .btn{width:100%!important;}
  h1{font-size:clamp(25px,8vw,36px)!important;}h2{font-size:clamp(22px,7vw,31px)!important;}
}

@media (max-width:359px){
  :root{--vm5-page-gap:9px;}
  .navbar-necro-apocalypse .navbar-header{top:8px!important;left:8px!important;}
  .navbar-necro-apocalypse .navbar-toggle{width:52px!important;height:52px!important;min-width:52px!important;min-height:52px!important;}
  .navbar-necro-apocalypse #navbar.navbar-collapse{padding-top:calc(70px + env(safe-area-inset-top))!important;}
}

@media (max-width:767px) and (orientation:landscape){
  .navbar-necro-apocalypse #navbar.navbar-collapse{padding-top:calc(66px + env(safe-area-inset-top))!important;}
  .avatar-chat-messages,[class*="chat-messages"],#chat-messages{min-height:45dvh!important;max-height:52dvh!important;}
  #fTelnetContainer,#fTelnet,#terminal,.terminal-container,.web-terminal,[id*="terminal"]{height:74dvh!important;min-height:260px!important;}
}

@media (prefers-reduced-motion:reduce){
  .navbar-necro-apocalypse #navbar.navbar-collapse{transition:none!important;}
}
