/* In-person controller + display — standalone pages (not session CSS). */
:root {
    --ip-bg: #0b1220;
    --ip-panel: #141c2e;
    --ip-text: #e8eef8;
    --ip-muted: #9aa8c0;
    --ip-accent: #2b6cb0;
    --ip-danger: #c53030;
    --ip-ok: #2f855a;
    --ip-warn: #b7791f;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--ip-bg);
    color: var(--ip-text);
    font-family: "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

body.in-person-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

body.in-person-display {
    height: 100dvh;
    max-height: 100dvh;
}

.ip-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    padding: 10px 14px;
    background: rgba(20, 28, 46, 0.92);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ip-topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.ip-brand {
    font-size: 13px;
    letter-spacing: 0.02em;
    color: var(--ip-muted);
}

.ip-room {
    font-weight: 600;
    color: var(--ip-text);
    font-variant-numeric: tabular-nums;
}

body.in-person-display .ip-display-end-btn {
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    background: var(--ip-danger);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

body.in-person-display .ip-display-end-btn:hover {
    filter: brightness(1.08);
}

body.in-person-display .ip-display-end-btn:disabled {
    opacity: 0.65;
    cursor: default;
}

.ip-banner,
.ip-status {
    margin: 0;
    flex: 0 0 auto;
    padding: 8px 14px;
    font-size: 13px;
    text-align: center;
}

body.in-person-controller .ip-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

body.in-person-controller .ip-banner-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: rgba(232, 238, 248, 0.95);
    animation: ip-bls-spin 0.75s linear infinite;
    flex: 0 0 auto;
}

body.in-person-controller .ip-banner-timer {
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
    font-size: 12px;
}

body.in-person-controller.ip-session-pending .ip-bls-host {
    opacity: 0.85;
}

body.in-person-controller .ip-leave-btn {
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    background: var(--ip-danger);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

body.in-person-controller .ip-leave-btn:hover {
    filter: brightness(1.08);
}

body.in-person-controller .ip-leave-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

.ip-banner[data-tone="error"],
.ip-status[data-tone="error"] { color: #feb2b2; background: rgba(197, 48, 48, 0.2); }
.ip-banner[data-tone="warn"],
.ip-status[data-tone="warn"] { color: #f6e05e; background: rgba(183, 121, 31, 0.2); }
.ip-banner[data-tone="ok"],
.ip-status[data-tone="ok"] { color: #9ae6b4; background: rgba(47, 133, 90, 0.2); }
.ip-banner[data-tone="neutral"],
.ip-status[data-tone="neutral"] { color: var(--ip-muted); }

.ip-stage {
    flex: 1 1 auto;
    position: relative;
    min-height: 0;
    background: #000;
    overflow: hidden;
}

.ip-stage canvas {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Display: stage fills leftover viewport exactly — no 100vh min-heights that overflow chrome */
body.in-person-display .ip-stage {
    flex: 1 1 auto;
    min-height: 0;
}

body.in-person-display .ip-stage canvas {
    min-height: 0;
}

.ip-controls {
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0));
    background: var(--ip-panel);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Full BLS settings shell (reuses .emdr-controls from session CSS) */
body.in-person-controller .ip-stage {
    flex: 0 0 176px;
    min-height: 176px;
    max-height: 176px;
    position: relative !important;
    display: block !important;
    overflow: hidden;
    background: #000;
}

/* Defeat session CSS absolute/PIP rules on the preview canvas */
body.in-person-controller .ip-stage .emdr-canvas-container {
    position: absolute !important;
    inset: 0 96px 0 0 !important;
    left: 0 !important;
    top: 0 !important;
    right: 96px !important;
    bottom: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    transform: none !important;
    z-index: 1 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

body.in-person-controller .ip-stage #emdrCanvas,
body.in-person-controller .ip-stage .emdr-canvas {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    display: block !important;
}

/* Start/Stop fixed on the right of the preview — round control */
body.in-person-controller .ip-stage-side {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    width: 96px !important;
    z-index: 5 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.45);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
}

body.in-person-controller .ip-stage-start-btn {
    width: 72px !important;
    height: 72px !important;
    min-width: 72px !important;
    min-height: 72px !important;
    max-width: 72px !important;
    max-height: 72px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.05;
    margin: 0;
    aspect-ratio: 1 / 1;
}

body.in-person-controller .ip-stage-start-btn .cycle-counter {
    font-size: 11px;
    opacity: 0.9;
}

body.in-person-controller .ip-stage-start-btn.running,
body.in-person-controller .ip-stage-start-btn.btn-danger {
    background: var(--ip-danger) !important;
}

body.in-person-controller .ip-bls-shell {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #f7fafc;
    color: #1a202c;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

body.in-person-controller.sandbox-mode .ip-bls-shell,
body.in-person-controller .ip-bls-shell {
    background: var(--ip-panel);
    color: var(--ip-text);
}

body.in-person-controller .ip-bls-host {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0));
}

/* Shown until session claim + controls markup finish (preview paints earlier) */
body.in-person-controller .ip-bls-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 160px;
    padding: 24px 16px;
    text-align: center;
}

body.in-person-controller .ip-bls-loading-spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-top-color: rgba(232, 238, 248, 0.9);
    animation: ip-bls-spin 0.75s linear infinite;
}

@keyframes ip-bls-spin {
    to { transform: rotate(360deg); }
}

body.in-person-controller .ip-bls-loading-text {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--ip-text);
}

body.in-person-controller .ip-bls-loading-timer {
    margin: 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--ip-muted);
}

