:root {
  --bg: #0f1013;
  --surface: rgba(24,25,29,.96);
  --surface-2: #1c1e23;
  --surface-3: #252830;
  --line: rgba(255,255,255,.09);
  --text: #f5f6f7;
  --muted: #9fa3ad;
  --accent: #7b8cff;
  --accent-2: #9d6cff;
  --incoming: #282b32;
  --danger: #ff5d73;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="light"] {
  --bg: #f3f4f7;
  --surface: rgba(255,255,255,.96);
  --surface-2: #fff;
  --surface-3: #e9ebf1;
  --line: rgba(30,35,50,.10);
  --text: #15171b;
  --muted: #737987;
  --accent: #5f70f5;
  --accent-2: #7d55df;
  --incoming: #e8eaf0;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden; color: var(--text); background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.gate {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  padding: calc(24px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  background: radial-gradient(circle at 50% 10%, rgba(123,140,255,.22), transparent 32%), var(--bg);
}
.gate-card {
  width: min(100%, 420px); max-height: 90vh; overflow-y: auto;
  padding: 28px; border: 1px solid var(--line); border-radius: 26px;
  background: var(--surface); box-shadow: 0 28px 90px rgba(0,0,0,.28);
}
.brand-mark {
  width: 64px; height: 64px; display: grid; place-items: center;
  margin-bottom: 20px; border-radius: 20px; color: white; font-size: 28px; font-weight: 800;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
}
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 1px; }
.gate-card h1 { margin: 0 0 8px; font-size: 29px; letter-spacing: -.7px; }
.gate-card form, .dialog-card { display: grid; gap: 15px; }
label { display: grid; gap: 7px; font-size: 14px; font-weight: 680; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; outline: none; background: var(--surface-2); font-size: 16px;
}
input:focus, textarea:focus, select:focus { border-color: rgba(123,140,255,.65); box-shadow: 0 0 0 3px rgba(123,140,255,.12); }
textarea { resize: none; }
.error { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }
.primary {
  border: 0; border-radius: 12px; padding: 12px; color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 750;
}
.primary.compact { width: auto; padding: 10px 14px; }
.secondary, .danger-outline, .link-button, .text-button { border: 0; background: transparent; }
.secondary, .danger-outline { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 12px; font-weight: 680; }
.danger-outline { color: var(--danger); }
.link-button, .text-button { color: var(--accent); font-weight: 700; }
.link-button { width: 100%; padding: 15px 6px 5px; }

.app { height: 100dvh; display: grid; grid-template-columns: 260px 1fr; }
.mobile-header { display: none; }
.sidebar {
  display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: var(--surface); backdrop-filter: blur(24px);
}
.sidebar-header { padding: calc(20px + var(--safe-top)) 18px 14px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-header h2 { margin: 0; font-size: 28px; letter-spacing: -.7px; }
.nav-list { display: grid; gap: 6px; padding: 8px 12px; }
.nav-item {
  width: 100%; border: 0; border-radius: 12px; padding: 12px 13px;
  text-align: left; background: transparent; color: var(--muted); font-weight: 680;
}
.nav-item.active { color: var(--text); background: var(--surface-3); }
.sidebar-bottom { margin-top: auto; padding: 12px 12px calc(12px + var(--safe-bottom)); }
.icon-button, .back-button { border: 0; background: transparent; color: var(--accent); min-width: 42px; min-height: 42px; font-size: 19px; }

.main-shell { min-width: 0; height: 100%; overflow: hidden; }
.view { display: none; height: 100%; overflow-y: auto; }
.active-view { display: block; }
.topbar, .page-header { padding: calc(28px + var(--safe-top)) 24px 18px; display: flex; align-items: center; justify-content: space-between; }
.topbar h1, .page-header h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -1.1px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; padding: 0 24px; }
.dash-card {
  min-height: 150px; padding: 20px; border: 1px solid var(--line); border-radius: 22px;
  text-align: left; background: var(--surface); display: flex; flex-direction: column; justify-content: flex-end; gap: 8px;
}
.primary-card { background: linear-gradient(145deg, rgba(123,140,255,.96), rgba(157,108,255,.92)); color: white; }
.card-kicker { font-size: 11px; letter-spacing: 1px; font-weight: 800; opacity: .72; }
.dash-card strong { font-size: 23px; letter-spacing: -.5px; }
.dash-card span:last-child { opacity: .72; }
.neutral-card:hover { background: var(--surface-3); }
.recent-panel { margin: 22px 24px 40px; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.section-heading { display: flex; justify-content: space-between; align-items: center; }
.section-heading h3 { margin: 0; }
.recent-list, .activity-list { margin-top: 14px; display: grid; gap: 10px; }
.recent-item, .activity-item {
  width: 100%; padding: 13px; border: 0; border-radius: 13px;
  text-align: left; background: var(--surface-3);
}
.recent-item strong, .activity-item strong { display: block; }
.recent-item span, .activity-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }

