/* The viewer's chrome carries the Rhino Sync identity of auth.css; the stage behind it is light, like a Rhino
   viewport, so layer colours picked in Rhino read the same here. */

:root {
    --bg:         #080b11;
    --panel:      rgba(12, 17, 26, 0.86);
    --surface:    rgba(150, 192, 228, 0.055);
    --surface-2:  rgba(150, 192, 228, 0.11);
    --border:     rgba(150, 192, 228, 0.16);

    --text:       #eef3f8;
    --text-dim:   #a7b2c0;
    --text-faint: #717d8c;

    --sync:        #44E100;
    --accent-text: #44E100;
    --accent-soft: rgba(68, 225, 0, 0.11);
    --accent-line: rgba(68, 225, 0, 0.30);
    --danger:      #ff6b5e;

    --solid:       #131a26;
    --solid-hover: #1c2636;
    --ring:        #121924;
    --shadow:      0 12px 32px -18px rgba(0, 0, 0, .6);
    --pop:         0 8px 22px -8px rgba(0, 0, 0, .7);
    --lift:        0 24px 60px -24px rgba(0, 0, 0, .7);
    --mine:        rgba(68, 225, 0, 0.14);
    --mine-time:   rgba(190, 240, 165, 0.6);
    --mention:     #7cc4ff;
    --ai:          #4a2424;
    --ai-text:     #ff8a80;
    --tv:          #24402a;
    --tv-text:     #8fe08f;

    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
    --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

    --keyboard: 0px;

    color-scheme: dark;
}

/* The brand green is too light to read on white: as text and thin strokes it darkens here. */
:root[data-theme="light"] {
    --panel:      rgba(251, 252, 253, 0.88);
    --surface:    rgba(22, 32, 48, 0.035);
    --surface-2:  rgba(22, 32, 48, 0.07);
    --border:     rgba(22, 32, 48, 0.13);

    --text:       #151b24;
    --text-dim:   #475262;
    --text-faint: #5f6b7a;

    --accent-text: #237a00;
    --accent-soft: rgba(68, 225, 0, 0.16);
    --accent-line: rgba(45, 150, 0, 0.42);
    --danger:      #c62a1d;

    --solid:       #ffffff;
    --solid-hover: #eef1f4;
    --ring:        #fbfcfd;
    --shadow:      0 12px 32px -16px rgba(22, 32, 48, .32);
    --pop:         0 8px 22px -8px rgba(22, 32, 48, .35);
    --lift:        0 24px 60px -24px rgba(22, 32, 48, .45);
    --mine:        rgba(68, 225, 0, 0.2);
    --mine-time:   #4d7a35;
    --mention:     #1764b8;
    --ai:          #fde4e1;
    --ai-text:     #b3261e;
    --tv:          #e0f3df;
    --tv-text:     #22722a;

    color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

.icon { flex: none; display: inline-block; width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.icon.google { --icon: url("/viewer/icons/google.png"); }
.icon.microsoft { --icon: url("/viewer/icons/microsoft.png"); }
.icon.dropbox { --icon: url("/viewer/icons/dropbox.png"); }
.icon.egnyte { --icon: url("/viewer/icons/egnyte.png"); }
.icon.network { --icon: url("/viewer/icons/network.png"); }
.icon.bolt { --icon: url("/viewer/icons/bolt.png"); }
.icon.save { --icon: url("/viewer/icons/save.png"); }
.icon.sync { --icon: url("/viewer/icons/sync.png"); }
.icon.upload { --icon: url("/viewer/icons/upload.png"); }
.icon.download { --icon: url("/viewer/icons/download.png"); }

[hidden] { display: none !important; }

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

/* A pinch belongs to the model, not to the page around it. */
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
    background: #9da3aa;
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.011em;
    -webkit-font-smoothing: antialiased;
}

#stage, #labels { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; }
#labels { pointer-events: none; overflow: hidden; }

.plate {
    position: absolute; left: 0; top: 0;
    padding: 2px 6px;
    font: 600 12px/1.3 var(--sans);
    white-space: nowrap;
    border-radius: 4px;
}

body.picking #stage { filter: blur(6px) brightness(.35); }
:root[data-theme="light"] body.picking #stage { filter: blur(6px) brightness(.8); }

#start {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: calc(100% - 32px); max-width: 460px; max-height: calc(100% - 32px);
    overflow-y: auto;
    padding: 36px 32px 30px;
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--lift);
}