body.in-person-controller .ip-bls-host .emdr-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
}

body.in-person-controller .ip-bls-host .control-group {
    margin: 0;
    width: 100%;
    justify-content: flex-start;
    align-items: stretch;
}

/* Shared left label column (matches Ball / Background / Tone) */
body.in-person-controller .ip-labeled-control-row {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 8px;
    align-items: center;
    width: 100%;
}

body.in-person-controller .ip-labeled-control-row .bls-control-suffix {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    justify-content: flex-start;
    flex-wrap: wrap;
}

body.in-person-controller .ip-speed-row #speedSlider {
    flex: 1;
    width: auto;
    min-width: 0;
    max-width: none;
}

body.in-person-controller .ip-speed-row #speedValue {
    flex: 0 0 auto;
    min-width: 4.5rem;
    color: var(--ip-text);
    font-size: 13px;
}

body.in-person-controller .ip-dir-row .pattern-btn {
    padding: 6px 8px;
    min-width: 34px;
}

/* Wide browser: phone-width control panel centered in the window */
@media (min-width: 480px) {
    body.in-person-controller .ip-topbar,
    body.in-person-controller .ip-banner,
    body.in-person-controller .ip-stage,
    body.in-person-controller .ip-bls-shell {
        width: 100%;
        max-width: 430px;
        margin-inline: auto;
    }

    body.in-person-controller .ip-bls-shell {
        border-left: 1px solid rgba(255, 255, 255, 0.06);
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }

    body.in-person-controller .ip-stage {
        border-left: 1px solid rgba(255, 255, 255, 0.06);
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }
}

body.in-person-controller .ip-bls-host .random-quick-controls {
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    opacity: 0.92;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

body.in-person-controller .ip-bls-host .random-quick-label {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--ip-muted);
}

body.in-person-controller .ip-bls-host .random-quick-suffix {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
    align-items: start !important;
}

body.in-person-controller .ip-bls-host .random-quick-chip {
    min-width: 0;
}

body.in-person-controller .ip-bls-host .random-quick-btn {
    width: 100%;
    padding: 6px 8px !important;
    font-size: 12px !important;
    line-height: 1.1;
    border-radius: 8px;
}

body.in-person-controller .ip-bls-host .random-quick-interval {
    min-width: 0;
    width: 100%;
}

body.in-person-controller .ip-bls-host .random-mini-slider {
    min-width: 0;
    max-width: none;
}

body.in-person-controller .ip-end-session-btn {
    width: 100%;
    background: var(--ip-danger) !important;
    color: #fff !important;
    border: 0 !important;
    padding: 12px 14px !important;
    font-weight: 600;
    border-radius: 10px;
}

body.in-person-controller .ip-hint {
    margin: 0;
    padding: 8px 12px 12px;
    font-size: 11px;
    color: var(--ip-muted);
}

