/* Phase 1 + Phase 2 Cognitive UI — Regions, Region Cosmos labels, Hugr v2 cards, Interactive Guide.
 * Follows modern-web-guidance: native <dialog> scroll containment, container-query cards, >=44px touch targets. */

/* --- Top HUD Guide & Regions triggers --- */
.hud-pill-btn {
  background: rgba(18, 21, 36, 0.82);
  color: var(--text-1, #e8ecf8);
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.28);
  border-radius: 999px;
  padding: 0.28rem 0.68rem;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  min-height: 30px;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.hud-pill-btn:hover,
.hud-pill-btn:focus-visible {
  border-color: rgb(var(--accent, 127, 170, 255));
  background: rgba(var(--accent, 127, 170, 255), 0.16);
}
.hud-pill-btn.is-accent {
  border-color: rgba(var(--accent, 127, 170, 255), 0.55);
}

/* --- Welcome / First-run tour banner (retired: permanent ? button in top bar never blocks UI) --- */
.guide-nudge,
#guide-nudge {
  display: none !important;
}
@media (max-width: 440px) {
  body:not(.ui-v2) #hud-regions-btn { display: none; }
}
.guide-nudge-go {
  background: rgb(var(--accent, 127, 170, 255));
  color: #090d18;
  border: 0;
  border-radius: 999px;
  padding: 0.34rem 0.78rem;
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}
.guide-nudge-x {
  background: transparent;
  border: 0;
  color: var(--muted, #98a2bd);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
}

/* --- 3D Cosmos floating labels (Region Constellation mode) --- */
.cosmos-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 14;
}
.cosmos-label {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  background: rgba(10, 14, 28, 0.82);
  color: #e9f0ff;
  border: 1px solid rgba(127, 176, 255, 0.38);
  border-radius: 999px;
  padding: 0.18rem 0.56rem;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: opacity 0.18s ease, border-color 0.18s ease;
}
.cosmos-label:hover {
  border-color: #ffcf6b;
  color: #fff;
}
.cosmos-label.is-synth {
  border-color: rgba(255, 207, 107, 0.72);
  box-shadow: 0 0 12px rgba(255, 207, 107, 0.25);
}
.cosmos-label.is-focused {
  border-color: rgb(var(--accent, 127, 170, 255));
  background: rgba(16, 26, 48, 0.96);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 16px rgba(var(--accent, 127, 170, 255), 0.5);
  z-index: 2;
}
.cm-btn.cm-exit {
  color: var(--text-1, #eef3ff);
  border-right: 1px solid rgba(160, 185, 255, 0.22);
  border-radius: 999px 0 0 999px;
  padding-right: 0.75rem;
  margin-right: 0.1rem;
}

/* --- Cosmos mode bar (Regions | Thoughts) --- */
.cosmos-mode-bar {
  position: fixed;
  top: 4.3rem;
  right: 1rem;
  z-index: 95;
  display: none;
  gap: 0.3rem;
  background: rgba(11, 14, 26, 0.84);
  border: 1px solid rgba(140, 170, 255, 0.24);
  border-radius: 999px;
  padding: 0.2rem;
  backdrop-filter: blur(6px);
}
body.explore .cosmos-mode-bar { display: inline-flex; }
.cm-btn {
  background: transparent;
  color: #aeb9d4;
  border: 0;
  border-radius: 999px;
  padding: 0.28rem 0.72rem;
  font-size: 0.74rem;
  white-space: nowrap;
  cursor: pointer;
}
.cm-btn.active {
  background: rgba(127, 176, 255, 0.22);
  color: #f3f7ff;
  font-weight: 600;
}

/* --- Regions & Hybrid Memory modal --- */
#regions-modal {
  max-width: 780px;
  width: min(94vw, 780px);
}
.reg-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.5rem 0 0.9rem;
}
.reg-tab {
  min-height: 38px;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border, rgba(160, 185, 255, 0.22));
  background: transparent;
  color: var(--muted, #a7b1cc);
  font-size: 0.82rem;
  cursor: pointer;
}
.reg-tab.active {
  background: rgba(var(--accent, 127, 170, 255), 0.18);
  color: var(--text-1, #eef3ff);
  border-color: rgb(var(--accent, 127, 170, 255));
  font-weight: 600;
}
.reg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.7rem;
}
.reg-card {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.2);
  background: rgba(19, 24, 42, 0.88);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.reg-card:hover {
  border-color: rgba(var(--accent, 127, 170, 255), 0.6);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}