.workspace-view { overflow: hidden; }
.workspace-layout { height: 100%; display: grid; grid-template-columns: 330px 1fr; }
.conversation-pane { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); }
.pane-header { padding: calc(20px + var(--safe-top)) 16px 12px; display: flex; align-items: center; justify-content: space-between; }
.pane-header h2 { margin: 0; font-size: 27px; }
.session-search { margin: 0 12px 10px; width: calc(100% - 24px); }
.conversation-list { flex: 1; overflow-y: auto; }
.conversation-item {
  width: 100%; display: flex; gap: 11px; padding: 11px 14px;
  border: 0; background: transparent; text-align: left;
}
.conversation-item.active { background: var(--surface-3); }
.pin-mark { color: var(--accent); font-size: 12px; }
.avatar {
  width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center;
  border-radius: 50%; color: white; font-weight: 800;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
}
.conversation-copy { flex: 1; min-width: 0; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.conversation-top { display: flex; justify-content: space-between; gap: 8px; }
.conversation-time { color: var(--muted); font-size: 12px; }
.conversation-preview { display: block; margin-top: 3px; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat { min-width: 0; display: grid; grid-template-rows: auto 1fr auto auto; background: var(--bg); }
.chat-header {
  min-height: calc(60px + var(--safe-top)); display: flex; align-items: center;
  padding: var(--safe-top) 14px 0; border-bottom: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(20px);
}
.chat-header .avatar { width: 38px; height: 38px; flex-basis: 38px; }
.chat-person { flex: 1; display: flex; flex-direction: column; margin-left: 9px; }
.chat-person span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.back-button { display: none; font-size: 35px; }
.messages { overflow-y: auto; padding: 18px max(16px, calc((100vw - 980px)/2)) 10px; }
.message-row { display: flex; margin: 6px 0; }
.message-row.user { justify-content: flex-end; }
.message-row > div { max-width: 100%; display: flex; flex-direction: column; }
.message-row.user > div { align-items: flex-end; }
.message-row.assistant > div { align-items: flex-start; }
.bubble {
  width: fit-content; min-width: 104px; max-width: min(78vw,650px);
  padding: 10px 14px; border-radius: 19px; line-height: 1.38; white-space: pre-wrap; overflow-wrap: anywhere;
}
.message-row.assistant .bubble { background: var(--incoming); border-bottom-left-radius: 6px; }
.message-row.user .bubble { color: white; background: linear-gradient(135deg,var(--accent),var(--accent-2)); border-bottom-right-radius: 6px; }
.message-time { margin: 4px 8px 0; color: var(--muted); font-size: 10px; }
.typing { padding: 0 max(16px, calc((100vw - 980px)/2)) 6px; }
.typing span { width: 7px; height: 7px; display: inline-block; margin: 0 1px; border-radius: 50%; background: var(--muted); animation: bounce 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: .13s; }
.typing span:nth-child(3) { animation-delay: .26s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }
.composer {
  display: flex; gap: 9px; align-items: flex-end; padding: 8px 13px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line); background: var(--surface);
}
.composer textarea { min-height: 40px; max-height: 126px; padding: 9px 13px; border-radius: 20px; }
.send-button { width: 36px; height: 36px; flex: 0 0 36px; border: 0; border-radius: 50%; color: white; background: var(--accent); font-size: 23px; font-weight: 800; }
.send-button:disabled { opacity: .35; }

.notes-view, .activity-view { padding-bottom: 40px; }
.notes-list, .activity-list { padding: 0 24px; }
.note-card {
  width: 100%; display: block; padding: 16px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); text-align: left;
}
.note-card strong { display: block; font-size: 17px; }
.note-card p { margin: 6px 0 0; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

dialog { width: min(92vw,520px); padding: 0; border: 0; border-radius: 20px; background: var(--surface); color: var(--text); box-shadow: 0 25px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(4px); }
.dialog-card { padding: 20px; max-height: 85vh; overflow-y: auto; }
.dialog-title { display: flex; justify-content: space-between; align-items: center; }
.dialog-title h3 { margin: 0; font-size: 22px; }
.slider-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.slider-grid label { padding: 12px; border-radius: 13px; background: var(--surface-3); }
.slider-grid output { float: right; color: var(--muted); }
.slider-grid input[type="range"] { padding: 0; border: 0; background: transparent; }
.theme-row { display: flex; justify-content: space-between; align-items: center; }
.theme-row input { width: 48px; height: 28px; appearance: none; border: 0; border-radius: 999px; padding: 0; background: var(--surface-3); position: relative; }
.theme-row input::after { content: ""; position: absolute; width: 22px; height: 22px; top: 3px; left: 3px; border-radius: 50%; background: white; transition: .2s; }
.theme-row input:checked { background: var(--accent); }
.theme-row input:checked::after { transform: translateX(20px); }
.menu-card { display: grid; padding: 8px; }
.menu-card button { padding: 14px; border: 0; background: transparent; font-weight: 680; }
.menu-card .danger { color: var(--danger); }

@media (max-width: 760px) {
  .app { display: block; padding-top: calc(54px + var(--safe-top)); }
  .mobile-header {
    position: fixed; inset: 0 0 auto 0; height: calc(54px + var(--safe-top)); z-index: 30;
    display: flex; align-items: flex-end; justify-content: space-between;
    padding: var(--safe-top) 9px 5px; border-bottom: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(20px);
  }
  .mobile-header strong { padding-bottom: 10px; }
  .sidebar { position: fixed; inset: 0; z-index: 40; transform: translateX(-100%); transition: .22s; }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-shell { height: 100%; }
  .topbar, .page-header { padding-top: 22px; }
  .desktop-only { display: none; }
  .dashboard-grid { grid-template-columns: 1fr; padding: 0 14px; }
  .recent-panel { margin: 18px 14px 32px; }
  .workspace-layout { display: block; position: relative; height: 100%; }
  .conversation-pane, .chat { position: absolute; inset: 0; transition: transform .22s ease; }
  .conversation-pane { transform: translateX(0); z-index: 2; }
  .chat { transform: translateX(100%); z-index: 3; }
  body.chat-open .conversation-pane { transform: translateX(-20%); }
  body.chat-open .chat { transform: translateX(0); }
  .pane-header { padding-top: 16px; }
  .chat-header { min-height: 58px; padding-top: 0; }
  .back-button { display: block; }
  .slider-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 80vw; min-width: 104px; }
  .notes-list, .activity-list { padding: 0 14px; }
}

