/* ══ AETERIA — THE GLASS SYSTEM (glass-ui.css) ═════════════════════════════
   One glassmorphism language for every surface: web gets depth (blur,
   layered translucency, floating panels); mobile gets a FLAT glass variant
   (cheap: no backdrop blur on phones — the GPU tax — tighter geometry,
   bottom sheets instead of floating drawers). Everything auto-fits:
   clamp() type, min()/max() sizing, safe-area insets, and hard
   max-width:100% so nothing can leave its frame.

   Loaded after tokens.css / aeteria.css; overrides are additive. */

:root {
  --g-radius: 16px;
  --g-radius-sm: 12px;
  --g-border: rgba(255, 255, 255, 0.10);
  --g-border-strong: rgba(255, 255, 255, 0.18);
  --g-fill: rgba(255, 255, 255, 0.045);
  --g-fill-hover: rgba(255, 255, 255, 0.08);
  --g-blur: 18px;
  --g-saturate: 140%;
  --g-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --g-shadow-sm: 0 10px 28px -14px rgba(0, 0, 0, 0.5);
  --g-accent: rgba(232, 100, 26, 0.55);
  --g-accent-bright: #ff9a4d;
  /* the auto-fit laws — every glass surface obeys */
  --g-safe-top: env(safe-area-inset-top, 0px);
  --g-safe-bottom: env(safe-area-inset-bottom, 0px);
  --g-safe-left: env(safe-area-inset-left, 0px);
  --g-safe-right: env(safe-area-inset-right, 0px);
}