.logo { width: 56px; height: 56px; margin: 0 auto 18px; display: block; }

.eyebrow {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent-text);
    margin-bottom: 12px;
}

h1 { font-size: 23px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }

#start > p { margin-top: 10px; color: var(--text-dim); font-size: 15px; text-wrap: pretty; }

.field { display: block; margin-top: 24px; text-align: left; }
.field span, .caption {
    display: block;
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 6px;
}
.field input {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.field input:focus { outline: none; border-color: var(--accent-line); }
.field input.missing { border-color: var(--danger); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
.tiles button {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 14px;
    font: inherit; font-weight: 500;
    color: var(--text);
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
}
.tiles button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--accent-line); }
.tiles button:disabled { opacity: .45; cursor: default; }
.tiles .icon { width: 20px; height: 20px; color: var(--accent-text); }

#folder, #recent { margin-top: 22px; text-align: left; }

.files { list-style: none; }
.files li { display: flex; align-items: center; gap: 4px; }
.files .open {
    flex: 1; min-width: 0;
    display: flex; align-items: baseline; gap: 10px;
    padding: 8px 10px;
    font: inherit;
    color: var(--text);
    text-align: left;
    background: none;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}
.files .open:hover:not(:disabled) { background: var(--surface-2); }
.files .open:disabled { cursor: default; opacity: .5; }
.files .file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .where { margin-left: auto; flex: none; font-size: 12px; color: var(--text-faint); }
.files .forget {
    width: 26px; height: 26px;
    color: var(--text-faint);
    background: none; border: 0; border-radius: 6px;
    cursor: pointer;
}
.files .forget:hover { color: var(--text); background: var(--surface-2); }

.hint { color: var(--text-faint); font-size: 13px; }
#message { margin-top: 18px; }
#message.error { color: var(--danger); }

.link {
    margin-top: 8px;
    font: inherit; font-size: 13px;
    color: var(--text-dim);
    background: none; border: 0;
    text-decoration: underline;
    cursor: pointer;
}

#chrome {
    position: fixed;
    left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top)); bottom: max(12px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
    pointer-events: none;
}
#chrome > * { pointer-events: auto; }