.empty-chat {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 7px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}
.empty-chat strong {
  color: var(--text);
  font-size: 18px;
}
.empty-chat span {
  max-width: 320px;
  line-height: 1.4;
}


/* v3 UI polish */
:root {
  --radius-xl: 24px;
  --radius-lg: 18px;
  --shadow-soft: 0 14px 40px rgba(0,0,0,.14);
}

body {
  background:
    radial-gradient(circle at 15% 0%, rgba(123,140,255,.06), transparent 28%),
    var(--bg);
}

.topbar {
  padding-bottom: 10px;
}

.dashboard-strip {
  margin: 0 24px 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 10px;
}

.dashboard-strip > div {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
}

.dashboard-strip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  font-weight: 750;
}

.dashboard-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
}

.dash-card {
  min-height: 136px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.dash-card:active {
  transform: scale(.985);
}

.primary-card {
  background:
    linear-gradient(145deg, rgba(123,140,255,.92), rgba(157,108,255,.84)),
    var(--surface);
}

.primary-card strong {
  font-size: 26px;
}

.neutral-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), transparent),
    var(--surface);
}

.recent-panel {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
}

.recent-item,
.activity-item,
.note-card {
  transition: transform .15s ease, background .15s ease;
}

.recent-item:active,
.activity-item:active,
.note-card:active {
  transform: scale(.99);
}

