/* Part 7.5 — cross-device compatibility layer.
   Loaded last on every page. Only adds safe-area, input-modality,
   viewport and overflow rules; page skins keep their own identity. */

:root{
  --safe-top:env(safe-area-inset-top,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-left:env(safe-area-inset-left,0px);
  --safe-right:env(safe-area-inset-right,0px);
  --safe-x:max(var(--safe-left),var(--safe-right));
}

html{
  -webkit-text-size-adjust:100%;
  text-size-adjust:100%;
}
body{
  -webkit-tap-highlight-color:transparent;
}
/* class-based display rules must never resurrect a [hidden] element */
[hidden]{display:none!important}
button,a,summary,label,[role="button"],input,select,textarea{
  touch-action:manipulation;
}
img,video{
  max-width:100%;
}
::selection{background:rgba(var(--brand-rgb),.4)}

/* ---------- safe areas: page chrome ---------- */
.site-header{
  padding-top:calc(20px + var(--safe-top));
  padding-inline:max(40px,var(--safe-x));
}
.v8-header{
  padding-top:calc(13px + var(--safe-top));
  padding-inline:max(clamp(16px,3.4vw,40px),var(--safe-x));
}
.landing{
  padding-inline:max(40px,var(--safe-x));
  padding-bottom:calc(80px + var(--safe-bottom));
}
.profile-wrap{
  padding-inline:max(24px,var(--safe-x));
  padding-bottom:calc(80px + var(--safe-bottom));
}
.auth-wrap{
  min-height:calc(100vh - 84px);
  min-height:calc(100dvh - 84px - var(--safe-top));
  padding-inline:max(20px,var(--safe-x));
  padding-bottom:calc(60px + var(--safe-bottom));
}
.v8-auth-wrap{
  min-height:calc(100vh - 76px);
  min-height:calc(100dvh - 76px - var(--safe-top));
  padding-inline:max(40px,var(--safe-x));
  padding-bottom:calc(64px + var(--safe-bottom));
}
.site-footer{padding-bottom:var(--safe-bottom)}
.toast-wrap{top:calc(18px + var(--safe-top))}
.install-chip{
  bottom:calc(18px + var(--safe-bottom));
  inset-inline-start:calc(18px + var(--safe-x));
}
.modal-backdrop{
  padding-top:calc(20px + var(--safe-top));
  padding-bottom:calc(20px + var(--safe-bottom));
  padding-inline:max(20px,var(--safe-x));
}
.modal{
  max-height:calc(100dvh - 40px - var(--safe-top) - var(--safe-bottom));
  overflow-y:auto;
}

/* ---------- room shell: dynamic viewport + notch ---------- */
.page-room{height:100vh;height:100dvh}
.room-shell{
  height:100vh;
  height:100dvh;
  grid-template-rows:minmax(calc(var(--topbar-h) + var(--safe-top)),auto) minmax(0,1fr);
}
.topbar{
  padding-top:var(--safe-top);
  padding-inline:max(18px,var(--safe-x));
}
.stage{
  padding-left:max(14px,var(--safe-left));
  padding-right:max(14px,var(--safe-right));
}
.voice-dock{bottom:calc(18px + var(--safe-bottom))}
html[dir="ltr"] .voice-dock,[dir="ltr"] .voice-dock{transform:translateX(-50%)}

@media (max-width:640px){
  .site-header{
    padding-top:calc(16px + var(--safe-top));
    padding-inline:max(18px,var(--safe-x));
  }
  .v8-header{padding-inline:max(18px,var(--safe-x))}
  .landing{
    padding-inline:max(18px,var(--safe-x));
    padding-bottom:calc(60px + var(--safe-bottom));
  }
  .profile-wrap{
    padding-inline:max(14px,var(--safe-x));
    padding-bottom:calc(60px + var(--safe-bottom));
  }
  .v8-auth-wrap{
    padding-inline:max(18px,var(--safe-x));
    padding-bottom:calc(48px + var(--safe-bottom));
  }
  .room-shell{
    height:var(--vvh,100vh);
    height:var(--vvh,100dvh);
    grid-template-rows:minmax(calc(var(--topbar-h) + var(--safe-top)),auto) minmax(0,1fr) var(--sheet-h);
  }
  .page-room{--sheet-h:46dvh}
  .room-shell.chat-hidden{
    grid-template-rows:minmax(calc(var(--topbar-h) + var(--safe-top)),auto) minmax(0,1fr);
  }
  .page-room.chat-focus .room-shell{
    grid-template-rows:minmax(calc(var(--topbar-h) + var(--safe-top)),auto) minmax(0,1fr);
  }
  .topbar{padding:var(--safe-top) max(10px,var(--safe-x)) 0}
  .stage{
    padding-left:max(8px,var(--safe-left));
    padding-right:max(8px,var(--safe-right));
  }
  .sidebar{
    padding-left:max(0px,var(--safe-left));
    padding-right:max(0px,var(--safe-right));
  }
  .chat-form{padding-bottom:calc(2px + var(--safe-bottom))}
  .chat-fab{bottom:calc(10px + var(--safe-bottom))}
  .voice-dock{bottom:calc(12px + var(--safe-bottom))}

  /* the chat sheet owns the lower half: keep floating chrome above it */
  .page-room:has(.room-shell:not(.chat-hidden)) .voice-dock{
    bottom:calc(var(--sheet-h,46dvh) + 8px + var(--safe-bottom));
  }
  .page-room:has(.room-shell:not(.chat-hidden)) .install-chip{
    bottom:calc(var(--sheet-h,46dvh) + 12px + var(--safe-bottom));
  }
  .page-room.chat-focus .voice-dock{
    top:calc(var(--topbar-h) + var(--safe-top) + 8px);
    bottom:auto;
    z-index:45;
  }
  .page-room.chat-focus:has(.voice-dock:not(.hidden)) .sidebar{padding-top:60px}
  .page-room.chat-focus .install-chip{display:none}
}

@media (min-width:980px) and (max-width:1080px){
  .v8-auth-wrap{padding-inline:max(18px,var(--safe-x))}
}

@media (min-width:820px) and (max-width:1080px){
  .room-shell{
    grid-template-columns:minmax(0,1fr) clamp(260px,30vw,330px);
    grid-template-rows:minmax(calc(var(--topbar-h) + var(--safe-top)),auto) minmax(0,1fr);
  }
  .room-shell.chat-hidden{grid-template-columns:minmax(0,1fr) 0}
  .sidebar{
    position:static;
    inset:auto;
    width:auto;
    height:auto;
    transform:none;
    z-index:auto;
    border-inline-end:0;
    border-inline-start:1px solid var(--border);
    box-shadow:none;
    padding-top:0;
    grid-row:2;
    grid-column:2;
    overflow:hidden;
  }
  html[dir="ltr"] .sidebar{transform:none}
  .sidebar.open{transform:none}
  .side-toggle{display:grid}
  .stage-wrap{padding-bottom:0}
}

/* narrow two-pane sidebar: settings labels get their own row */
@media (min-width:820px) and (max-width:1000px){
  .pref-row{grid-template-columns:1fr 36px}
  .pref-row label{grid-column:1/-1}
}

/* off-canvas drawer: keep it clear of the notch in landscape */
@media (max-width:819px){
  .sidebar{
    padding-left:max(0px,var(--safe-left));
    padding-right:max(0px,var(--safe-right));
  }
}

/* ---------- touch: targets, hover alternatives, no accidental zoom ---------- */
@media (any-pointer:coarse){
  .icon-btn{width:42px;height:42px}
  .friend-remove,.mini-btn{width:34px;height:34px}
  .person-actions button{width:34px;height:34px}
  .msg-actions button{width:34px;height:34px}
  .chat-timer-btn{min-height:36px;min-width:34px}
  .chat-timer-reset{width:32px;height:32px}
  .link-btn{display:inline-block;min-height:32px;padding-block:6px}
  .accent-swatch{width:32px;height:32px}
  .chip{min-height:32px;padding-block:4px}
  .invite-btn{height:32px}
  .sheet-grip{height:28px}
  .emoji-btn,.send-btn{width:42px;height:42px}
  .react-tray button{width:40px;height:40px}
  .emoji-pop button{min-height:40px}
  .screen-ctl{width:32px;height:32px}
  .top-menu-item{min-height:44px}
  .tab{min-height:40px}
  .faq-item summary{min-height:44px;display:flex;align-items:center}

  /* touch devices (including hybrids) always get visible message/person actions */
  .person-actions{opacity:1}
  .msg-actions{
    display:flex;
    position:static;
    background:none;
    border:none;
    box-shadow:none;
    padding:0;
    margin-top:4px;
    opacity:.72;
  }
}

@media (any-pointer:coarse) and (max-width:640px){
  .icon-btn{width:40px;height:40px}
  /* the room topbar rule in style.css narrows these to 32px; keep tap targets usable */
  .page-room .topbar-right .icon-btn{width:40px;height:40px;border-radius:12px}
  .page-room .topbar-right{gap:0}
  .stage-controls .ctl{height:40px;min-width:34px}
  .invite-btn{height:32px}
  .chat-fab{height:44px}
}

@media (hover:hover) and (pointer:fine){
  .msg-actions{
    display:flex;
    opacity:0;
    pointer-events:none;
    transition:opacity .12s ease;
  }
  .msg:hover .msg-actions,
  .msg:focus-within .msg-actions{
    opacity:1;
    pointer-events:auto;
  }
  .person:focus-within .person-actions{opacity:1}
}

/* hybrids report both fine hover and coarse touch: touch must still win */
@media (any-pointer:coarse){
  .person-actions{opacity:1}
  .msg-actions{
    display:flex;
    position:static;
    opacity:.72;
    pointer-events:auto;
    background:none;
    border:none;
    box-shadow:none;
    padding:0;
    margin-top:4px;
  }
}

/* iOS zooms any focused field below 16px, which leaves the layout off-screen */
@media (pointer:coarse) and (max-width:1024px){
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="color"]),
  select,
  textarea{
    font-size:16px !important;
  }
  .chat-input-row input{font-size:16px !important}
}

