/* RemoteTeams
   Clean and calm. Light (default): white + neutral greys. Dark: slate. Accent = the logo's teal (buttons, card titles). Inter.
   The only colours are functional: red for the helper's pointer, "live" and stop; green for "connected".
   Light values here (the default); html.dark-mode (visitor's choice, set in index.html) switches them. */
:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --subtle: #f5f5f5;
    --text: #0a0a0a;
    --muted: #5f5f5f;
    --border: #e4e4e4;
    --border-strong: #cfcfcf;
    --ink: #0a0a0a;
    --ink-hover: #2b2b2b;
    --ink-text: #ffffff;
    --accent: #0d9488;       /* the logo's teal: buttons, card titles, icon badges, focus */
    --accent-hover: #0f766e;
    --accent-text: #ffffff;
    --accent-soft: #e2f4f2;
    --accent-fg: #0d9488;    /* accent-coloured icons/text on the page background */
    --brand-teal: #0d9488;   /* "Teams" in the logo */
    --danger: #c62828;
    --ok: #1b7a3e;
    --pointer: #e5133a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 28px rgba(0, 0, 0, .06);
    --radius: 12px;
}
html.dark-mode {
    /* Slate + Sage */
    --bg: #21272b;
    --surface: #293035;
    --subtle: #30383e;
    --text: #eef2f1;
    --muted: #a6b0ad;
    --border: #384147;
    --border-strong: #4a545b;
    --ink: #eef2f1;
    --ink-hover: #d6dcda;
    --ink-text: #21272b;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-text: #042f2e;
    --accent-soft: #1f3b3b;
    --accent-fg: #2dd4bf;
    --brand-teal: #2dd4bf;
    --danger: #ef6b62;
    --ok: #7fd09a;
    --pointer: #ff2d55;
    --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 10px 30px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}
main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 24px 48px; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; font-weight: 500; letter-spacing: -.02em; }
a { color: var(--text); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.error { color: var(--danger); font-weight: 500; }
.row { display: flex; flex-wrap: wrap; align-items: center; }
.gap { gap: 10px; }
.end { justify-content: flex-end; }
.center { text-align: center; }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }

/* Icons */
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

.warn { display: flex; gap: 10px; align-items: flex-start; background: var(--subtle); color: var(--text); padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); }
.warn .i { margin-top: 3px; color: var(--muted); }