.workspace-layout {
  background:
    radial-gradient(circle at 100% 0%, rgba(123,140,255,.05), transparent 30%),
    var(--bg);
}

.conversation-pane {
  background: rgba(18,19,23,.94);
  backdrop-filter: blur(24px);
}

:root[data-theme="light"] .conversation-pane {
  background: rgba(255,255,255,.92);
}

.chat-header {
  min-height: calc(66px + var(--safe-top));
}

.chat-person {
  gap: 1px;
}

.chat-person strong {
  font-size: 16px;
}

.scene-pill {
  display: inline-flex;
  width: fit-content;
  max-width: 220px;
  margin-top: 3px;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-3);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  scroll-behavior: smooth;
}

.bubble {
  min-width: 92px;
  max-width: min(76vw, 620px);
  padding: 10px 14px;
  border-radius: 20px;
  letter-spacing: -.1px;
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
}

.message-row.assistant .bubble {
  background:
    linear-gradient(180deg, rgba(255,255,255,.025), transparent),
    var(--incoming);
}

.message-row.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.message-time {
  opacity: .75;
}

.composer {
  padding-top: 10px;
  background: rgba(18,19,23,.94);
  backdrop-filter: blur(22px);
}

:root[data-theme="light"] .composer {
  background: rgba(255,255,255,.94);
}

.composer textarea {
  border-radius: 22px;
  background: var(--surface-2);
}

.send-button {
  box-shadow: 0 8px 20px rgba(123,140,255,.28);
}

.empty-chat {
  min-height: 100%;
  padding: 40px 24px;
}

.empty-chat strong {
  font-size: 20px;
}

.mobile-bottom-nav {
  display: none;
}

@media (max-width: 760px) {
  .app {
    padding-bottom: calc(66px + var(--safe-bottom));
  }

  .mobile-header {
    border-bottom: 0;
    box-shadow: 0 6px 24px rgba(0,0,0,.10);
  }

  .dashboard-strip {
    margin: 0 14px 12px;
  }

  .dashboard-grid {
    gap: 12px;
  }

  .dash-card {
    min-height: 126px;
  }

  .conversation-pane,
  .chat {
    bottom: calc(66px + var(--safe-bottom));
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    height: calc(66px + var(--safe-bottom));
    display: grid;
    grid-template-columns: repeat(4,1fr);
    padding: 6px 8px var(--safe-bottom);
    border-top: 1px solid var(--line);
    background: rgba(18,19,23,.96);
    backdrop-filter: blur(22px);
  }

  :root[data-theme="light"] .mobile-bottom-nav {
    background: rgba(255,255,255,.96);
  }

  .bottom-nav-item {
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    gap: 1px;
    padding: 5px 4px;
  }

  .bottom-nav-item span {
    font-size: 20px;
    line-height: 1;
  }

  .bottom-nav-item small {
    font-size: 10px;
  }

  .bottom-nav-item.active {
    color: var(--text);
    background: var(--surface-3);
  }

  .bubble {
    max-width: 78vw;
    min-width: 96px;
  }

  .chat-header {
    min-height: 62px;
  }

  .scene-pill {
    max-width: 160px;
  }

  dialog {
    width: min(94vw,520px);
  }
}