.panel { position: fixed; display: flex; flex-direction: column; }
.panel > .body { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.panel > .grab { flex: none; display: flex; align-items: center; gap: 6px; height: 32px; padding-left: 6px; cursor: grab; touch-action: none; }
.panel > .grab span {
    flex: 1; min-width: 0;
    font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--text-faint);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel > .grab .close { flex: none; width: 24px; height: 24px; padding: 5px; color: var(--text-faint); background: none; border: 0; border-radius: 6px; cursor: pointer; }
.panel > .grab .close:hover { color: var(--text); background: var(--surface-2); }
.panel > .grab svg { display: block; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.panel > .grab:active { cursor: grabbing; }
.panel > .grip { position: absolute; touch-action: none; }
.panel > .grip.n, .panel > .grip.s { left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.panel > .grip.e, .panel > .grip.w { top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.panel > .grip.n { top: -4px; }
.panel > .grip.s { bottom: -4px; }
.panel > .grip.e { right: -4px; }
.panel > .grip.w { left: -4px; }
.panel > .grip.ne, .panel > .grip.nw, .panel > .grip.se, .panel > .grip.sw { width: 14px; height: 14px; }
.panel > .grip.ne { top: -4px; right: -4px; cursor: nesw-resize; }
.panel > .grip.sw { bottom: -4px; left: -4px; cursor: nesw-resize; }
.panel > .grip.nw { top: -4px; left: -4px; cursor: nwse-resize; }
.panel > .grip.se { bottom: -4px; right: -4px; cursor: nwse-resize; }

#layers { right: 12px; top: 12px; width: 260px; max-height: 70vh; padding: 0 6px 6px; }
#layers ul, #chat ul { list-style: none; }
#layers ul ul { margin-left: 14px; }
#layers .layer { display: flex; align-items: center; }
#layers .caret {
    flex: none; width: 18px; height: 24px;
    font-size: 10px;
    color: var(--text-dim);
    background: none; border: 0; border-radius: 4px;
    cursor: pointer;
}
#layers .caret:disabled { cursor: default; }
#layers .toggle {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 8px;
    padding: 5px 8px 5px 4px;
    font: inherit; font-size: 13px;
    color: var(--text);
    text-align: left;
    background: none; border: 0; border-radius: 6px;
    cursor: pointer;
}
#layers .toggle:hover, #layers .caret:hover:not(:disabled) { background: var(--surface-2); }
#layers .toggle::before {
    content: ""; flex: none; width: 15px; height: 15px;
    background: #f5c842;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7z'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7z'/%3E%3C/svg%3E") center / contain no-repeat;
}
#layers .toggle.off, #layers .toggle.dim { color: var(--text-faint); }
#layers .toggle.dim::before { opacity: .35; }
#layers .toggle.off::before { background: var(--text-faint); opacity: .55; }
#layers .toggle span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#chat { left: 12px; bottom: 56px; width: 320px; height: 380px; max-height: calc(100% - 24px); gap: 6px; padding: 0 8px 8px; }
#chat-body { position: relative; flex: 1; min-height: 0; display: flex; }
#chat-list { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; font-size: 13px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

#chat-list .msg { display: flex; align-items: center; gap: 2px; margin: 0 0 3px; padding-right: 4px; }
#chat-list .msg.mine { flex-direction: row-reverse; }
#chat-list .msg.first:not(:first-child) { margin-top: 9px; }
#chat-list .msg.flash .bubble { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 2px var(--who); } to { box-shadow: 0 0 0 2px transparent; } }

#chat-list .bubble { min-width: 0; max-width: calc(100% - 46px); padding: 5px 10px; background: var(--surface-2); border-radius: 6px; }
#chat-list .mine .bubble { background: var(--mine); }
#chat-list .first .bubble { border-top: 3px solid var(--who); border-radius: 0 0 6px 6px; }
#chat-list .sender { margin-bottom: 3px; font-size: 10.5px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
#chat-list .sender .badge.ai { display: inline-flex; align-items: center; height: 14px; margin-left: 6px; padding: 0 5px; border-radius: 6px; vertical-align: 1px; font: 700 9px/1 var(--sans); background: var(--ai); color: var(--ai-text); }
#chat-list .quote {
    display: block; max-width: 100%;
    margin-bottom: 4px; padding: 1px 0 1px 6px;
    font: inherit; font-size: 11px;
    color: var(--text-faint);
    text-align: left;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    background: none; border: 0; border-left: 2px solid var(--text-faint);
    cursor: pointer;
}
#chat-list .quote:hover { color: var(--text-dim); }
#chat-list .line { display: flex; align-items: flex-end; gap: 10px; }
#chat-list .mine .line, #chat-list .mine .foot { flex-direction: row-reverse; }
#chat-list .content { min-width: 0; }
#chat-list .text { font-size: 13.5px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
#chat-list .time { flex: none; font-size: 10.5px; line-height: 1.6; color: var(--text-faint); }
#chat-list .mine .time { color: var(--mine-time); }
#chat-list .emoji svg { width: 16px; height: 16px; margin: 0 1px; vertical-align: -3px; }
#chat-list .emoji-only .emoji svg { width: 23px; height: 23px; vertical-align: -5px; }
#chat-list .mention { font-weight: 600; color: var(--mention); }
#chat-list .mention.me { padding: 0 3px; color: #0b1a05; background: var(--sync); border-radius: 4px; }
#chat-list .foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 5px; }
#chat-list .reactions { display: flex; flex-wrap: wrap; gap: 7px; }
#chat-list .reaction {
    display: inline-flex; align-items: center; gap: 4px;
    font: inherit; font-size: 11px;
    color: var(--text-faint);
    background: none; border: 0;
    cursor: pointer;
}
#chat-list .reaction svg { width: 12px; height: 12px; }

#chat-list .actions { flex: none; display: flex; visibility: hidden; }
#chat-list .msg:hover .actions, #chat-list .msg.touched .actions { visibility: visible; }
#chat-list .mine .actions { flex-direction: row-reverse; }
#chat-list .actions button {
    width: 20px; height: 20px; padding: 3px;
    color: var(--text-faint);
    background: none; border: 0; border-radius: 10px;
    cursor: pointer;
}
#chat-list .actions button:hover { color: var(--text); background: var(--surface-2); }
#chat-list .actions svg { display: block; width: 14px; height: 14px; }