/* ---------- long names, titles and messages ---------- */
.topbar-left,.room-code-row,.msg-head,.person-name,.friend-info,.entry-head,
.lobby-strip-main,.auth-perks li,.ofield,.ot-titles{min-width:0}
.chat-list,.people-list{overflow-x:hidden}
.nick,.person-name,.friend-info strong,.friend-user,.u-name,.lobby-copy h2,
.profile-identity h2,.profile-identity .muted,.recovery-code,.recovery-label,
.owner-top h1,.os-brand b,.os-brand span,.ocard h2{
  overflow-wrap:anywhere;
}
.recovery-code{word-break:break-all}
.top-menu{max-width:calc(100vw - 16px)}
.emoji-pop{max-height:min(60vh,360px)}

/* ---------- ultrawide: readable chat, centred content ---------- */
@media (min-width:1800px){
  .room-shell{grid-template-columns:minmax(0,1fr) clamp(340px,20vw,440px)}
  .stage{padding:20px}
}

/* ---------- short landscape phones: keep the actions above the fold ---------- */
@media (max-height:520px) and (orientation:landscape){
  .v8-hero{padding-top:18px;gap:20px}
  .v8-hero-visual{display:none}
  .v8-auth-wrap,.auth-wrap{padding-top:12px;min-height:auto}
  .owner-gate{place-items:start center;padding-top:calc(16px + var(--safe-top))}
  .modal-backdrop{place-items:start center;overflow-y:auto}
  .modal{max-height:none}
}

