/* Enter the Field · PERT-OS original-experience bridge · B16 RC4
   Removes obsolete site chrome, supplies a single portal return control, and
   adds responsive safety without rewriting the original creative engines. */

:root {
  --pert-portal-ink: #e6e4d4;
  --pert-portal-muted: #9fa899;
  --pert-portal-night: #0d1513;
  --pert-portal-line: rgba(203, 220, 194, .18);
  --pert-portal-green: #78b98d;
  --pert-portal-gold: #d9ad61;
}

html[data-pert-original="true"] {
  min-width: 0;
  color-scheme: dark;
  background: var(--pert-portal-night);
}

html[data-pert-original="true"],
html[data-pert-original="true"] body {
  max-width: 100%;
  overflow-x: clip;
}

body.pert-restored {
  padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
}

body.pert-restored :where(img, svg, video, canvas) {
  max-width: 100%;
}

body.pert-restored :where(button, a, input, select, textarea) {
  max-width: 100%;
}

/* Old global PERT-OS navigation is intentionally retired in RC4. */
body.pert-restored :where(header.topbar, footer.footer-links, footer.site-footer, .daw-return) {
  display: none !important;
}

#pertPortalBridge {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 2147483647;
  width: min(360px, calc(100vw - 28px));
  color: var(--pert-portal-ink);
  font: 500 13px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  filter: drop-shadow(0 16px 38px rgba(0, 0, 0, .52));
}

#pertPortalBridge,
#pertPortalBridge * {
  box-sizing: border-box;
}

#pertPortalBridge .pert-bridge-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--pert-portal-line);
  border-radius: 3px;
  background: rgba(8, 15, 14, .94);
  backdrop-filter: blur(14px);
}

#pertPortalBridge .pert-bridge-label {
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #b8c9b5;
  font-size: 12px;
  letter-spacing: .04em;
}

#pertPortalBridge .pert-bridge-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

#pertPortalBridge a,
#pertPortalBridge button {
  min-height: 40px;
  appearance: none;
  border: 1px solid var(--pert-portal-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .025);
  color: var(--pert-portal-ink);
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}

#pertPortalBridge a:hover,
#pertPortalBridge button:hover,
#pertPortalBridge a:focus-visible,
#pertPortalBridge button:focus-visible {
  border-color: rgba(217, 173, 97, .56);
  background: rgba(217, 173, 97, .08);
  outline: 2px solid rgba(242, 201, 118, .6);
  outline-offset: 2px;
}

#pertPortalBridge .pert-bridge-panel {
  margin-bottom: 8px;
  padding: 14px 15px;
  border: 1px solid var(--pert-portal-line);
  border-radius: 3px;
  background: rgba(8, 15, 14, .97);
  backdrop-filter: blur(16px);
}

#pertPortalBridge .pert-bridge-panel[hidden] {
  display: none;
}

#pertPortalBridge .pert-bridge-panel strong {
  display: block;
  margin-bottom: 6px;
  color: #d9cfb6;
  font-size: 14px;
}

#pertPortalBridge .pert-bridge-panel p {
  margin: 7px 0;
  color: rgba(230, 228, 212, .78);
}

#pertPortalBridge .pert-bridge-panel small {
  display: block;
  color: rgba(230, 228, 212, .58);
}

#pertPortalBridge .pert-bridge-panel .pert-bridge-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}

#pertPortalBridge .pert-bridge-panel .pert-bridge-panel-actions a {
  background: rgba(120, 185, 141, .08);
}

/* Visualizer responsive integration */
body.pert-visualizer .wrap {
  width: min(1180px, calc(100% - 28px));
  margin-inline: auto;
}

body.pert-visualizer .viz-shell {
  padding-top: 14px;
}

/* FRI responsive integration */
body.pert-fri .fri,
body.pert-fri .main,
body.pert-fri .top-row,
body.pert-fri .ds,
body.pert-fri .loop,
body.pert-fri .kb,
body.pert-fri .expr {
  min-width: 0;
  max-width: 100%;
}

/* FPHP responsive integration */
body.pert-fphp .daw-shell,
body.pert-fphp .daw-main,
body.pert-fphp .daw-field-panel,
body.pert-fphp .daw-controls-panel {
  min-width: 0;
  max-width: 100%;
}

/* Chambers keep their original field, while text and controls remain reachable. */
body.pert-chamber .nav-bar {
  gap: 8px !important;
}