/* ---------- Header / footer ---------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 24px; max-width: 1040px; width: 100%; margin: 0 auto;
    padding-top: max(18px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 400; font-size: 1.35rem; letter-spacing: .005em; }
.brand b { color: var(--brand-teal); font-weight: 700; }
.theme-toggle {
    display: grid; place-items: center; background: transparent; color: var(--muted);
    border: 1px solid var(--border); border-radius: 999px; width: 40px; height: 40px; cursor: pointer;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle .sun { display: none; }
html.dark-mode .theme-toggle .sun { display: block; }
html.dark-mode .theme-toggle .moon { display: none; }
.footer {
    display: flex; flex-wrap: wrap; gap: 6px 20px; justify-content: space-between;
    max-width: 1040px; width: 100%; margin: 0 auto; color: var(--muted);
    padding: 24px 24px max(24px, env(safe-area-inset-bottom)); font-size: .85rem; border-top: 1px solid var(--border);
}

/* ---------- Views ---------- */
.view { display: none; }
.view.active { display: block; animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons & inputs ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 46px; padding: 10px 20px; border-radius: 8px;
    border: 1px solid var(--border-strong); background: transparent; color: var(--text);
    font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { border-color: var(--text); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary .i { transition: transform .15s ease; }
.btn.primary:hover .i { transform: translateX(2px); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
/* Blue (from the logo's teal→blue gradient): "Stop sharing" */
.btn.blue { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.blue:hover { background: #1d4ed8; border-color: #1d4ed8; }
html.dark-mode .btn.blue { background: #60a5fa; color: #0b1a2e; border-color: #60a5fa; }
html.dark-mode .btn.blue:hover { background: #93c5fd; border-color: #93c5fd; }
html.dark-mode .btn.danger { color: #0b0b0b; }
.btn.big { min-height: 54px; font-size: 1.02rem; padding: 14px 24px; }
.btn.link { background: none; border: none; color: var(--muted); padding-left: 0; }
.btn.link:hover { color: var(--text); }
input {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 8px; padding: 10px 14px; min-height: 48px;
}
input::placeholder { color: var(--muted); opacity: .7; }
input:focus { outline: none; border-color: var(--accent-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-fg) 22%, transparent); }
:focus-visible { outline: 2px solid var(--accent-fg); outline-offset: 2px; }

/* ---------- Home ---------- */
.intro { text-align: center; padding: 24px 0 44px; }
.intro h1 { font-size: clamp(2.3rem, 5.5vw, 3.6rem); font-weight: 300; letter-spacing: -.035em; }
.lead { font-size: clamp(1.02rem, 2vw, 1.15rem); color: var(--muted); max-width: 640px; margin: 0 auto; font-weight: 400; }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 760px) { .choices { grid-template-columns: minmax(0, 1fr); } }
.choice {
    display: flex; flex-direction: column; align-items: flex-start;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    padding: 36px; transition: border-color .2s ease, box-shadow .2s ease;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}
.choice:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.choice-icon {
    width: 52px; height: 52px; padding: 13px; border-radius: 12px; stroke-width: 1.5; margin-bottom: 24px;
    background: var(--accent-soft); color: var(--accent-fg);
}
.choice h2 { font-size: 1.7rem; font-weight: 500; letter-spacing: -.025em; margin-bottom: 10px; color: var(--accent-fg); }
.choice p { color: var(--muted); margin: 0 0 28px; max-width: 360px; }
.choice > .btn { margin-top: auto; align-self: stretch; }
.join-form { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; margin-top: auto; }
.join-form input { min-width: 0; }
.code-input { flex: 1 1 140px; font-size: 1.3rem; font-weight: 500; letter-spacing: .16em; text-align: center; font-variant-numeric: tabular-nums; }
.name-input { flex: 1 1 160px; }
.join-form .btn { flex: 1 1 100%; }
@media (max-width: 420px) { .choice { padding: 26px; } }

.assurances {
    list-style: none; padding: 0; margin: 44px 0 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 36px;
    color: var(--muted); font-size: .93rem;
}
.assurances li { display: flex; align-items: center; gap: 8px; }
.more { max-width: 620px; margin: 36px auto 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.more summary {
    cursor: pointer; list-style: none; padding: 16px 0; font-weight: 500; display: flex; justify-content: space-between; align-items: center;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "+"; font-size: 1.3rem; font-weight: 300; color: var(--muted); }
.more[open] summary::after { content: "–"; }
.more p { margin: 0 0 18px; color: var(--muted); }
.caution { text-align: center; color: var(--muted); font-size: .85rem; margin: 22px 0 0; }

/* ---------- Panels (share / view / ended) ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; margin-top: 16px; }
.panel.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.panel h2 { font-size: 1.8rem; font-weight: 400; }
.source-buttons { display: flex; flex-direction: column; gap: 10px; margin: 22px 0; }
.check { display: flex; align-items: center; gap: 10px; margin: 6px 0 16px; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

.live-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 14px; }
.code-display { font-size: clamp(2.6rem, 10vw, 4rem); font-weight: 300; letter-spacing: .12em; font-variant-numeric: tabular-nums; line-height: 1; }
.status { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; font-weight: 500; font-size: .86rem; border: 1px solid var(--border); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.waiting::before { animation: pulse 1.4s infinite; }
.status.live::before { background: var(--danger); animation: pulse 1.4s infinite; }
.status.ok::before { background: var(--ok); }
@keyframes pulse { 50% { opacity: .25; } }

.live-body { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; margin-top: 24px; }
@media (max-width: 820px) { .live-body { grid-template-columns: minmax(0, 1fr); } }
.preview { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 10; }
.preview video { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; }
.chat-log {
    flex: 1; min-height: 160px; max-height: 340px; overflow-y: auto; background: var(--subtle);
    border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 6px;
}
.msg { max-width: 85%; padding: 7px 12px; border-radius: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; color: var(--muted); font-size: .85rem; background: none; padding: 2px; }
.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form input { flex: 1; min-width: 0; min-height: 44px; }
.chat-form .btn { min-height: 44px; }

/* ---------- Viewer ---------- */
.viewer {
    display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; overflow: hidden; height: calc(100vh - 160px); height: calc(100dvh - 160px); min-height: 360px;
}
.viewer:fullscreen { height: 100vh; border-radius: 0; border: none; }
.toolbar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.tool-group { display: flex; flex-wrap: wrap; gap: 4px; }
.tbtn {
    position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 38px; min-width: 38px; padding: 6px 10px; border-radius: 8px;
    border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; font-weight: 500; font-size: .92rem; cursor: pointer;
}
.tbtn:hover { background: var(--subtle); }
.tbtn[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent-fg); }
.tbtn.danger { color: var(--danger); }
.badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--pointer); color: #fff; font: 600 11px/18px Inter, system-ui, sans-serif; text-align: center; }
.viewer-body { flex: 1; display: flex; min-height: 0; position: relative; }
/* touch-action: none – the viewer handles pinch-zoom and dragging itself (see script.js), also in full screen */
.stage { flex: 1; position: relative; overflow: auto; background: #050505; touch-action: none; }
.stage:not(.fit) { display: flex; }   /* centres a small picture; a big one scrolls from its edge */
.stage video { display: block; margin: auto; flex: none; user-select: none; -webkit-user-select: none; }
/* Fit: the picture fills the whole viewer (and the whole monitor in full screen), keeping its shape */
.stage.fit video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage.pointing video { cursor: crosshair; }
.drawer { width: 320px; max-width: 100%; border-left: 1px solid var(--border); padding: 10px; background: var(--surface); }
.drawer .chat-log { max-height: none; }
@media (max-width: 700px) {
    .viewer { height: calc(100dvh - 130px); }
    .drawer { position: absolute; inset: auto 0 0 0; width: 100%; height: 55%; border-left: none; border-top: 1px solid var(--border); box-shadow: 0 -8px 24px rgba(0,0,0,.3); }
    .toolbar { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
    .toolbar::-webkit-scrollbar { display: none; }
    .tool-group { flex-wrap: nowrap; flex-shrink: 0; }
    #viewStatus { flex-shrink: 0; }
    .tbtn { padding: 6px 8px; white-space: nowrap; }
}

/* Pointer shown where the helper tapped (red so it shows on any screen) */
.pointer {
    position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%;
    border: 3px solid var(--pointer); background: color-mix(in srgb, var(--pointer) 22%, transparent); pointer-events: none;
    animation: ping 1.4s ease-out infinite; z-index: 2;
}
@keyframes ping {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--pointer) 55%, transparent); }
    100% { box-shadow: 0 0 0 20px transparent; }
}

/* ---------- Misc ---------- */
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent-fg); margin: 8px auto 18px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-icon { width: 52px; height: 52px; color: var(--ok); stroke-width: 1.3; margin-bottom: 12px; }
.big-icon.bad { color: var(--danger); }
dialog {
    border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
    padding: 30px; max-width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { font-size: 1.4rem; font-weight: 500; }
.dialog-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-fg); margin-bottom: 16px; }
.dialog-icon .i { width: 22px; height: 22px; }
.toast {
    position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
    background: var(--ink); color: var(--ink-text); padding: 10px 18px; border-radius: 999px; font-weight: 500;
    z-index: 50; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center;
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
/* While viewing someone's screen, use (almost) the whole width of big monitors */
main:has(#viewLive:not([hidden])) { max-width: min(1800px, 100%); }

/* Chat header with the "Open automatically" switch */
.chat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chat-head .label { margin: 0; }
.auto-open { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: .82rem; color: var(--muted); cursor: pointer; }
.auto-open input { width: 16px; height: 16px; min-height: 0; margin: 0; accent-color: var(--accent); }
.chat-head .tbtn { min-height: 32px; min-width: 32px; padding: 4px; }
/* A new message makes the chat flash briefly */
.chat-log.flash { animation: chatflash 1.4s ease; }
@keyframes chatflash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* New-message banner (bottom of the screen, big enough to notice on a phone) */
.msg-banner {
    position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
    z-index: 60; display: flex; align-items: center; gap: 12px; width: min(560px, calc(100vw - 24px));
    padding: 14px 16px; border-radius: 14px; border: none; cursor: pointer; text-align: left; font: inherit;
    background: var(--accent); color: var(--accent-text); box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
    animation: bannerin .3s ease;
}
.msg-banner .i { width: 24px; height: 24px; }
.mb-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.mb-body b { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
#msgBannerText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.02rem; font-weight: 500; }
.mb-cta { font-weight: 700; padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, .2); }
@keyframes bannerin { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Sharing paused (sharer's preview and helper's viewer) */
.paused {
    position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; padding: 20px; text-align: center; background: #111416; color: #e8ecee;
}
.paused b { font-size: 1.15rem; font-weight: 500; }
.paused span { color: #a3adb2; max-width: 360px; }

/* Links in chat messages */
.msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.msg.them a { color: var(--accent-fg); }

/* DEV-only connection badge */
.dev-conn {
    position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 70;
    max-width: calc(100vw - 24px); padding: 5px 12px; border-radius: 999px; font: 600 .75rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
    background: #374151; color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.25); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    pointer-events: none;
}
.dev-conn.direct { background: #166534; }
.dev-conn.relay { background: #1d4ed8; }
.dev-conn.failed { background: #b91c1c; }

/* Hand-over code in the helper's Invite dialog */
.invite-code { font-size: 2.6rem; text-align: center; margin: 6px 0 20px; color: var(--accent-fg); }
.msg.prev { opacity: .85; }