.profile-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.018);
}

.profile-section h4 {
  margin: 0;
  font-size: 15px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 12px;
}

@media (max-width: 620px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}


/* v5 chat cleanup */
.chat-person .scene-pill {
  max-width: 180px;
}

@media (max-width: 760px) {
  .chat-person .scene-pill {
    max-width: 135px;
  }
}


/* v6 living-world polish */
.status-pulse {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(123,140,255,.10);
}

.workspace-hub{height:100%;overflow-y:auto;padding-bottom:40px}.hub-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;padding:0 24px}.hub-card{min-height:138px;padding:18px;border:1px solid var(--line);border-radius:22px;background:var(--surface);text-align:left;display:flex;flex-direction:column;justify-content:flex-end;gap:7px}.hub-card span{font-size:22px;font-weight:750}.hub-card small,.hub-footer{color:var(--muted)}.hub-footer{padding:18px 24px;font-size:12px}.workspace-private-content{display:none;height:100%}.workspace-view.private-open .workspace-hub{display:none}.workspace-view.private-open .workspace-private-content{display:block}.privacy-screen{position:fixed;inset:0;z-index:1000;display:grid;place-items:center;padding:24px;background:var(--bg)}.privacy-card{width:min(100%,390px);padding:28px;border:1px solid var(--line);border-radius:24px;background:var(--surface);box-shadow:0 24px 80px rgba(0,0,0,.25)}@media(max-width:760px){.hub-grid{grid-template-columns:1fr;padding:0 14px}.hub-footer{padding:16px 14px}body.private-chat-open .mobile-bottom-nav{display:none!important}body.private-chat-open .app{padding-bottom:0}body.private-chat-open .conversation-pane,body.private-chat-open .chat{bottom:0}}


/* v8: force anonymous hub and private archive to be mutually exclusive */
.workspace-hub {
  position: absolute !important;
  inset: 0 !important;
  z-index: 12 !important;
  display: block !important;
  background: var(--bg) !important;
}
.workspace-hub.hidden,
.workspace-view.private-open .workspace-hub {
  display: none !important;
}
.workspace-private-content {
  position: absolute !important;
  inset: 0 !important;
  z-index: 13 !important;
  background: var(--bg) !important;
}
.workspace-private-content.hidden {
  display: none !important;
}
.workspace-private-content:not(.hidden) {
  display: block !important;
}
.hub-card {
  width: 100% !important;
  min-height: 124px !important;
  padding: 18px !important;
  border: 1px solid var(--line) !important;
  border-radius: 20px !important;
  background: var(--surface) !important;
  color: var(--text) !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: flex-end !important;
  gap: 5px !important;
  white-space: normal !important;
}
.hub-card span {
  display: block !important;
  color: var(--text) !important;
  font-size: 21px !important;
  line-height: 1.15 !important;
}
.hub-card small {
  display: block !important;
  color: var(--muted) !important;
  font-size: 13px !important;
  line-height: 1.25 !important;
}


/* v10: reliable mobile new-chat control */
#newChatButton {
  position: relative !important;
  z-index: 50 !important;
  min-width: 48px !important;
  min-height: 48px !important;
  flex: 0 0 48px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  touch-action: manipulation !important;
  cursor: pointer !important;
}


/* v11: + button must have a tight hit area — never stretch over the page */
.pane-header {
  position: relative;
}
#newChatButton {
  position: static !important;
  inset: auto !important;
  width: 48px !important;
  height: 48px !important;
  min-width: 48px !important;
  min-height: 48px !important;
  max-width: 48px !important;
  max-height: 48px !important;
  margin: 0 !important;
  padding: 0 !important;
  flex: 0 0 48px !important;
  align-self: center !important;
  pointer-events: auto !important;
}