body.pert-chamber .nav-btn {
  min-height: 42px;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

@media (max-width: 920px) {
  body.pert-visualizer .viz-hud {
    grid-template-columns: 1fr !important;
  }

  body.pert-visualizer .hud-row,
  body.pert-visualizer .hud-row-2,
  body.pert-visualizer .hud-row-3 {
    grid-template-columns: minmax(90px, .34fr) minmax(0, 1fr) !important;
  }

  body.pert-visualizer .hud-row-2,
  body.pert-visualizer .hud-row-3,
  body.pert-visualizer .hud-actions {
    display: flex !important;
    flex-wrap: wrap !important;
  }

  body.pert-visualizer .viz-quick-controls {
    flex-wrap: wrap;
    margin-top: 0;
  }

  body.pert-fri .hdr {
    align-items: flex-start;
  }

  body.pert-fri .hdr-c {
    width: 100%;
    gap: 8px;
  }

  body.pert-fri .btns {
    flex-wrap: wrap;
  }

  body.pert-fri .top-row {
    grid-template-columns: 1fr !important;
  }

  body.pert-fri .ctrl-pnl,
  body.pert-fri .fx-pnl {
    width: 100%;
    max-height: none;
  }

  body.pert-fphp .daw-main {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 700px) {
  body.pert-restored {
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  }

  #pertPortalBridge {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    width: calc(100vw - 16px);
  }

  #pertPortalBridge .pert-bridge-label {
    display: none;
  }

  #pertPortalBridge .pert-bridge-bar {
    justify-content: flex-end;
  }

  #pertPortalBridge .pert-bridge-actions {
    width: 100%;
  }

  #pertPortalBridge a,
  #pertPortalBridge button {
    min-height: 44px;
    flex: 1;
    padding: 9px 11px;
    text-align: center;
  }

  #pertPortalBridge .pert-bridge-panel {
    max-height: min(62vh, 520px);
    overflow-y: auto;
  }

  body.pert-restored :where(input, select, textarea) {
    font-size: 16px !important;
  }

  body.pert-visualizer .wrap {
    width: calc(100% - 16px);
  }

  body.pert-visualizer #vizCanvas {
    height: min(58vh, 520px) !important;
    border-radius: 8px;
  }

  body.pert-visualizer .viz-quick-controls,
  body.pert-visualizer .hud-actions,
  body.pert-visualizer .zen-hud {
    gap: 7px;
  }

  body.pert-visualizer .hud-row,
  body.pert-visualizer .hud-row-2,
  body.pert-visualizer .hud-row-3 {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 7px;
  }

  body.pert-visualizer .hud-value {
    display: block !important;
    min-width: 0;
    text-align: left;
  }

  body.pert-visualizer .hud-actions .btn,
  body.pert-visualizer .hud-actions select,
  body.pert-visualizer .viz-quick-controls .btn {
    width: 100%;
    min-height: 44px;
  }

  body.pert-fri .hdr {
    padding: 10px;
  }

  body.pert-fri .mini-scope,
  body.pert-fri .breath {
    display: none;
  }

  body.pert-fri .coh {
    width: 100%;
  }

  body.pert-fri .coh-bar {
    flex: 1;
    width: auto;
  }

  body.pert-fri .btns {
    width: 100%;
  }

  body.pert-fri .btns .btn {
    min-height: 44px;
    flex: 1 1 120px;
    justify-content: center;
  }

  body.pert-fri .main {
    padding: 8px;
  }

  body.pert-fri .vis {
    width: min(84vw, 340px) !important;
    height: min(84vw, 340px) !important;
  }

  body.pert-fri .ds,
  body.pert-fri .kb-wrap {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  body.pert-fri .seq-grid,
  body.pert-fri .keys {
    min-width: 620px;
  }

  body.pert-fri :where(.ctrl-btn, .fx-btn, .ds-btn, .loop-btn, .preset-btn) {
    min-height: 36px;
  }

  body.pert-fphp .daw-shell {
    width: 100%;
    padding-inline: 8px;
  }

  body.pert-fphp .daw-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  body.pert-fphp .daw-pads {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body.pert-fphp .daw-keys-wrap {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  body.pert-fphp .daw-keys {
    min-width: 620px;
  }

  body.pert-fphp :where(.daw-btn, .pad, .daw-opt) {
    min-height: 44px;
  }

  body.pert-chamber {
    min-height: 100svh !important;
    height: 100svh !important;
  }

  body.pert-chamber header {
    top: 76px !important;
    width: calc(100% - 24px);
  }

  body.pert-chamber header h1 {
    font-size: clamp(1.65rem, 9vw, 2.35rem) !important;
  }

  body.pert-chamber header h2 {
    font-size: clamp(1.2rem, 6.5vw, 1.8rem) !important;
  }

  body.pert-chamber .chamber-info {
    top: 160px !important;
    width: calc(100% - 28px);
    max-width: none !important;
    font-size: .78rem;
  }

  body.pert-chamber .control-btn {
    top: 12px !important;
    left: 12px !important;
    max-width: calc(50vw - 18px);
    min-height: 46px;
    padding: .7rem .9rem !important;
    font-size: .82rem !important;
  }

  body.pert-chamber .nav-bar {
    top: 12px !important;
    right: 12px !important;
    max-width: calc(50vw - 18px);
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  body.pert-chamber .nav-btn {
    min-height: 46px;
    padding: .68rem .82rem !important;
    font-size: .78rem !important;
    text-align: center;
  }

  body.pert-chamber .guidance {
    bottom: 172px !important;
    width: calc(100% - 26px);
    max-width: none !important;
    font-size: clamp(1.25rem, 7vw, 2rem) !important;
  }

  body.pert-chamber .coherence {
    bottom: 128px !important;
    width: calc(100% - 26px);
    font-size: 1.05rem !important;
    text-align: center;
  }

  body.pert-chamber .log {
    bottom: 76px !important;
    width: calc(100% - 24px);
    max-width: none !important;
    padding: 8px 10px !important;
    font-size: .68rem !important;
  }

  body.pert-chamber .final-message {
    width: calc(100% - 28px);
    font-size: clamp(1.7rem, 9vw, 2.6rem) !important;
  }
}

@media (max-width: 420px) {
  body.pert-fphp .daw-pads {
    grid-template-columns: 1fr !important;
  }

  body.pert-chamber .control-btn,
  body.pert-chamber .nav-bar {
    max-width: calc(50vw - 14px);
  }
}

@media (pointer: coarse) {
  #pertPortalBridge a,
  #pertPortalBridge button,
  body.pert-restored :where(.btn, .daw-btn, .nav-btn) {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #pertPortalBridge,
  #pertPortalBridge * {
    scroll-behavior: auto !important;
  }

  body:not(.pert-original-motion-enabled) * {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (forced-colors: active) {
  #pertPortalBridge .pert-bridge-bar,
  #pertPortalBridge .pert-bridge-panel {
    border: 2px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  #pertPortalBridge a,
  #pertPortalBridge button {
    border: 1px solid ButtonText;
    color: ButtonText;
    background: ButtonFace;
  }
}