.reg-card header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
}
.reg-card h3 {
  margin: 0;
  font-size: 0.98rem;
  color: var(--text-1, #f1f5ff);
}
.reg-badge {
  font-size: 0.72rem;
  color: rgb(var(--accent, 127, 170, 255));
  white-space: nowrap;
}
.reg-meta {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted, #9aa6c4);
  line-height: 1.4;
}
.reg-peers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.reg-peer {
  border: 1px solid rgba(160, 185, 255, 0.2);
  background: rgba(127, 176, 255, 0.08);
  color: var(--ink, #d9e4ff);
  border-radius: 999px;
  padding: 0.16rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
}
.reg-card footer {
  display: flex;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.3rem;
}
.reg-act {
  min-height: 44px;
  padding: 0.48rem 0.85rem;
  border-radius: 11px;
  border: 1px solid var(--border, rgba(160, 185, 255, 0.24));
  background: transparent;
  color: var(--ink, #e8eefc);
  font-size: 0.88rem;
  cursor: pointer;
}
.reg-act.primary {
  background: rgba(var(--accent, 127, 170, 255), 0.2);
  border-color: rgb(var(--accent, 127, 170, 255));
  font-weight: 600;
}
.reg-detail-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}
.reg-synth-box {
  padding: 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 207, 107, 0.35);
  background: rgba(255, 207, 107, 0.06);
  margin: 0.65rem 0;
  font-size: 0.85rem;
  line-height: 1.55;
  white-space: pre-wrap;
}
.reg-seg {
  border-left: 2px solid rgba(var(--accent, 127, 170, 255), 0.45);
  padding-left: 0.75rem;
  margin: 0.85rem 0;
}
.reg-seg-head {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgb(var(--accent, 127, 170, 255));
  margin-bottom: 0.35rem;
}
.reg-note-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(160, 185, 255, 0.14);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin: 0.42rem 0;
  color: var(--text-1, #e5ebfa);
  font-size: 0.94rem;
  line-height: 1.5;
  cursor: pointer;
}
.reg-note-btn:hover { border-color: rgb(var(--accent, 127, 170, 255)); }
.reg-note-meta {
  display: block;
  font-size: 0.76rem;
  color: var(--muted, #95a2c0);
  margin-bottom: 0.22rem;
}
.reg-outcome-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.7rem 0;
}
.reg-outcome-form input,
.reg-outcome-form textarea {
  flex: 1 1 100%;
  min-height: 46px;
  padding: 0.6rem 0.82rem;
  border-radius: 12px;
  border: 1px solid var(--border, rgba(160, 185, 255, 0.26));
  background: rgba(0, 0, 0, 0.26);
  color: var(--ink, #eef3ff);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.48;
}
.reg-outcome-form textarea {
  width: 100%;
  resize: vertical;
}
.reg-search-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.75rem;
}
.reg-search-row input[type="search"] {
  flex: 1 1 220px;
  min-height: 46px;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border, rgba(160, 185, 255, 0.28));
  background: rgba(0, 0, 0, 0.26);
  color: var(--ink, #eef3ff);
  font-size: 1rem;
}
.reg-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted, #a7b1cc);
  cursor: pointer;
}