#chat .chips { display: flex; flex-wrap: wrap; gap: 5px; }
#chat-list .chips { margin: 3px 0 1px; }
#chat .chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px 2px 7px;
    font: inherit; font-size: 11px;
    color: var(--text);
    background: none; border: 1px solid var(--border); border-radius: 9px;
    cursor: pointer;
}
#chat .chip:hover { background: var(--surface-2); }
#chat .chip svg { width: 11px; height: 11px; color: var(--accent-text); }
#chat .chip .cross { margin-left: 2px; color: var(--text-faint); }

#chat-floats { position: absolute; right: 12px; bottom: 6px; display: flex; gap: 5px; }
#chat-floats button {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px;
    font: inherit; font-size: 11px;
    color: var(--text);
    background: var(--solid); border: 1px solid var(--border); border-radius: 12px;
    cursor: pointer;
}
#chat-floats button:hover { background: var(--solid-hover); }
#chat-floats svg { width: 10px; height: 10px; }
#chat-floats #chat-mentions { font-weight: 600; color: var(--accent-text); }

#chat-typing { padding: 0 4px; font-size: 11px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-replying { display: flex; align-items: center; gap: 5px; padding: 0 4px; font-size: 11px; color: var(--text-faint); }
#chat-replying svg { flex: none; width: 11px; height: 11px; color: var(--accent-text); }
#chat-replying span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-replying button { flex: none; width: 16px; height: 16px; font-size: 13px; line-height: 1; color: var(--text-faint); background: none; border: 0; cursor: pointer; }
#chat-replying button:hover { color: var(--text); }

#chat-form { display: flex; flex-direction: column; gap: 3px; }
#chat-tools { display: flex; align-items: center; gap: 2px; }
#chat-box {
    display: flex; align-items: flex-end; gap: 4px;
    padding: 3px 3px 3px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 17px;
}
#chat-box:focus-within { border-color: var(--accent-line); }
#chat-input {
    flex: 1; min-width: 0;
    padding: 4px 0;
    font: inherit; font-size: 13px; line-height: 1.4;
    color: var(--text);
    background: none;
    border: 0;
    resize: none;
}
#chat-input:focus { outline: none; }
#chat-form button {
    flex: none; width: 28px; height: 28px; padding: 6px;
    color: var(--text-dim);
    background: none; border: 0; border-radius: 8px;
    cursor: pointer;
}
#chat-form button:hover { color: var(--text); background: var(--surface-2); }
#chat-form svg { display: block; width: 16px; height: 16px; }
#chat-form #chat-send { width: 26px; height: 26px; padding: 5px; color: #0b1a05; background: var(--sync); border-radius: 50%; }
#chat-form #chat-send:hover { filter: brightness(1.12); }
#chat-send svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

#leave {
    position: fixed; z-index: 5;
    display: flex; flex-direction: column; gap: 12px;
    min-width: 220px; padding: 14px;
    font-size: 13px;
    background: var(--panel);
    border: 1px solid var(--border); border-radius: 12px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--pop);
}
#leave .choices { display: flex; justify-content: flex-end; gap: 6px; }
#leave button { padding: 5px 12px; font: inherit; font-size: 12.5px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
#leave button:hover { background: var(--solid-hover); }
#leave #leave-ok { color: #fff; background: var(--danger); border-color: transparent; }
#leave #leave-ok:hover { filter: brightness(1.08); }

#scenery {
    position: fixed; z-index: 5;
    display: flex; flex-direction: column; gap: 10px;
    width: 300px; padding: 12px;
    background: var(--panel);
    border: 1px solid var(--border); border-radius: 12px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--pop);
}
#scenery .caption { margin: 0; }
#scenery-list { display: flex; }
#scenery #scenery-list button { flex: 1; padding: 5px 0; }
#scenery .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--text-dim); }
#scenery .segment { padding: 2px; background: var(--surface); border-radius: 8px; }
#scenery .segment button { padding: 3px 9px; font: inherit; font-size: 11.5px; color: var(--text-dim); background: none; border: 0; border-radius: 6px; cursor: pointer; }
#scenery .segment button:hover { color: var(--text); }
#scenery .segment button.on { color: var(--text); background: var(--surface-2); }
#scenery input[type="range"] { flex: 1; max-width: 168px; accent-color: var(--sync); }