/* Always show build id on the controller (narrow column even on laptops) */
body.in-person-controller .app-version-phone {
    display: block;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    color: rgba(232, 238, 248, 0.38);
    text-shadow: none;
}

/* Tone row: label · mute · profile dropdown */
body.in-person-controller .bls-inline-tone-row {
    display: grid;
    grid-template-columns: 72px auto 1fr;
    gap: 8px;
    align-items: center;
}

body.in-person-controller .bls-inline-tone-row #blsBallAudioBtn {
    flex: 0 0 auto;
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

body.in-person-controller .bls-inline-tone-row .bls-sound-profile-select {
    min-width: 0;
    width: 100%;
}

body.in-person-controller #blsBallAudioBtn.ip-audio-on {
    background-color: #28a745 !important;
    border-color: #1e7e34 !important;
    color: #fff !important;
}

body.in-person-controller #blsBallAudioBtn.ip-audio-off {
    background-color: #dc3545 !important;
    border-color: #b02a37 !important;
    color: #fff !important;
}

body.in-person-display .ip-display-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px max(12px, env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.28), transparent);
    pointer-events: none;
}

body.in-person-display .ip-display-bottom .bls-control-group,
body.in-person-display .ip-display-bottom .bottom-control-btn {
    pointer-events: auto;
}

body.in-person-display .ip-stage {
    padding-bottom: 72px;
}

body.in-person-display .ip-audio-unlock {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: max(80px, calc(env(safe-area-inset-bottom) + 72px));
    transform: translateX(-50%);
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 10px 16px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
    cursor: pointer;
}

body.in-person-display .ip-audio-unlock[hidden] {
    display: none !important;
}

.ip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.ip-btn {
    appearance: none;
    border: 0;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    background: var(--ip-accent);
}

.ip-btn.is-running { background: var(--ip-danger); }
.ip-btn-danger { background: var(--ip-danger); }
.ip-btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--ip-text);
}

.pattern-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ip-text);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    cursor: pointer;
}

.pattern-btn[data-pattern="sine"] {
    font-size: 1.45em;
    font-weight: 700;
    line-height: 1;
    padding: 6px 9px;
}

.pattern-ellipse-wrap {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
    z-index: 1;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.pattern-ellipse-wrap.is-open {
    z-index: 6000;
}

.pattern-btn[data-pattern="ellipse"] {
    min-width: 42px;
    padding: 4px 8px;
    line-height: 0;
    touch-action: manipulation;
}

.pattern-ellipse-glyph,
.pattern-line-glyph {
    display: block;
    width: 26px;
    height: 22px;
    overflow: visible;
    pointer-events: none;
}

.pattern-btn[data-pattern="vertical"] {
    min-width: 42px;
    padding: 4px 8px;
    line-height: 0;
    touch-action: manipulation;
}

.pattern-ellipse-menu {
    position: absolute;
    top: calc(100% + 6px);
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6001;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 148px;
    padding: 6px;
    border-radius: 10px;
    background: #1c1c1e;
    color: #f5f5f7;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
}

.pattern-ellipse-menu.is-ported {
    position: fixed;
    z-index: 10050;
}

.pattern-ellipse-menu[hidden] {
    display: none !important;
}

.pattern-ellipse-menu-sep {
    height: 1px;
    margin: 4px 6px;
    background: currentColor;
    opacity: 0.22;
}

.pattern-ellipse-shape[hidden] {
    display: none;
}

.pattern-ellipse-menu button {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.pattern-ellipse-menu button:hover,
.pattern-ellipse-menu button.is-active {
    background: rgba(255, 255, 255, 0.14);
}

.pattern-btn.is-active {
    background: rgba(43, 108, 176, 0.35);
    border-color: var(--ip-accent);
}

/* In-person hue sliders — same full-width layout as the video session
   (label above the track). Do not use 72px | 1fr | 28px: the shared
   emdr-integrated-session.css places the track in grid-column 1 / row 2,
   which would trap the rainbow in the 72px label column. */
body.in-person-controller .bls-inline-color-row.bls-inline-hue-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 28px;
    grid-template-rows: auto auto;
    row-gap: 4px;
    column-gap: 8px;
    align-items: center;
    width: 100%;
}

body.in-person-controller .bls-inline-hue-row .bls-inline-color-label {
    grid-column: 1;
    grid-row: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--ip-muted);
}