/* v12: keep the private workspace inside the Workspace view.
   v8/v10 used absolute positioning without a positioned parent, which
   allowed the archive header to slide underneath the fixed iPhone header. */
.workspace-view {
  position: relative !important;
}

.workspace-view .workspace-hub,
.workspace-view .workspace-private-content {
  position: absolute !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
}

/* The archive heading and + must sit below the fixed mobile topbar. */
@media (max-width: 760px) {
  .workspace-view.private-open .workspace-private-content {
    overflow: hidden !important;
  }

  .workspace-view.private-open .workspace-layout {
    height: 100% !important;
  }

  .workspace-view.private-open .conversation-pane {
    padding-top: 0 !important;
  }

  .workspace-view.private-open .pane-header {
    padding-top: 16px !important;
    min-height: 74px !important;
  }

  .workspace-view.private-open #newChatButton {
    z-index: 60 !important;
  }
}

@media (max-width:760px){
  html,body,#app,.app{width:100%;height:100dvh!important;min-height:100dvh!important;overflow:hidden}
}
#activityView,[data-view="activity"],[data-nav="activity"],[href="#activity"],.nav-activity,.activity-menu,.activity-toggle,.activity-widget{display:none!important}

/* v14 portrait-safe private archive */
.workspace-view,
.workspace-private-content,
.workspace-layout,
.conversation-pane {
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

.workspace-private-content {
  width: 100% !important;
  overflow-x: hidden !important;
}

.workspace-layout {
  width: 100% !important;
  grid-template-columns: minmax(0, 1fr) !important;
  overflow-x: hidden !important;
}

.conversation-pane {
  width: 100% !important;
  overflow-x: hidden !important;
}

.floating-new-chat {
  display: none;
}

@media (max-width: 760px) {
  .workspace-view.private-open .floating-new-chat {
    display: flex !important;
    position: fixed !important;
    right: max(18px, env(safe-area-inset-right)) !important;
    bottom: calc(24px + env(safe-area-inset-bottom)) !important;
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    max-width: 56px !important;
    max-height: 56px !important;
    border: 0 !important;
    border-radius: 50% !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 0 4px !important;
    font-size: 38px !important;
    line-height: 1 !important;
    font-weight: 300 !important;
    z-index: 9999 !important;
    touch-action: manipulation !important;
  }

  body.chat-open .floating-new-chat {
    display: none !important;
  }
}


/* v16 header clipping fix */
@media (max-width: 760px) {
  :root {
    --workspace-topbar-height: 74px;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
  }

  .mobile-header,
  .app-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 10000 !important;
    height: calc(var(--workspace-topbar-height) + env(safe-area-inset-top)) !important;
    min-height: calc(var(--workspace-topbar-height) + env(safe-area-inset-top)) !important;
    padding-top: env(safe-area-inset-top) !important;
    box-sizing: border-box !important;
    background: var(--surface, var(--bg)) !important;
  }

  .app,
  #app {
    padding-top: calc(var(--workspace-topbar-height) + env(safe-area-inset-top)) !important;
    box-sizing: border-box !important;
  }

  .view,
  .workspace-view,
  .workspace-private-content,
  .workspace-layout,
  .conversation-pane,
  .chat {
    max-width: 100vw !important;
    min-width: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  .workspace-view {
    position: relative !important;
    height: calc(
      100dvh
      - var(--workspace-topbar-height)
      - env(safe-area-inset-top)
    ) !important;
  }

  .workspace-private-content {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
  }

  .workspace-layout {
    height: 100% !important;
    min-height: 0 !important;
  }

  .conversation-pane {
    height: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .chat-header {
    position: relative !important;
    top: 0 !important;
    flex: 0 0 auto !important;
    min-height: 74px !important;
    padding-top: 12px !important;
    padding-bottom: 12px !important;
    box-sizing: border-box !important;
    z-index: 20 !important;
    background: var(--surface, var(--bg)) !important;
  }

  .messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .composer {
    position: relative !important;
    flex: 0 0 auto !important;
    bottom: auto !important;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    box-sizing: border-box !important;
  }

  .chat-person,
  .chat-person strong,
  .chat-person span {
    max-width: 100% !important;
  }

  .chat-person {
    overflow: hidden !important;
  }

  .chat-person strong,
  .chat-person span {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  body.chat-open .mobile-bottom-nav,
  body.private-chat-open .mobile-bottom-nav {
    display: none !important;
  }
}

/* v17 secrecy: Activity is not part of the visible product */
#activityView,
[data-view="activity"],
[data-nav="activity"],
[href="#activity"],
.nav-activity,
.activity-menu,
.activity-toggle,
.activity-widget,
.activity-card,
.activity-panel {
  display: none !important;
}


/* v17: messenger is hard-bounded between top header and bottom nav */
@media (max-width:760px) {
  :root {
    --top-shell-h: 74px;
    --bottom-shell-h: 72px;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    overflow: hidden !important;
  }

  #app,
  .app {
    width: 100%;
    max-width: 100%;
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
    padding: 0 !important;
  }

  .mobile-header,
  .app-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(var(--top-shell-h) + env(safe-area-inset-top)) !important;
    min-height: calc(var(--top-shell-h) + env(safe-area-inset-top)) !important;
    padding-top: env(safe-area-inset-top) !important;
    z-index: 10000 !important;
    box-sizing: border-box !important;
  }

  .mobile-bottom-nav {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    height: calc(var(--bottom-shell-h) + env(safe-area-inset-bottom)) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    z-index: 10000 !important;
    box-sizing: border-box !important;
  }

  .view,
  .workspace-view {
    position: fixed !important;
    top: calc(var(--top-shell-h) + env(safe-area-inset-top)) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: calc(var(--bottom-shell-h) + env(safe-area-inset-bottom)) !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .workspace-hub,
  .workspace-private-content,
  .workspace-layout,
  .conversation-pane,
  .chat {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  .workspace-layout {
    display: block !important;
  }

  .conversation-pane {
    display: flex !important;
    flex-direction: column !important;
  }

  .chat-header {
    flex: 0 0 76px !important;
    min-height: 76px !important;
    max-height: 76px !important;
    padding: 12px 16px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 12px !important;
  }

  .composer {
    position: relative !important;
    flex: 0 0 auto !important;
    bottom: auto !important;
    min-height: 76px !important;
    padding: 10px 14px !important;
    box-sizing: border-box !important;
    background: var(--bg) !important;
  }

  /* Individual chat uses the same shell; nav remains visible for immersion. */
  body.chat-open .mobile-bottom-nav,
  body.private-chat-open .mobile-bottom-nav {
    display: grid !important;
  }

  /* Nothing may render underneath shell bars. */
  .workspace-view *,
  .conversation-pane *,
  .chat * {
    max-width: 100%;
    box-sizing: border-box;
  }
}

@media (max-width:760px) {
  .workspace-view.private-open .pane-header {
    padding-top: 18px !important;
    min-height: 94px !important;
  }
}

/* v18 secrecy layers */
.workspace-view:not(.private-open) #workspacePrivateContent {
  display: none !important;
}
.workspace-view:not(.private-open) #workspaceHub {
  display: block !important;
}

.creator-dialog{width:min(94vw,560px)}
.creator-card{display:grid;gap:16px;padding:20px;max-height:88vh;overflow-y:auto}
.creator-top{display:flex;align-items:center;justify-content:space-between}
.creator-top h3{margin:0;font-size:24px}
.creator-progress{display:flex;justify-content:center;gap:8px}
.creator-dot{width:7px;height:7px;border-radius:999px;background:var(--surface-3)}
.creator-dot.active{width:22px;background:var(--accent)}
.creator-dot.done{background:var(--muted)}
.creator-step{display:none;gap:14px}
.creator-step.active{display:grid}
.creator-footer{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.creator-footer .primary,.creator-footer .secondary{width:100%}
.creator-preview-card{padding:14px;border:1px solid var(--line);border-radius:16px;background:var(--surface-3)}
#creatorPreview{margin-top:8px;font-size:15px}
.creator-step small{color:var(--muted);font-weight:500}
@media(max-width:760px){.creator-dialog{width:94vw!important;max-width:94vw!important}.creator-card{max-height:82dvh}}

/* v21 life-sandbox */
.pane-actions{display:flex;align-items:center;gap:2px}
.new-message-grid{display:grid;gap:10px}
.choice-card{width:100%;padding:16px;border:1px solid var(--line);border-radius:16px;background:var(--surface-3);text-align:left;display:grid;gap:5px}
.choice-card strong{font-size:16px}.choice-card span{font-size:13px;color:var(--muted);line-height:1.35}
.prompt-chips{display:flex;gap:8px;flex-wrap:wrap}.prompt-chips button{border:1px solid var(--line);border-radius:999px;padding:8px 10px;background:var(--surface-3);font-size:12px}
.world-card h4{margin:0}.world-card small{color:var(--muted);font-weight:500}.player-sliders label{min-width:0}
.unread-dot{width:8px;height:8px;border-radius:50%;background:var(--accent);display:inline-block;margin-left:6px}
.group-badge{display:inline-block;margin-left:6px;padding:2px 6px;border-radius:999px;background:var(--surface-3);color:var(--muted);font-size:10px;font-weight:700}
.event-toast{position:fixed;z-index:1200;left:50%;bottom:calc(88px + var(--safe-bottom));transform:translateX(-50%);width:min(calc(100% - 28px),420px);padding:13px 15px;border:1px solid var(--line);border-radius:16px;background:var(--surface);box-shadow:0 18px 55px rgba(0,0,0,.28);display:grid;gap:3px}.event-toast small{color:var(--muted)}
/* old floating CTA is intentionally retired */
.floating-new-chat{display:none!important}
@media(max-width:760px){.world-card,.new-message-dialog .dialog-card{max-height:82dvh}.event-toast{bottom:calc(78px + var(--safe-bottom))}body.private-chat-open .event-toast{bottom:calc(18px + var(--safe-bottom))}}


/* v22 memory + world events */
.world-event-status {
  display:grid; gap:4px; padding:13px 14px; border:1px solid var(--line); border-radius:14px; background:var(--surface-3);
}
.world-event-status strong { font-size:14px; }
.world-event-status small { color:var(--muted); line-height:1.35; }
/* v23 balanced mobile navigation */
@media (max-width:760px){
  .mobile-bottom-nav{grid-template-columns:repeat(3,minmax(0,1fr));padding-left:12px;padding-right:12px;column-gap:6px;}
  .bottom-nav-item{width:100%;min-width:0;justify-self:stretch;text-align:center;}
}
#creatorKinks{min-height:150px;}


/* v24 dashboard scrolling + status-only private doorway */
.dashboard-status-widget {
  width:100%;
  min-width:0;
  padding:13px 14px;
  border:1px solid var(--line);
  border-radius:16px;
  background:rgba(255,255,255,.025);
  color:var(--text);
  text-align:left;
  font:inherit;
  -webkit-touch-callout:none;
  user-select:none;
}
.dashboard-status-widget span {
  display:block; color:var(--muted); font-size:11px; text-transform:uppercase;
  letter-spacing:.7px; font-weight:750;
}
.dashboard-status-widget strong { display:block; margin-top:4px; font-size:17px; }
.workspace-blank-touch { cursor:default; }

@media (max-width:760px) {
  #dashboardView.active-view {
    overflow-y:auto !important;
    overflow-x:hidden !important;
    -webkit-overflow-scrolling:touch !important;
    overscroll-behavior-y:contain;
    touch-action:pan-y;
    padding-bottom:24px !important;
  }
  #dashboardView .dashboard-grid,
  #dashboardView .dashboard-strip,
  #dashboardView .page-header {
    touch-action:pan-y;
  }
}