#chat-picker, #chat-suggestions {
    position: fixed; z-index: 5;
    background: var(--solid);
    border: 1px solid var(--border);
    box-shadow: var(--pop);
}
#chat-picker { display: flex; padding: 3px 5px; border-radius: 14px; }
#chat-picker button { width: 24px; height: 24px; padding: 5px; background: none; border: 0; border-radius: 11px; cursor: pointer; }
#chat-picker button:hover, #chat-suggestions button:hover, #chat-suggestions button.on { background: var(--surface-2); }
#chat-picker svg { display: block; width: 14px; height: 14px; }
#chat-suggestions { display: flex; flex-direction: column; min-width: 140px; max-height: 180px; overflow-y: auto; padding: 3px; border-radius: 6px; }
#chat-suggestions button { padding: 3px 10px 3px 6px; font: inherit; font-size: 12px; color: var(--text); text-align: left; background: none; border: 0; border-radius: 4px; cursor: pointer; }
#chat-suggestions button span { color: var(--accent-text); }

.pin { position: absolute; left: 0; top: 0; }
.pin .dot { position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; background: var(--who); border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .45); }
.pin .card {
    position: absolute; left: 14px; top: 0; transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 1px;
    max-width: 320px; padding: 5px 10px 6px 11px;
    background: var(--panel);
    border: 1px solid var(--border); border-left: 3px solid var(--who); border-radius: 4px 8px 8px 4px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--pop);
    white-space: nowrap;
}
.pin .card b { font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--text); }
.pin .card span { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }

.pivot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; background: var(--sync); border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .45); pointer-events: none; }

body.pointing #stage canvas { cursor: crosshair; }

#status { display: contents; }
#dock { display: none; }

#busy, #note, #following, #pointing { position: fixed; }

#bar, #views, #dock, #info, #people, #layers, #chat, #busy, #note, #following, #pointing {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--shadow);
}

/* Folded, the bar keeps only the mark. interpolate-size lets the rest open from no width to its own; a browser
   without it folds at once. Hidden only once folded, so the buttons inside leave the tab order. */
#bar {
    position: relative; z-index: 1;
    display: flex; align-items: center;
    min-height: 48px;
    padding: 0 9px;
    interpolate-size: allow-keywords;
}
#bar .more { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; padding: 4px 0; transition: width .28s cubic-bezier(.2, .8, .2, 1), visibility 0s; }
#bar.folded .more { width: 0; visibility: hidden; transition: width .28s cubic-bezier(.2, .8, .2, 1), visibility 0s .28s; }
#bar:not(.folded) #mark { cursor: default; }
#bar .more > .tools:last-child { margin-right: 2px; }

#mark { position: relative; flex: none; width: 30px; height: 30px; padding: 2px; background: none; border: 0; border-radius: 50%; cursor: pointer; }
#mark img { display: block; width: 26px; height: 26px; }
#mark::after {
    content: ""; position: absolute; right: 0; bottom: 0; width: 8px; height: 8px;
    background: var(--text-faint); border-radius: 50%; box-shadow: 0 0 0 2px var(--ring);
    opacity: 0; transition: opacity .2s;
}
#bar.folded #mark::after { opacity: 1; }
#bar:has(.state.live) #mark::after { background: var(--sync); }
#bar:has(.state.warn) #mark::after { background: var(--danger); }
#mark .count { position: absolute; right: -9px; top: -7px; min-width: 13px; height: 13px; padding: 0 3px; font-size: 9px; font-weight: 700; line-height: 13px; letter-spacing: 0; color: #0b1a05; background: var(--sync); border-radius: 7px; box-shadow: 0 0 0 2px var(--ring); }
#mark .count:empty { right: -1px; top: -1px; min-width: 9px; height: 9px; padding: 0; }
#bar:not(.folded) #mark .count { display: none; }

#theme .moon, [data-theme="light"] #theme .sun { display: none; }
[data-theme="light"] #theme .moon { display: block; }