/* --- Hugr v2 Cognitive Model inside #profile-overlay --- */
.hugr-v2 {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border, rgba(160, 185, 255, 0.2));
}
.hugr-v2 h2 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
}
.hugr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.65rem 0;
}
.hugr-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin-top: 0.6rem;
}
.hugr-card {
  container-type: inline-size;
  padding: 0.72rem 0.82rem;
  border-radius: 12px;
  border: 1px solid var(--border, rgba(160, 185, 255, 0.18));
  background: rgba(255, 255, 255, 0.03);
}
.hugr-card.is-confirmed { border-color: rgba(110, 220, 160, 0.45); }
.hugr-card.is-rejected { opacity: 0.5; }
.hugr-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--muted, #9aa6c4);
  margin-bottom: 0.3rem;
}
.hugr-cat {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: rgb(var(--accent, 127, 170, 255));
}
.hugr-claim {
  margin: 0 0 0.5rem;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text-1, #eef3ff);
}
.hugr-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.hugr-ev {
  font-size: 0.72rem;
  color: var(--muted, #9aa6c4);
  margin-right: auto;
}
.hugr-preview {
  margin-top: 0.75rem;
  font-size: 0.78rem;
}
.hugr-preview pre {
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 10px;
  padding: 0.65rem;
  margin-top: 0.4rem;
  line-height: 1.45;
}

/* --- Native <dialog> Contextual Guide & Use-Case Playbook --- */
dialog.huginn-guide {
  max-width: min(94vw, 520px);
  width: 100%;
  max-height: 86dvh;
  padding: 1.05rem 1.1rem;
  border-radius: 18px;
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.42);
  background: #111626;
  color: var(--text-1, #eef3ff);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  margin: auto;
  overflow: hidden;
}
dialog.huginn-guide[open] {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
dialog.huginn-guide:modal {
  overscroll-behavior: contain;
}
dialog.huginn-guide::backdrop {
  background: rgba(5, 8, 18, 0.84);
  overflow: hidden;
  overscroll-behavior: contain;
}
.guide-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.guide-head h1 {
  margin: 0;
  font-size: 1.06rem;
  letter-spacing: 0.01em;
  text-transform: none;
  font-weight: 700;
}
.guide-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  flex-shrink: 0;
}
.guide-tab {
  min-block-size: 42px;
  padding: 0.4rem 0.65rem;
  border-radius: 12px;
  border: 1px solid rgba(160, 185, 255, 0.22);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted, #a7b1cc);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}
.guide-tab[aria-selected="true"] {
  background: rgba(var(--accent, 127, 170, 255), 0.2);
  border-color: rgb(var(--accent, 127, 170, 255));
  color: var(--text-1, #eef3ff);
  font-weight: 700;
}
.guide-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 0.9rem;
  line-height: 1.54;
  color: var(--text-1, #dfe7fb);
  padding-right: 0.15rem;
}
.guide-body h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  color: rgb(var(--accent, 127, 170, 255));
}
.guide-body p { margin: 0 0 0.55rem; }
.guide-ctx-strip {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 0.35rem;
  padding-bottom: 0.45rem;
  margin-bottom: 0.55rem;
  border-bottom: 1px solid rgba(160, 185, 255, 0.14);
  scrollbar-width: none;
}
.guide-ctx-strip::-webkit-scrollbar { display: none; }
.guide-ctx-pill {
  flex: 0 0 auto;
  min-block-size: 36px;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(160, 185, 255, 0.2);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted, #a7b1cc);
  font-size: 0.78rem;
  white-space: nowrap;
  cursor: pointer;
}
.guide-ctx-pill.active {
  background: rgba(var(--accent, 127, 170, 255), 0.18);
  border-color: rgb(var(--accent, 127, 170, 255));
  color: var(--text-1, #eef3ff);
  font-weight: 600;
}
.guide-items {
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
  margin: 0.6rem 0;
}
.guide-item {
  padding: 0.62rem 0.75rem;
  border-radius: 12px;
  border: 1px solid rgba(160, 185, 255, 0.15);
  background: rgba(255, 255, 255, 0.03);
}
.guide-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  margin-bottom: 0.22rem;
}
.guide-item-head strong {
  font-size: 0.9rem;
  color: var(--text-1, #eef3ff);
}
.guide-item p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted, #b5c0da);
}
.guide-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.guide-badge.local {
  color: #8ce8b6;
  background: rgba(76, 175, 125, 0.14);
  border-color: rgba(76, 175, 125, 0.35);
}
.guide-badge.llm {
  color: #d6b6ff;
  background: rgba(176, 120, 255, 0.15);
  border-color: rgba(176, 120, 255, 0.38);
}
.guide-badge.copy {
  color: #93d5ff;
  background: rgba(90, 180, 255, 0.14);
  border-color: rgba(90, 180, 255, 0.35);
}
.guide-search {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.65rem;
  border-radius: 12px;
  border: 1px solid rgba(160, 185, 255, 0.26);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text-1, #eef3ff);
  font-size: 1rem;
}
.guide-cases {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.guide-case {
  padding: 0.78rem 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(160, 185, 255, 0.18);
  background: rgba(19, 25, 44, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.guide-case-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.45rem;
}
.guide-case-head h3 {
  margin: 0;
  font-size: 0.94rem;
  color: var(--text-1, #eef3ff);
  line-height: 1.35;
}
.guide-case ol {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.84rem;
  color: var(--muted, #c0cbe3);
  line-height: 1.5;
}
.guide-case ol li { margin-bottom: 0.2rem; }
.guide-case-foot {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.15rem;
}
.guide-tip {
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: rgba(var(--accent, 127, 170, 255), 0.11);
  border-left: 3px solid rgb(var(--accent, 127, 170, 255));
  font-size: 0.82rem;
  margin-top: 0.45rem;
}
.guide-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding-top: 0.3rem;
  border-top: 1px solid rgba(160, 185, 255, 0.12);
}

/* ==========================================================================
   Phase 4: 3-Tab Phone-First "Pół-Interfejs" (body.ui-v2)
   Follows modern-web-guidance: form-factor-adaptation, content-first-noise-reduction, tabs.
   ========================================================================== */
:root {
  --target-size: 44px;
  --p4-top-h: 52px;
  --p4-nav-h: 64px;
  --p4-col: 460px;
}

/* Hidden cleanly when user switches back to Classic Orb View */
body:not(.ui-v2) #p4-topbar,
body:not(.ui-v2) #p4-frigg-pulse,
body:not(.ui-v2) #p4-capture-quick,
body:not(.ui-v2) #p4-result-bar,
body:not(.ui-v2) #p4-feed,
body:not(.ui-v2) #p4-mind-pane,
body:not(.ui-v2) #p4-clarify-pane,
body:not(.ui-v2) #p4-nav {
  display: none !important;
}

/* Override index.html `html, body { overflow: hidden; }` so ui-v2 scrolls natively everywhere!
 * Focus Not Obscured (WCAG 2.4.11) for fixed top & bottom bars.
 * Note: index.html has no viewport-fit=cover and Android MainActivity.java already pads
 * android.R.id.content out of status/nav bars, so we do NOT add env(safe-area-inset-*) here
 * (which caused double top/bottom blank bands in the Android WebView). */
html.ui-v2-scroll,
html:has(body.ui-v2) {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  height: auto !important;
  -webkit-overflow-scrolling: touch;
  scroll-padding-top: calc(var(--p4-top-h) + 0.5rem);
  scroll-padding-bottom: calc(var(--p4-nav-h) + 0.75rem);
}

body.ui-v2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100dvh;
  height: auto !important;
  overflow-x: clip !important;
  overflow-y: visible !important;
  overflow-wrap: break-word;
  padding-top: calc(var(--p4-top-h) + 0.55rem);
  padding-bottom: calc(var(--p4-nav-h) + 1.35rem);
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}
body.ui-v2 :where(a, code) {
  overflow-wrap: anywhere;
}
body.ui-v2 :where(h1, h2, h3) {
  text-wrap: balance;
}
body.ui-v2 :where(p, li) {
  text-wrap: pretty;
}

/* Silence the 18 noisy legacy controls, duplicate h1/subtitle, floating nudge, and 30 blind orbs in ui-v2 */
body.ui-v2 > h1,
body.ui-v2 .hud-tl,
body.ui-v2 .subtitle,
body.ui-v2 #guide-nudge,
body.ui-v2 #view-toggle,
body.ui-v2 #lens-switch,
body.ui-v2 #scope-switch,
body.ui-v2 #apps-btn,
body.ui-v2 #menu-btn,
body.ui-v2 #orb-flow,
body.ui-v2 #ring-now {
  display: none !important;
}

/* When viewing 3D Cosmos (body.explore) in ui-v2, hide capture/feed/panes cleanly */
body.ui-v2.explore #p4-frigg-pulse,
body.ui-v2.explore #record-btn,
body.ui-v2.explore #mic-line,
body.ui-v2.explore #bt-input,
body.ui-v2.explore #p4-capture-quick,
body.ui-v2.explore #capture-status,
body.ui-v2.explore #p4-result-bar,
body.ui-v2.explore #result,
body.ui-v2.explore #p4-feed,
body.ui-v2.explore #p4-mind-pane,
body.ui-v2.explore #p4-clarify-pane {
  display: none !important;
}
body.ui-v2.explore {
  overflow: hidden !important;
  height: 100dvh !important;
}

/* When on Mind or Clarify tab (not 3D cosmos), hide capture stage while keeping recorder mounted */
body.ui-v2[data-p4tab="mind"]:not(.explore) #p4-frigg-pulse,
body.ui-v2[data-p4tab="mind"]:not(.explore) #record-btn,
body.ui-v2[data-p4tab="mind"]:not(.explore) #mic-line,
body.ui-v2[data-p4tab="mind"]:not(.explore) #bt-input,
body.ui-v2[data-p4tab="mind"]:not(.explore) #p4-capture-quick,
body.ui-v2[data-p4tab="mind"]:not(.explore) #capture-status,
body.ui-v2[data-p4tab="mind"]:not(.explore) #p4-result-bar,
body.ui-v2[data-p4tab="mind"]:not(.explore) #result,
body.ui-v2[data-p4tab="mind"]:not(.explore) #p4-feed,
body.ui-v2[data-p4tab="clarify"] #p4-frigg-pulse,
body.ui-v2[data-p4tab="clarify"] #record-btn,
body.ui-v2[data-p4tab="clarify"] #mic-line,
body.ui-v2[data-p4tab="clarify"] #bt-input,
body.ui-v2[data-p4tab="clarify"] #p4-capture-quick,
body.ui-v2[data-p4tab="clarify"] #capture-status,
body.ui-v2[data-p4tab="clarify"] #p4-result-bar,
body.ui-v2[data-p4tab="clarify"] #result,
body.ui-v2[data-p4tab="clarify"] #p4-feed {
  display: none !important;
}