:root[data-theme="light"] {
  --g-border: rgba(20, 16, 10, 0.10);
  --g-border-strong: rgba(20, 16, 10, 0.18);
  --g-fill: rgba(255, 255, 255, 0.55);
  --g-fill-hover: rgba(255, 255, 255, 0.75);
  --g-shadow: 0 18px 50px -20px rgba(92, 77, 48, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

/* ── the surfaces ─────────────────────────────────────────────────────────── */
.g-card, .g-panel, .g-bar, .g-dock, .g-sheet, .g-fab {
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: anywhere;
}
.g-card, .g-panel {
  background: var(--g-fill);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius);
  box-shadow: var(--g-shadow);
  backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  -webkit-backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
}
.g-bar {
  background: color-mix(in srgb, var(--g-fill) 80%, transparent);
  border: 1px solid var(--g-border);
  border-radius: 999px;
  box-shadow: var(--g-shadow-sm);
  backdrop-filter: blur(calc(var(--g-blur) * 0.75));
  -webkit-backdrop-filter: blur(calc(var(--g-blur) * 0.75));
}
.g-btn-glass {
  background: var(--g-fill);
  border: 1px solid var(--g-border);
  border-radius: 999px;
  color: inherit;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.g-btn-glass:hover, .g-btn-glass:focus-visible { background: var(--g-fill-hover); border-color: var(--g-border-strong); }
.g-btn-glass:active { transform: scale(0.97); }
.g-chip-glass {
  background: var(--g-fill);
  border: 1px solid var(--g-border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── the mobile bottom tab bar (built by nav.js) ──────────────────────────── */
#glassTabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + var(--g-safe-bottom));
  z-index: 70;
  display: none;
  width: min(520px, calc(100vw - 20px));
  padding: 6px;
  gap: 2px;
}
#glassTabbar .tab {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px 6px;
  border-radius: 14px;
  color: var(--text-tertiary, #b9b2a8);
  text-decoration: none;
  font-size: clamp(10px, 2.6vw, 12px);
  letter-spacing: 0.01em;
  transition: color 0.15s ease, background 0.15s ease;
}
#glassTabbar .tab .tab-ic { font-size: 19px; line-height: 1; }
#glassTabbar .tab.active { color: var(--g-accent-bright); background: var(--g-fill-hover); }
#glassTabbar .tab .tab-lb { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the fit guard may strip labels when the bar is too tight */
#glassTabbar.g-overflow .tab .tab-lb { display: none; }
#glassTabbar.g-overflow .tab .tab-ic { font-size: 22px; }

/* ── THE MOBILE VARIANT — flat glass, bottom sheets, thumb reach ─────────── */
@media (max-width: 860px), (pointer: coarse) and (max-width: 1024px) {
  :root {
    --g-blur: 0px;              /* no backdrop blur on phones — the GPU law */
    --g-radius: 14px;
    --g-shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  }
  /* THE TAB BAR BECOMES VISIBLE — display:none on desktop, flex on phones
     (this flip was missing once and the whole mobile navigation vanished
     behind an 86px dead band — the "mobile site is broken" bug) */
  #glassTabbar {
    display: flex;
    align-items: stretch;
  }
  .g-card, .g-panel, .g-bar, .g-sheet { box-shadow: var(--g-shadow-sm); }
  /* sheets rise from the thumb line, full-width, safe-area aware */
  .g-sheet {
    position: fixed;
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: calc(8px + var(--g-safe-bottom)) !important;
    width: auto !important;
    max-height: min(72dvh, 640px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* the tab bar owns the bottom; the page yields */
  body[data-g-tabbar="on"] { padding-bottom: calc(86px + var(--g-safe-bottom)) !important; }
  /* nothing leaves the frame on a phone */
  .g-card, .g-panel, .g-bar, img, video, canvas, iframe { max-width: 100% !important; }
  h1 { font-size: clamp(30px, 8.5vw, 42px); }
  h2 { font-size: clamp(20px, 5.5vw, 26px); }
  p, li, .t-13 { font-size: clamp(13px, 3.6vw, 15px); }
  .g-tap { min-height: 44px; min-width: 44px; }   /* the thumb law */
}

/* ── THE FIT GUARD HOOKS — ui-guards.js toggles these ────────────────────── */
[data-g-fit].g-overflow { font-size: 0.86em; letter-spacing: -0.01em; }
[data-g-fit].g-overflow .g-shrinkable { display: none; }
.os-statusbar.g-overflow .os-status-phase { display: none; }
.os-statusbar.g-overflow .os-status-credits { display: none; }
.rail.g-overflow .rail-label { display: none; }

/* ── THE CHAT, ON A PHONE — minimal, one column, no stage ─────────────────── */
@media (max-width: 860px) {
  body[data-page="resident"] #stage-slot,
  body[data-page="resident"] #stage-slot ~ *,
  body[data-page="resident"] .stage-toolbar { display: none !important; }
  body[data-page="resident"] .chat-shell,
  body[data-page="resident"] .room {
    display: flex !important;
    flex-direction: column !important;
    min-height: 0;
  }
  body[data-page="resident"] #feed {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none !important;
    height: auto;
    padding: 10px 10px 4px;
  }
  body[data-page="resident"] .composer,
  body[data-page="resident"] #composer {
    position: sticky;
    bottom: calc(0px + var(--g-safe-bottom));
    padding: 8px 8px 10px;
    background: linear-gradient(to top, var(--ground, #0a0a0a) 70%, transparent);
    border: 0;
  }
  body[data-page="resident"] .composer textarea,
  body[data-page="resident"] #input {
    font-size: 16px;             /* the iOS zoom law: 16px prevents jump */
    min-height: 44px;
  }
  body[data-page="resident"] #btn-send { min-width: 48px; min-height: 48px; }
  body[data-page="resident"] .msg { padding: 8px 12px; margin: 3px 0; border-radius: 16px; }
}

/* ══ THE TABLET, REGLAZED — the OS shell in the site's glass ════════════════ */
body[data-page="tablet"] .os-statusbar {
  background: var(--g-fill);
  border: 1px solid var(--g-border);
  border-radius: 999px;
  box-shadow: var(--g-shadow-sm);
  backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  -webkit-backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  padding: 8px 16px;
  gap: 12px;
  max-width: 100%;
}
body[data-page="tablet"] .os-statusbar .os-status-name { font-weight: 700; }
body[data-page="tablet"] .os-dock {
  background: var(--g-fill);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius);
  box-shadow: var(--g-shadow);
  backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  -webkit-backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  padding: 10px 14px;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
body[data-page="tablet"] .os-dock::-webkit-scrollbar { display: none; }
body[data-page="tablet"] .liquid-drawer-overlay {
  background: rgba(4, 3, 2, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
body[data-page="tablet"] .liquid-drawer-header { border-bottom: 1px solid var(--g-border); }
body[data-page="tablet"] .rail {
  background: var(--g-fill);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius);
  box-shadow: var(--g-shadow-sm);
  backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  -webkit-backdrop-filter: blur(var(--g-blur)) saturate(var(--g-saturate));
  padding: 10px 8px;
  gap: 6px;
}
body[data-page="tablet"] .rail-btn {
  border-radius: var(--g-radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}
body[data-page="tablet"] .rail-btn.active {
  background: var(--g-fill-hover);
  color: var(--g-accent-bright);
}

/* the tablet on a phone: the dock rides above the tab bar, the drawer
   becomes a bottom sheet, the split console stacks */
@media (max-width: 860px) {
  body[data-page="tablet"] .os-home { padding-bottom: calc(96px + var(--g-safe-bottom)); }
  body[data-page="tablet"] .os-dock {
    position: sticky;
    bottom: calc(96px + var(--g-safe-bottom));
    z-index: 30;
    flex-wrap: nowrap;
  }
  body[data-page="tablet"] .liquid-drawer-overlay .liquid-drawer,
  body[data-page="tablet"] #liquidGlassDrawer > *:first-child {
    margin: auto 8px calc(8px + var(--g-safe-bottom));
    max-height: min(76dvh, 660px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  body[data-page="tablet"] #splitConsoleView { flex-direction: column !important; }
  body[data-page="tablet"] #splitConsoleView .rail {
    flex-direction: row !important;
    overflow-x: auto;
    scrollbar-width: none;
  }
  body[data-page="tablet"] #splitConsoleView .rail::-webkit-scrollbar { display: none; }
  body[data-page="tablet"] #smoke { display: none !important; }   /* the decorative haze rests on phones */
}