.title { min-width: 0; flex: none; max-width: 280px; margin: 0 8px 0 12px; }
.title .name { font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title .state { display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 1.35; color: var(--text-dim); white-space: nowrap; overflow: hidden; }
.title .state::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.title .state.live::before { background: var(--sync); box-shadow: 0 0 8px var(--sync); }
.title .state.live { display: none; }
.title .state.warn::before { background: var(--danger); }

.tools { display: flex; align-items: center; gap: 4px; flex: none; }
.tools button, .toggle {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 10px;
    font: inherit; font-size: 13px;
    color: var(--text);
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}
.tools button:hover:not(:disabled), .toggle:hover { background: var(--surface-2); }
.tools button:disabled { opacity: .45; cursor: default; }
.tools button.pending { color: var(--accent-text); background: var(--accent-soft); border-color: var(--accent-line); }
.tools button.on { background: var(--surface-2); border-color: var(--border); }
.segment { display: flex; gap: 2px; }
.tools button svg { flex: none; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tools button svg .face { fill: currentColor; fill-opacity: .55; stroke: none; }
.tools [data-view] svg, #extents svg, #scenery-toggle svg { width: 17px; height: 17px; stroke-width: 1.5; }
.tools .count { font-weight: 600; color: var(--accent-text); }
.toggle { gap: 7px; color: var(--text-dim); }
.toggle input {
    -webkit-appearance: none; appearance: none;
    position: relative; flex: none; width: 28px; height: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.toggle input::before {
    content: ""; position: absolute; left: 2px; top: 2px; width: 10px; height: 10px;
    background: var(--text-dim); border-radius: 50%;
    transition: transform .15s, background .15s;
}
.toggle input:checked { background: var(--accent-soft); border-color: var(--accent-line); }
.toggle input:checked::before { background: var(--sync); transform: translateX(12px); }
.toggle input:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.toggle:has(input:checked) { color: var(--text); }
.rule { width: 1px; height: 18px; margin: 0 4px; background: var(--border); }

#views {
    position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%);
    gap: 2px;
    padding: 3px;
}
#bar[hidden] ~ #views { display: none; }
#views button { padding: 5px 10px; font-size: 12.5px; border: 0; border-radius: 9px; }
#views [data-view], #extents, #scenery-toggle { position: relative; padding: 5px 7px; }
#views .rule { height: 16px; margin: 0 3px; }
#views .tip {
    display: none;
    position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%);
    align-items: center; gap: 7px;
    padding: 3px 4px 3px 9px;
    font-size: 12px; line-height: 18px; white-space: nowrap;
    color: var(--text);
    background: var(--solid);
    border: 1px solid var(--border); border-radius: 7px;
    box-shadow: var(--pop);
    pointer-events: none;
}
#views kbd { min-width: 18px; padding: 0 4px; font: inherit; font-size: 11px; line-height: 16px; text-align: center; color: var(--text-dim); border: 1px solid var(--border); border-radius: 4px; }
#extents .tip { left: auto; right: 0; transform: none; }
#views button:focus-visible .tip { display: flex; }

@media (hover: hover) {
    #views, #info { opacity: .8; transition: opacity .2s; }
    #views:hover, #views:focus-within, #info:hover { opacity: 1; }
    #views button:hover .tip { display: flex; }
}

#people { left: 12px; top: 72px; width: 200px; max-height: calc(100% - 84px); padding: 0 6px 6px; }
#people ul { list-style: none; }
#people ul:not(:empty) { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
#me { display: flex; align-items: center; gap: 8px; padding: 7px 9px 7px 8px; }
#colour {
    -webkit-appearance: none; appearance: none;
    flex: none; width: 13px; height: 13px; padding: 0;
    background: none; border: 0; border-radius: 50%;
    cursor: pointer;
}
#colour:hover, #colour:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 2px; }
#colour::-webkit-color-swatch-wrapper { padding: 0; }
#colour::-webkit-color-swatch { border: 0; border-radius: 50%; }
#colour::-moz-color-swatch { border: 0; border-radius: 50%; }
#people li button {
    width: 100%;
    display: flex; align-items: center; gap: 9px;
    padding: 7px 8px;
    font: inherit;
    color: var(--text);
    text-align: left;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}