/* Single-row compact top bar (<10% viewport height; no double safe-area inset in APK WebView) */
.p4-topbar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, var(--p4-col));
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--p4-top-h);
  padding: 0.3rem 0.75rem 0.3rem 0.85rem;
  background: rgba(11, 14, 24, 0.96);
  border-bottom: 1px solid rgba(160, 185, 255, 0.14);
}
@media (min-width: 500px) {
  .p4-topbar {
    border-inline: 1px solid rgba(160, 185, 255, 0.14);
    border-radius: 0 0 16px 16px;
  }
}
.p4-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-block-size: var(--target-size);
  background: transparent;
  border: 0;
  color: var(--text-1, #eef3ff);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  padding: 0 0.25rem;
}
.p4-brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgb(var(--accent, 127, 170, 255));
  box-shadow: 0 0 10px rgba(var(--accent, 127, 170, 255), 0.8);
}
.p4-topbar-acts {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.p4-icon-btn {
  min-block-size: max(36px, var(--target-size));
  min-inline-size: max(36px, var(--target-size));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid rgba(160, 185, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-1, #e8eefc);
  font-size: 1rem;
  cursor: pointer;
}
.p4-icon-btn:hover {
  border-color: rgba(var(--accent, 127, 170, 255), 0.65);
}
.p4-icon-btn.is-unseen {
  border-color: rgb(var(--accent, 127, 170, 255));
  background: rgba(var(--accent, 127, 170, 255), 0.16);
  color: var(--text-1, #eef3ff);
}

/* Position menu popover & modals cleanly above top/bottom bars in ui-v2 */
body.ui-v2 #menu-popover {
  top: calc(var(--p4-top-h) + 0.35rem);
  right: max(0.75rem, calc((100vw - var(--p4-col)) / 2 + 0.75rem));
  z-index: 120;
}
body.ui-v2 .modal-overlay {
  z-index: 150;
}

/* Calm 1-line Frigg pulse above the record orb */
.p4-frigg-pulse {
  width: min(100%, var(--p4-col));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  min-block-size: 44px;
  padding: 0.55rem 0.95rem;
  margin: 0.2rem 0 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 207, 107, 0.36);
  background: rgba(255, 207, 107, 0.09);
  color: #ffe2a4;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}
.p4-frigg-pulse[hidden] { display: none; }

/* Keep the central record orb familiar, slightly tighter so cards sit right below */
body.ui-v2 #record-btn {
  width: 142px;
  height: 142px;
  margin-top: 0.35rem;
  margin-bottom: 0.3rem;
  flex-shrink: 0;
}
body.ui-v2 > #mic-line,
body.ui-v2 > #mic-line:not(.warn) {
  position: static;
  margin: 0.15rem auto 0.35rem !important;
  align-self: center;
}
body.ui-v2 > #bt-input,
body.ui-v2 > #bt-input:not(.open) {
  margin: 0.15rem auto !important;
}
.p4-capture-quick {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  margin: 0.35rem 0 0.65rem;
}
.p4-chip {
  min-block-size: 44px;
  padding: 0.42rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(160, 185, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted, #b5c0da);
  font-size: 0.88rem;
  cursor: pointer;
}
.p4-chip[aria-pressed="true"],
.p4-chip.active {
  background: rgba(var(--accent, 127, 170, 255), 0.2);
  border-color: rgb(var(--accent, 127, 170, 255));
  color: var(--text-1, #eef3ff);
  font-weight: 600;
}

/* Scrollable Live Text box in ui-v2 (local Whisper only, cumulative phrases, auto-scroll) */
body.ui-v2 #capture-status {
  width: min(100%, var(--p4-col));
  margin: 0.1rem auto 0.45rem;
}
body.ui-v2 #capture-preview-toggle {
  min-block-size: 38px;
  padding: 0.32rem 0.85rem;
  font-size: 0.84rem;
  border-radius: 999px;
}
body.ui-v2 #capture-preview-toggle[aria-pressed="true"]::before {
  content: "● ";
  font-size: 0.72rem;
}
body.ui-v2 #capture-preview-text {
  display: block;
  -webkit-line-clamp: unset;
  -webkit-box-orient: initial;
  width: 100%;
  max-height: 175px;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0.55rem auto 0;
  padding: 0.78rem 0.95rem;
  border-radius: 14px;
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.36);
  background: rgba(11, 18, 30, 0.9);
  color: var(--text-1, #eef3ff);
  font-size: 1rem;
  line-height: 1.54;
  text-align: left;
  overflow-wrap: break-word;
}
body.ui-v2 #capture-preview-text.is-status {
  text-align: center;
  color: var(--muted, #9aa6c4);
  font-size: 0.88rem;
  border-style: dashed;
}
body.ui-v2 #capture-preview-text[hidden] {
  display: none;
}
#capture-preview-text .preview-partial {
  opacity: 0.6;
  font-style: italic;
}