/* ---------- owner console safe areas ---------- */
.owner-body,.owner-gate,.owner-app{min-height:100vh;min-height:100dvh}
.owner-side{
  height:100vh;
  height:100dvh;
  padding-top:calc(22px + var(--safe-top));
  padding-bottom:calc(22px + var(--safe-bottom));
  padding-inline:max(16px,var(--safe-x));
}
.owner-top{
  padding-top:calc(16px + var(--safe-top));
  padding-inline:max(26px,var(--safe-x));
}
.owner-content{
  padding-inline:max(26px,var(--safe-x));
  padding-bottom:calc(60px + var(--safe-bottom));
}
@media (max-width:900px){
  .owner-top{
    padding-top:calc(13px + var(--safe-top));
    padding-inline:max(16px,var(--safe-x));
  }
  .owner-content{
    padding-inline:max(14px,var(--safe-x));
    padding-bottom:calc(48px + var(--safe-bottom));
  }
  .owner-side{max-height:100dvh}
}
@media (max-width:620px){
  .owner-side{padding-inline:max(16px,var(--safe-x))}
  .gate-card{max-height:none}
}

/* ---------- small phones: keep the room topbar on one line ---------- */
@media (max-width:380px){
  .topbar .invite-btn{width:34px;padding:0;justify-content:center}
  .topbar .invite-short{display:none}
  .topbar-left{gap:6px}
  .topbar-right{gap:0}
  .room-code-row{gap:4px}
  .room-meta h1{max-width:32vw}
}