#people li button:hover:not(:disabled) { background: var(--surface-2); }
#people li button:disabled { cursor: default; }
#people li button.followed { background: var(--accent-soft); border-color: var(--accent-line); }
#people li { display: flex; align-items: center; gap: 2px; }
#people li button:not(.eye) { flex: 1; min-width: 0; }
#people li button.eye {
    flex: none; width: 28px; height: 28px; padding: 0;
    justify-content: center;
    color: var(--text-dim);
}
#people li button.eye.off { color: var(--text-faint); }
#people li button.eye svg, #cameras-all svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#cameras-all {
    width: 100%;
    display: flex; align-items: center; gap: 9px;
    margin-top: 2px; padding: 6px 0 6px 8px;
    font: inherit; font-size: 12px;
    color: var(--text-dim);
    text-align: left;
    background: none; border: 1px solid transparent; border-radius: 8px;
    cursor: pointer;
}
#cameras-all:hover { background: var(--surface-2); color: var(--text); }
#cameras-all > span:first-of-type { flex: 1; }
/* Laid out as a person's row: the camera over the colour dots, the eye in the same box as theirs. */
#cameras-all > svg { margin: 0 -2.5px; }
#cameras-all .state { display: inline-flex; justify-content: center; width: 26px; }
#cameras-all.off { color: var(--text-faint); }
#people .dot { width: 10px; height: 10px; flex: none; border-radius: 50%; }
#people .who { min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#people .badge { flex: none; display: inline-flex; align-items: center; height: 15px; padding: 0 5px; border-radius: 6px; font: 700 9px/1 var(--sans); }
#people .badge.ai { background: var(--ai); color: var(--ai-text); }
#people .badge.tv { background: var(--tv); color: var(--tv-text); }
#people .badge svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#people .badge.busy { margin-left: auto; padding: 0 3px; color: var(--accent-text); background: var(--accent-soft); }
#people .badge.busy .icon { width: 12px; height: 12px; }
#people .badge.busy .icon, #info .busy .icon { animation: drift 1.1s ease-in-out infinite alternate; }
@keyframes drift { from { opacity: .45; } to { opacity: 1; } }

#info {
    position: fixed; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom));
    display: flex; align-items: center;
    max-width: calc(50% - 220px);
    height: 34px; padding: 0 3px;
    font-size: 12px; color: var(--text-dim);
    overflow: hidden;
}
#info > span { display: inline-flex; align-items: center; gap: 6px; padding: 0 9px; white-space: nowrap; }
#info > span:not([hidden]) ~ span:not([hidden]) { border-left: 1px solid var(--border); }
#info b { font-weight: 600; color: var(--text); }
#info .icon { width: 15px; height: 15px; color: var(--text-dim); }
#info-provider .icon, #info .busy .icon, #info .bolt { color: var(--accent-text); }
#info .dot { flex: none; width: 7px; height: 7px; margin-left: 2px; border-radius: 50%; }
#info > #info-saved, #info > #info-quick { gap: 5px; }
#info > #info-activity { gap: 12px; }
#info .busy { display: inline-flex; align-items: center; gap: 5px; }
#info .busy b { color: var(--accent-text); }

#following, #pointing { left: 50%; bottom: 104px; transform: translateX(-50%); padding: 7px 14px; font-size: 13px; }
#pointing { bottom: 146px; display: flex; align-items: center; gap: 12px; }
#pointing button { font: inherit; color: var(--text-dim); background: none; border: 0; text-decoration: underline; cursor: pointer; }
#pointing button:hover { color: var(--text); }

#busy { left: 50%; bottom: 62px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 9px 16px 9px 12px; font-size: 13px; }
.spinner {
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--sync);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#note { right: 12px; bottom: 12px; max-width: 360px; padding: 9px 13px; font-size: 12.5px; color: var(--text-dim); }
#note.error { color: var(--danger); }

@media (max-width: 1180px) {
    .tools button svg + span:not(.count) { display: none; }

    #layers { top: 72px; }
}

/* Here the chat panel would reach the view bar in the middle. */
@media (max-width: 1020px) {
    #views { left: auto; right: max(12px, env(safe-area-inset-right)); transform: none; }
    #info { max-width: calc(100% - 420px); }
    #note { bottom: 62px; }
}

@media (max-width: 900px) {
    #bar .rule { display: none; }
    #people { width: 160px; }
}