body.in-person-controller .bls-inline-hue-row .bls-hue-track-wrap {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
}

body.in-person-controller .bls-inline-hue-row .bls-hue-swatch,
body.in-person-controller .bls-inline-hue-row .bls-visual-type-wrap {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: end;
}

body.in-person-controller .control-group input[type="range"].bls-hue-slider,
body.in-person-controller .bls-inline-hue-row .bls-hue-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 1 1 auto;
    height: 12px;
    border-radius: 999px;
    outline: none;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.25);
    background: linear-gradient(
        to right,
        #ff0000 0%,
        #ffff00 17%,
        #00ff00 33%,
        #00ffff 50%,
        #0000ff 67%,
        #ff00ff 83%,
        #ff0000 100%
    );
}

body.in-person-controller .bls-hue-slider--soft {
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
    background: linear-gradient(
        to right,
        #ffb3b3 0%,
        #ffffb3 17%,
        #b3ffb3 33%,
        #b3ffff 50%,
        #b3b3ff 67%,
        #ffb3ff 83%,
        #ffb3b3 100%
    );
}

body.in-person-controller .bls-hue-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #222;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    cursor: grab;
}

body.in-person-controller .bls-hue-slider--soft::-webkit-slider-thumb {
    background: #f7f7f7;
    border-color: #555;
}

body.in-person-controller .bls-hue-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #222;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    cursor: grab;
}

body.in-person-controller .bls-hue-slider--soft::-moz-range-thumb {
    background: #f7f7f7;
    border-color: #555;
}

body.in-person-controller .bls-hue-slider::-moz-range-track {
    height: 12px;
    border-radius: 999px;
    background: transparent;
}

body.in-person-controller .bls-hue-swatch {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
    background: #ff0000;
}

body.in-person-controller .bls-visual-type-wrap {
    position: relative;
    display: inline-flex;
    z-index: 1;
}

body.in-person-controller .bls-visual-type-wrap.is-open {
    z-index: 6000;
}

body.in-person-controller .bls-visual-type-trigger {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
}

body.in-person-controller .bls-visual-preview-ball {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ff0000;
    box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.18), 0 1px 2px rgba(0, 0, 0, 0.28);
    pointer-events: none;
}

body.in-person-controller .bls-visual-preview-ball[hidden],
body.in-person-controller .bls-visual-preview-sprite[hidden],
body.in-person-controller .bls-visual-preview-scene[hidden] {
    display: none !important;
}

body.in-person-controller .bls-visual-preview-sprite {
    width: 24px;
    height: 24px;
    object-fit: contain;
    pointer-events: none;
}

body.in-person-controller .bls-visual-type-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 6001;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 132px;
    padding: 6px;
    border-radius: 10px;
    background: #1c1c1e;
    color: #f5f5f7;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
}

body.in-person-controller .bls-visual-type-menu.is-ported {
    position: fixed;
    z-index: 10050;
    max-height: min(72vh, 420px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    touch-action: manipulation;
}

body.in-person-controller .bls-visual-type-menu[hidden] {
    display: none !important;
}

body.in-person-controller .bls-visual-type-menu button {
    border: none;
    border-radius: 7px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 13px;
    padding: 10px 12px;
    min-height: 44px;
    text-align: left;
    touch-action: manipulation;
    cursor: pointer;
    white-space: nowrap;
}

body.in-person-controller .bls-visual-type-menu button:hover,
body.in-person-controller .bls-visual-type-menu button.is-active {
    background: rgba(94, 183, 255, 0.22);
    color: #fff;
}

body.in-person-controller .bls-visual-type-menu button.is-active {
    font-weight: 600;
}

.ip-speed label {
    font-size: 12px;
    color: var(--ip-muted);
    display: block;
    margin-bottom: 4px;
}

.ip-speed input[type="range"] {
    width: 100%;
}

.ip-hint {
    font-size: 12px;
    color: var(--ip-muted);
    line-height: 1.4;
    margin: 0;
}