/* Readout & Scannable Thought Feed — hide legacy #result in ui-v2 unless explicitly opened */
.p4-result-bar {
  width: min(100%, var(--p4-col));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.35rem auto 0.25rem;
  padding: 0.2rem 0.15rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted, #9aa6c4);
}
.p4-result-bar[hidden] { display: none !important; }
body.ui-v2 #result:not(.p4-open) {
  display: none !important;
}
body.ui-v2 #result.p4-open {
  width: min(100%, var(--p4-col));
  min-height: 0;
  height: auto;
  flex: 0 0 auto;
  margin: 0.1rem auto 0.85rem;
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.32);
  background: rgba(14, 20, 36, 0.9);
}
body.ui-v2 #result:empty {
  display: none !important;
  margin: 0;
}
.p4-feed {
  width: min(100%, var(--p4-col));
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 0.4rem;
}
.p4-feed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #94a2c2);
  padding: 0 0.15rem;
}
.p4-card {
  container-type: inline-size;
  padding: 1rem 1.05rem;
  border-radius: 16px;
  border: 1px solid rgba(160, 185, 255, 0.18);
  background: rgba(17, 22, 38, 0.88);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.p4-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted, #95a3c4);
}
.p4-reg-pill {
  min-block-size: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.38);
  background: rgba(var(--accent, 127, 170, 255), 0.12);
  color: rgb(var(--accent, 127, 170, 255));
  border-radius: 999px;
  padding: 0.18rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.p4-card-text {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.54;
  color: var(--text-1, #eef3ff);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.p4-card-acts {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.15rem;
}
.p4-card-acts .reg-act {
  padding: 0.44rem 0.68rem;
  font-size: 0.85rem;
  white-space: nowrap;
}
.p4-more-btn {
  margin-inline-start: auto;
  flex-shrink: 0;
  min-block-size: 44px;
  min-inline-size: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  border: 1px solid rgba(160, 185, 255, 0.22);
  background: transparent;
  color: var(--muted, #b5c0da);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0 0.5rem;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.p4-more-btn[aria-expanded="true"] {
  border-color: rgb(var(--accent, 127, 170, 255));
  background: rgba(var(--accent, 127, 170, 255), 0.16);
  color: var(--text-1, #eef3ff);
}
.p4-more-drawer {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
  margin-top: 0.25rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(160, 185, 255, 0.14);
}
.p4-more-drawer[hidden] {
  display: none !important;
}
.p4-more-drawer .reg-act {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: rgba(9, 13, 24, 0.72);
  font-size: 0.88rem;
}

/* Full-screen inline panes for Mind & Clarify — Pixel 9 Pro XL column mirrored on desktop */
.p4-pane {
  width: min(100%, var(--p4-col));
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.p4-pane[hidden] { display: none; }

/* Single-row sub-tabs tuned so all 4 pills fit cleanly inside 412px Pixel 9 Pro XL */
.p4-subtabs {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  scroll-snap-type: inline proximity;
  gap: 0.36rem;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}
.p4-subtabs::-webkit-scrollbar { display: none; }
.p4-subtab {
  flex: 1 0 auto;
  scroll-snap-align: start;
  position: relative;
  min-block-size: 44px;
  padding: 0.42rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(160, 185, 255, 0.22);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted, #a7b1cc);
  font-size: 0.85rem;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}
.p4-subtab[aria-selected="true"],
.p4-subtab.active {
  background: rgba(var(--accent, 127, 170, 255), 0.18);
  color: var(--text-1, #eef3ff);
  border-color: rgb(var(--accent, 127, 170, 255));
}
.p4-subtab[aria-selected="true"]::after,
.p4-subtab.active::after {
  content: "";
  position: absolute;
  inset: auto 18% 0;
  border-block-end: 3px solid currentColor;
  border-radius: 3px;
}

/* Communicate ("Pół-Interfejs") register picker & output card */
.comm-regs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}
.comm-reg-btn {
  min-block-size: 54px;
  padding: 0.62rem 0.75rem;
  border-radius: 13px;
  border: 1px solid rgba(160, 185, 255, 0.22);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink, #dfe7fb);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}
.comm-reg-btn.active {
  border-color: rgb(var(--accent, 127, 170, 255));
  background: rgba(var(--accent, 127, 170, 255), 0.16);
}
.comm-reg-btn strong { font-size: 0.92rem; }
.comm-reg-btn span { font-size: 0.77rem; line-height: 1.35; color: var(--muted, #9aa6c4); }
.comm-select {
  width: 100%;
  min-block-size: 46px;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border, rgba(160, 185, 255, 0.26));
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink, #eef3ff);
  font-size: 1rem;
}

/* Bottom 3-tab primary navigation — Pixel 9 Pro XL thumb bar (centered column on desktop) */
.p4-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, var(--p4-col));
  bottom: 0;
  z-index: 95;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(11, 14, 24, 0.97);
  border-top: 1px solid rgba(160, 185, 255, 0.18);
  padding: 0 0.35rem 0.3rem;
}
@media (min-width: 500px) {
  .p4-nav {
    border-inline: 1px solid rgba(160, 185, 255, 0.14);
    border-radius: 16px 16px 0 0;
  }
}
.p4-nav-btn {
  position: relative;
  min-block-size: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  border: 0;
  background: transparent;
  color: var(--muted, #93a1c4);
  cursor: pointer;
  padding: 0.35rem 0.25rem;
}
.p4-nav-ic { font-size: 1.22rem; line-height: 1; }
.p4-nav-lbl { font-size: 0.8rem; letter-spacing: 0.02em; }
.p4-nav-btn[aria-current="page"] {
  color: rgb(var(--accent, 127, 170, 255));
}
.p4-nav-btn[aria-current="page"] .p4-nav-lbl { font-weight: 600; }
/* Shape indicator (WCAG 1.4.1 & forced-colors safe: border, not background/box-shadow) */
.p4-nav-btn[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset: 0 22% auto;
  border-block-start: 3px solid currentColor;
  border-radius: 0 0 3px 3px;
}

/* 3D Cosmos HUD & Floating Region Preview Sheet in ui-v2 */
body.ui-v2 #cosmos-mode-bar {
  top: calc(var(--p4-top-h) + 0.5rem);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  max-width: calc(100vw - 1.2rem);
}
body.ui-v2.explore .graph-reset {
  top: calc(var(--p4-top-h) + 3.4rem);
  right: 0.75rem;
}
body.ui-v2.explore #gt-shapes {
  top: calc(var(--p4-top-h) + 5.9rem);
  right: 0.75rem;
}
body.ui-v2.explore #gt-dive {
  top: calc(var(--p4-top-h) + 8.4rem);
  right: 0.75rem;
}
body.ui-v2.explore .graph-foot {
  bottom: calc(var(--p4-nav-h) + 0.55rem);
}
body.ui-v2.explore.has-cosmos-card .graph-foot {
  display: none;
}
.p4-cosmos-card {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--p4-nav-h) + 0.65rem);
  width: min(calc(100% - 1.5rem), calc(var(--p4-col) - 1rem));
  z-index: 96;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(var(--accent, 127, 170, 255), 0.45);
  background: rgba(13, 18, 34, 0.97);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
body:not(.ui-v2) .p4-cosmos-card {
  bottom: 4.5rem;
}
.p4-cosmos-card[hidden] {
  display: none !important;
}
.p4-cosmos-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.p4-cosmos-card-head strong {
  font-size: 1.02rem;
  color: var(--text-1, #eef3ff);
}
.p4-cosmos-card-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted, #9aa6c4);
  line-height: 1.4;
}
.p4-cosmos-card-acts {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
body.ui-v2 #guide-nudge {
  bottom: calc(var(--p4-nav-h) + 0.75rem);
}