@media (pointer: coarse) {
    .tools button, .toggle { min-height: 36px; }

    .panel > .grab { height: 40px; }
    .panel > .grab .close { width: 36px; height: 36px; padding: 11px; }

    /* iOS zooms the page into a field whose text is smaller than this. */
    #chat-input, .field input { font-size: 16px; }

    .files .open { padding: 11px 10px; }
    .files .forget { width: 36px; height: 36px; }

    #layers .caret { width: 30px; height: 38px; font-size: 12px; }
    #layers .toggle { padding: 9px 8px 9px 4px; font-size: 14px; }
    #people li button { padding: 10px 8px; }
    #me { padding: 10px 9px 10px 8px; }
    #colour { width: 22px; height: 22px; }

    #chat-list .bubble { max-width: calc(100% - 68px); }
    #chat-list .actions button { width: 32px; height: 32px; padding: 7px; border-radius: 16px; }
    #chat-list .actions svg { width: 18px; height: 18px; }
    #chat-list .reaction { padding: 3px 2px; font-size: 12px; }
    #chat-list .reaction svg { width: 14px; height: 14px; }
    #chat .chip { padding: 5px 11px 5px 9px; font-size: 12px; border-radius: 13px; }
    #chat .chip svg { width: 13px; height: 13px; }
    #chat-floats button { padding: 6px 12px; font-size: 12px; border-radius: 15px; }
    #chat-replying button { width: 28px; height: 28px; font-size: 17px; }
    #chat-form button { width: 40px; height: 36px; padding: 9px 11px; }
    #chat-form #chat-send { width: 32px; height: 32px; padding: 7px; }
    #chat-box { border-radius: 20px; }
    #chat-form svg { width: 18px; height: 18px; }
    #chat-picker { padding: 4px 6px; border-radius: 22px; }
    #chat-picker button { width: 40px; height: 40px; padding: 9px; border-radius: 20px; }
    #chat-picker svg { width: 22px; height: 22px; }
    #chat-suggestions { max-height: 220px; }
    #chat-suggestions button { padding: 9px 14px 9px 9px; font-size: 14px; }
}

@media (max-width: 700px), (max-height: 520px) {
    .panel > .grip { display: none; }
    .panel > .grab { cursor: default; }
}

/* A phone held upright: the panels come up from the bottom as sheets, over a dock that opens them. */
@media (max-width: 700px) {
    #start { padding: 28px 20px 24px; }

    #info { display: none; }

    #chrome { left: 8px; right: 8px; top: max(8px, env(safe-area-inset-top)); bottom: max(8px, env(safe-area-inset-bottom)); gap: 8px; }

    #bar:not(.folded) { align-self: stretch; }
    #bar .more { flex: 1; }
    #bar .title { flex: 1 1 auto; max-width: none; }
    #bar .tools button { padding: 5px 7px; }
    #bar .toggle { padding: 5px 6px; }

    #views { left: 50%; right: auto; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 64px); transform: translateX(-50%); }
    #chrome:has(.panel:not([hidden])) #views { display: none; }

    #status { display: flex; flex-direction: column; align-items: center; gap: 6px; align-self: stretch; pointer-events: none; }
    #status > * { position: static; transform: none; max-width: 100%; pointer-events: auto; }

    #dock {
        position: fixed; left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); transform: translateX(-50%);
        display: flex; gap: 2px;
        padding: 4px;
        border-radius: 16px;
    }
    #bar[hidden] ~ #dock { display: none; }
    #dock button { position: relative; flex-direction: column; gap: 1px; min-width: 76px; padding: 6px 10px 4px; font-size: 11px; border-radius: 12px; }
    #dock button svg { width: 20px; height: 20px; }
    #dock button svg + span:not(.count) { display: inline; }
    #dock .count { position: absolute; left: calc(50% + 5px); top: 3px; padding: 0 5px; font-size: 10px; line-height: 15px; color: #0b1a05; background: var(--sync); border-radius: 8px; }

    #people, #layers, #chat {
        left: 8px; right: 8px; top: auto; bottom: max(calc(max(8px, env(safe-area-inset-bottom)) + 66px), calc(var(--keyboard) + 8px));
        width: auto; max-height: min(58%, calc(100% - var(--keyboard) - 116px));
    }
    #chat { height: 50%; }

    body.pointing #chat { display: none; }
}

/* A phone on its side: one row of chrome, and the panels stand along the right edge. */
@media (max-height: 520px) and (min-width: 701px) {
    #info { display: none; }
    #people, #layers, #chat {
        left: auto; right: max(12px, env(safe-area-inset-right)); top: 72px; bottom: auto;
        width: 300px; max-height: calc(100% - 84px - var(--keyboard));
    }
    #chat { height: auto; bottom: max(12px, calc(var(--keyboard) + 8px)); }
    #note { left: max(12px, env(safe-area-inset-left)); right: auto; bottom: 62px; }
    #views { left: max(12px, env(safe-area-inset-left)); right: auto; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .toggle input, .toggle input::before, #bar .more, #views, #info { transition: none; }
    #people .badge.busy .icon, #info .busy .icon { animation: none; }
    .spinner { animation-duration: 2.4s; }
}