/* ---------- Part 8: touch player extras ---------- */
@media (pointer:coarse){#video{touch-action:none}}
#video{transition:filter .12s linear}
.video-frame.buffering::after{
  content:"";position:absolute;inset:0;margin:auto;width:38px;height:38px;border-radius:50%;
  border:3px solid rgba(255,255,255,.2);border-top-color:#fff;
  animation:wtSpin .8s linear infinite;z-index:4;pointer-events:none;
}
@keyframes wtSpin{to{transform:rotate(360deg)}}
.gesture-hud{
  position:absolute;top:16px;left:50%;transform:translateX(-50%);z-index:8;
  display:flex;align-items:center;gap:9px;padding:9px 14px;border-radius:14px;min-width:158px;
  background:rgba(8,10,17,.84);border:1px solid rgba(255,255,255,.16);
  backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  color:#fff;font-size:12px;font-weight:700;pointer-events:none;
}
.gesture-hud.hidden{display:none}
.gh-icon svg{width:17px;height:17px;display:block}
.gh-bar{flex:1;height:5px;border-radius:99px;background:rgba(255,255,255,.18);overflow:hidden}
.gh-bar i{display:block;height:100%;width:0;background:var(--grad);border-radius:inherit;transition:width .08s linear}
.gh-val{min-width:36px;text-align:end;font-variant-numeric:tabular-nums}
.player-error{
  position:absolute;inset:0;z-index:6;display:grid;place-items:center;padding:20px;
  background:rgba(4,5,9,.84);backdrop-filter:blur(5px);-webkit-backdrop-filter:blur(5px);
}
.player-error.hidden{display:none}
.pe-box{
  width:100%;max-width:430px;text-align:center;padding:20px 18px;border-radius:16px;
  background:rgba(15,17,27,.96);border:1px solid var(--border-strong);box-shadow:0 24px 60px rgba(0,0,0,.6);
}
.pe-box h3{font-size:15px;margin-bottom:8px}
.pe-box p{font-size:12.5px;line-height:1.9;color:var(--text-dim)}
.pe-actions{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:14px}
#peCloseBtn{min-width:42px}
html[data-theme="light"] .pe-box{background:#fff;border-color:rgba(15,23,42,.14)}
html[data-theme="light"] .pe-box p{color:#475569}
.cap-off{opacity:.45}
.cap-off:hover{opacity:.62}
.cap-limited{opacity:.75}

/* ---------- Part 8: offline bar + safe update chip ---------- */
@keyframes obIn{from{opacity:0;transform:translate(-50%,8px)}to{opacity:1;transform:translate(-50%,0)}}
.offline-bar{
  position:fixed;left:50%;transform:translateX(-50%);
  bottom:calc(var(--sheet-h,0px) + 62px + env(safe-area-inset-bottom));
  z-index:94;display:flex;align-items:center;gap:10px;max-width:calc(100% - 24px);
  padding:10px 12px;border-radius:14px;font-size:12px;line-height:1.7;color:#ffe9c4;
  background:rgba(30,22,10,.95);border:1px solid rgba(245,178,62,.42);
  box-shadow:0 18px 40px rgba(0,0,0,.5);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  transition:opacity .24s,transform .24s;
}
.offline-bar.leaving{opacity:0;transform:translate(-50%,8px)}
.ob-icon svg{width:16px;height:16px;display:block;flex:none}
.ob-text{min-width:0}
.ob-retry{
  flex:none;border:none;border-radius:9px;padding:7px 11px;min-height:34px;
  background:rgba(245,178,62,.16);color:#ffd489;font:inherit;font-size:11.5px;font-weight:800;
  cursor:pointer;touch-action:manipulation;
}
.update-chip{
  position:fixed;left:50%;top:calc(env(safe-area-inset-top) + 72px);transform:translateX(-50%);
  z-index:94;display:flex;align-items:center;gap:10px;flex-wrap:wrap;justify-content:center;
  max-width:calc(100% - 24px);padding:9px 13px;border-radius:15px;font-size:12px;
  background:rgba(13,17,32,.97);border:1px solid rgba(var(--brand-rgb),.5);
  box-shadow:0 18px 44px rgba(0,0,0,.55);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);
  animation:obIn .22s ease;
}
.update-chip.hidden{display:none}
.uc-text{font-weight:700}
.update-chip .btn,.update-chip .link-btn{min-height:34px}
html[data-theme="light"] .update-chip{background:#fff;color:#0f172a;border-color:rgba(61,107,255,.4)}

/* hidden tab: no decorative animation work */
html[data-visibility="hidden"] *,
html[data-visibility="hidden"] *::before,
html[data-visibility="hidden"] *::after{animation-play-state:paused!important}
