/* DeckPilot Web Deck. Dark, purple accent; system fonts only (no network fonts on a LAN page). */
:root {
  --bg: #0d0d12; --bg-2: #1a1a24; --bg-3: #252535; --line: #34344a; --ink: #f3f3f8; --ink-2: #a9a9bd;
  --accent: #8b5cf6; --accent-2: #c4b5fd; --good: #10b981; --warn: #f59e0b; --bad: #ef4444;
  --deck-accent: #8b5cf6;
  --g-idle: #6b7280; --g-thinking: #8b5cf6; --g-needs: #f59e0b; --g-done: #10b981; --g-error: #ef4444;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.4; overflow: hidden; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea, select { font: inherit; color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

#app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 10px); }

/* ---------- underglow: blurred edge light behind the deck ---------- */
#underglow { position: fixed; inset: 0; pointer-events: none; z-index: 0; --ug: transparent; }
#underglow::before { content: ""; position: absolute; inset: 6px; border-radius: 28px; box-shadow: inset 0 0 38px 6px var(--ug), 0 0 0 1px color-mix(in srgb, var(--ug) 40%, transparent); opacity: .55; transition: box-shadow .4s ease, opacity .4s ease; }
#underglow.urgent::before { animation: ugbreathe 2.6s ease-in-out infinite; }
@keyframes ugbreathe { 50% { opacity: .9; } }

/* ---------- top bar ---------- */
#topbar { display: flex; align-items: center; gap: 10px; min-height: 40px; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.conn { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); font-family: var(--font); font-size: 13px; color: var(--ink); min-width: 0; flex: 0 1 auto; white-space: nowrap; }
.conn span { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn small { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.conn.ok i { background: var(--good); } .conn.bad i { background: var(--bad); }
.tabs { display: inline-flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; font-family: var(--font); }
.tabs button { padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tabs button.on { background: #221b33; color: #fff; box-shadow: inset 0 0 0 1px var(--accent); }
.nbadge { background: var(--warn); color: #000; border-radius: 999px; padding: 0 6px; font-size: 10.5px; font-weight: 800; line-height: 16px; }
.ctx { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.tools { display: inline-flex; gap: 4px; flex: none; margin-left: auto; }
.tools button { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); }
.tools button:hover { background: var(--bg-2); color: var(--ink); }
.tools svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.tab-pair #btnDecks, body.tab-pair .ctx { visibility: hidden; }

/* ---------- views ---------- */
#stage { position: relative; flex: 1; min-height: 0; border-radius: 22px; margin-top: 6px; background: linear-gradient(180deg, #121219, #0b0b11); overflow: hidden; }
#pairView, #deckView, #agentsView { position: absolute; inset: 0; display: none; }
body.tab-pair #pairView { display: flex; }
body.tab-deck #deckView { display: flex; }
body.tab-agents #agentsView { display: flex; }

/* ---------- pairing ---------- */
#pairView { align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.pairform { max-width: 380px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pairform h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.pairform p { margin: 0; color: var(--ink-2); font-size: 14px; }
.logo { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; width: 54px; height: 54px; padding: 9px; border-radius: 15px; background: var(--accent); box-shadow: 0 10px 30px rgba(139, 92, 246, .4); }
.logo i { background: #fff; border-radius: 3px; } .logo i:nth-child(2), .logo i:nth-child(3) { opacity: .7; }
.digits { display: flex; gap: 10px; }
.digits input { width: 56px; height: 66px; text-align: center; font-family: var(--mono); font-size: 30px; background: #0a0a0f; border: 1.5px solid var(--line); border-radius: 14px; caret-color: var(--accent); }
.digits input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px rgba(139, 92, 246, .2); }
.pinform { display: flex; gap: 10px; align-items: center; }
.pinform input { width: 220px; height: 56px; text-align: center; font-family: var(--mono); font-size: 24px; letter-spacing: .18em; background: #0a0a0f; border: 1.5px solid var(--line); border-radius: 14px; caret-color: var(--accent); }
.pinform input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px rgba(139, 92, 246, .2); }
/* pairing modes: DeckPilot PIN (default) or the 4-digit on-screen PIN (LAN, first device / fallback) */
body:not(.pin-screen) .digits, body:not(.pin-screen) #newPin, body.pin-screen .pinform, body.relay #pinModeLink, body.relay .pinform, body.relay .digits, body.relay #newPin { display: none; }
#remoteURLIn { width: 60%; min-width: 0; background: #0a0a0f; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-family: var(--mono); font-size: 12px; }
.linkbtn { background: none; color: var(--accent-2, #a78bfa); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; padding: 4px; }
.pinsetbody { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.pinsetbody label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.pinsetbody label[hidden] { display: none; }
.pinsetbody input { width: 150px; height: 42px; text-align: center; font-family: var(--mono); font-size: 20px; letter-spacing: .2em; background: #0a0a0f; border: 1.5px solid var(--line); border-radius: 10px; }
.pinsetbody input:focus { border-color: var(--accent); outline: none; }
.pinsetbody .acts2 { display: flex; justify-content: flex-end; gap: 8px; }
.status { font-family: var(--mono); font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; min-height: 18px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.status.ok i { background: var(--good); } .status.bad { color: #fca5a5; } .status.bad i { background: var(--bad); }
.pbtn { border-radius: 999px; padding: 9px 18px; background: var(--accent); color: #fff; font-weight: 800; }
.pbtn.ghost { background: var(--bg-3); border: 1px solid var(--line); color: var(--ink); }
.pbtn.bad { background: #3a1416; border: 1px solid var(--bad); color: #fecaca; }

/* ---------- deck ---------- */
#deckView { flex-direction: column; align-items: stretch; }
#deckArea { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0; touch-action: none; }
/* iPhone deck background (DeckTheme): purple gradient with two radial glows. A layout background overrides it. */
#stage { background: radial-gradient(circle at 92% 5%, rgba(139, 92, 246, .22), rgba(139, 92, 246, .06) 45%, transparent 72%), radial-gradient(circle at 8% 95%, rgba(109, 40, 217, .18), rgba(109, 40, 217, .05) 45%, transparent 72%), linear-gradient(135deg, #1b0e2e 0%, #0d0918 55%, #150a26 100%); }
.deck { display: grid; gap: var(--gap, 6px); padding: var(--pad, 8px); position: relative; flex: none; transform-origin: center; }
/* Portrait: the landscape canvas turns -90° (ButtonGridView.useRotated); tile content turns back below. */
.deck.rotated { transform: rotate(-90deg); }
.key > .kc, .ctl > .kc { display: flex; flex-direction: column; align-items: inherit; justify-content: inherit; gap: inherit; width: 100%; height: 100%; min-height: 0; min-width: 0; }
.deck.rotated .key > .kc, .deck.rotated .ctl > .kc { position: absolute; left: 50%; top: 50%; width: var(--kh, 100%); height: var(--kw, 100%); transform: translate(-50%, -50%) rotate(90deg); }
/* Content turns smoothly only when the orientation actually changes (DeckButtonView .smooth(0.5)). */
.deck.orienting .key > .kc, .deck.orienting .ctl > .kc { transition: transform .5s cubic-bezier(.2,.8,.2,1); }
.deck.no-labels .key .lbl { display: none; }
.deck.freeform { display: block; }
.deck .empty { color: var(--ink-2); font-family: var(--mono); font-size: 13px; }
.pagedots { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 999px; background: rgba(28, 24, 40, .9); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); box-shadow: inset 0 0 0 .5px var(--line); }
#deckView.has-touchbar .pagedots { bottom: calc(64px + 8px + var(--safe-b)); }
.pagedots .dot { width: 8px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .3); transition: width .45s cubic-bezier(.2,.9,.3,1.1), background .2s; }
.pagedots .dot.on { width: 20px; background: var(--deck-accent); }

/* Tiles follow DeckButtonView: radius 14, glass over the deck background, 1px white .06 border,
   icon = min(w,h) × .7 (.9 without a label), label 11pt medium white .6, press = scale .95 + 3pt down. */
.key { position: relative; min-width: 0; min-height: 0; border-radius: 14px; background: var(--key-bg, rgba(34, 30, 52, .62)); -webkit-backdrop-filter: blur(18px) saturate(1.3); backdrop-filter: blur(18px) saturate(1.3); border: 1px solid rgba(255, 255, 255, .06); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; cursor: pointer; overflow: hidden; background-size: cover; background-position: center; transition: transform .08s linear, box-shadow .2s, border-color .2s, filter .2s, opacity .15s; }
.key .ico { --isz: calc(var(--cell, 90px) * var(--icon-scale, .7)); width: var(--isz); height: var(--isz); max-width: 100%; max-height: 100%; flex: 0 1 auto; min-height: 0; display: grid; place-items: center; pointer-events: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .45)); }
.key.nolbl .ico { --isz: calc(var(--cell, 90px) * var(--icon-scale, .9)); }
.key .ico-img { width: 100%; height: 100%; object-fit: contain; border-radius: 18%; }
/* Running app: white 6pt dot at (11,11); on a rotated canvas it sits at the canvas top-right (screen top-left). */
.key.running::before { content: ""; position: absolute; top: 8px; left: 8px; width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .85); z-index: 2; }
.deck.rotated .key.running::before { left: auto; right: 8px; }
/* Frontmost Mac app (context_change / touch_bar_state.activeAppBundleID). */
.key.active-app { border: 2px solid color-mix(in srgb, var(--deck-accent) 95%, transparent); box-shadow: 0 0 22px color-mix(in srgb, var(--deck-accent) 75%, transparent); }
.key.active-app[style*="--key-bg"] { background-color: color-mix(in srgb, var(--deck-accent) 15%, var(--key-bg)); }
.key .ico-emoji { font-size: calc(var(--cell, 90px) * .34 * var(--icon-scale, 1)); line-height: 1; }
.key .ico-text { font-weight: 800; font-size: calc(var(--cell, 90px) * .2); line-height: 1.05; text-align: center; word-break: break-word; }
.key .ico-initial { width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--deck-accent) 22%, #14141c); color: var(--accent-2); font-weight: 800; font-size: calc(var(--cell, 90px) * .2); }
.key .lbl { max-width: 100%; height: 16px; line-height: 16px; font-size: var(--label-size, 11px); font-weight: 500; color: rgba(255, 255, 255, .6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; text-shadow: 0 1px 2px rgba(0, 0, 0, .5); flex: none; }
.key .sub { font-family: var(--mono); font-size: 9.5px; color: var(--ink-2); pointer-events: none; }
.key > .badge { position: absolute; top: 6px; right: 6px; z-index: 2; min-width: 24px; height: 24px; border-radius: 12px; background: var(--bad); color: #fff; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; padding: 0 7px; box-shadow: 0 1px 3px rgba(0, 0, 0, .4); }
.deck.rotated .key > .badge { top: auto; bottom: 6px; right: 6px; transform: rotate(90deg); }
.key.down { transform: scale(.95) translateY(3px); }
.key.down.active-app { box-shadow: 0 0 22px color-mix(in srgb, var(--deck-accent) 75%, transparent); }
.key.held { border-color: var(--accent-2); }
.key.ok { border-color: var(--good); }
.key.fail { border-color: var(--bad); animation: shake .3s; }
.key.locked { opacity: .55; }
@keyframes shake { 25% { translate: -3px 0; } 75% { translate: 3px 0; } }

/* Edit Deck: wiggle (random phase via --wig), lift, shake on reject */
.deck.editing > .key, .deck.editing > .ctl { animation: wiggle .26s ease-in-out var(--wig, 0s) infinite alternate; cursor: grab; }
.deck.editing > .key *, .deck.editing > .ctl * { pointer-events: none; }
.deck.editing > .drag-no { animation: none; opacity: .5; cursor: not-allowed; }
.deck.editing > .lifted { animation: none !important; z-index: 20; cursor: grabbing; transform: translate(var(--dx, 0), var(--dy, 0)) scale(1.08); box-shadow: 0 14px 34px rgba(0, 0, 0, .55), 0 0 0 2px var(--deck-accent, #8b5cf6); transition: box-shadow .15s; opacity: .96; }
.deck.editing > .shake, .deck > .shake { animation: shake .14s ease-in-out 3 !important; }
@keyframes wiggle { from { transform: rotate(calc(-1.5deg * var(--wigdir, 1))) scale(.96); } to { transform: rotate(calc(1.5deg * var(--wigdir, 1))) scale(.96); } }
html.reduce-motion .deck.editing > .drag-ok { outline: 1.5px dashed color-mix(in srgb, var(--deck-accent, #8b5cf6) 70%, transparent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .deck.editing > .drag-ok { outline: 1.5px dashed color-mix(in srgb, var(--deck-accent, #8b5cf6) 70%, transparent); outline-offset: 2px; } }
.editbar { position: absolute; top: 8px; left: 12px; right: 12px; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none; }
.editbar[hidden] { display: none; }
.editbar span { font-size: 12px; color: var(--ink-2); font-family: var(--mono); }
.editbar .editdone { pointer-events: auto; border-radius: 999px; padding: 7px 16px; background: var(--deck-accent, #8b5cf6); color: #fff; font-weight: 800; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }

/* agent keys */
.key.agent-key { align-items: stretch; justify-content: space-between; padding: 9px 10px; border-color: var(--c); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 45%, transparent); }
.key.agent-key .row { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.key.agent-key .agent { font-family: var(--mono); font-size: 10px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 5px; min-width: 0; overflow: hidden; }
.key.agent-key .agent i { width: 15px; height: 15px; border-radius: 4px; display: inline-grid; place-items: center; font-size: 8.5px; font-style: normal; font-weight: 800; color: #fff; background: #555; flex: none; }
.agent i.v-claude { background: #d97757; } .agent i.v-codex { background: #10a37f; } .agent i.v-gemini { background: #4285f4; }
.key.agent-key .badge { min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.key.agent-key .big { font-size: calc(var(--cell, 90px) * .26); font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.key.agent-key .lbl { text-align: left; }
.key.agent-key .state { font-family: var(--mono); font-size: 10px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.key.agent-key .state i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.key.agent-key.gone { opacity: .45; box-shadow: none; }
.key.agent-key.pulse { animation: pulse 1.6s ease-in-out infinite; }
.key.agent-key.breathe { animation: breathe 2.6s ease-in-out infinite; }
.key.agent-key.down { transform: scale(.94); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 6px color-mix(in srgb, var(--c) 30%, transparent); } 50% { box-shadow: 0 0 26px color-mix(in srgb, var(--c) 75%, transparent); } }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 10px color-mix(in srgb, var(--c) 35%, transparent); border-color: color-mix(in srgb, var(--c) 60%, #2c2c3e); } 50% { box-shadow: 0 0 34px color-mix(in srgb, var(--c) 90%, transparent); border-color: var(--c); } }

/* controls */
.ctl { position: relative; min-width: 0; min-height: 0; border-radius: 14px; background: #15151e; border: 1.5px solid #2c2c3e; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px; user-select: none; -webkit-user-select: none; touch-action: none; --ctl: var(--deck-accent); }
.ctl .lbl { font-size: 11.5px; font-weight: 700; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ctl.active { border-color: var(--ctl); }
.knob .dial { position: relative; width: min(70%, calc(var(--cell, 90px) * .56)); flex: none; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #2b2b3a, #14141c 70%); border: 1.5px solid #34344a; box-shadow: inset 0 0 0 5px #0e0e14, 0 6px 18px rgba(0, 0, 0, .5); cursor: ns-resize; }
.knob svg { position: absolute; inset: -8%; width: 116%; height: 116%; fill: none; stroke-width: 6; stroke-linecap: round; pointer-events: none; }
.knob svg .track { stroke: #26263a; } .knob svg .arc { stroke: var(--ctl); stroke-dasharray: 0 100; }
.knob .ind { position: absolute; left: 50%; top: 8%; width: 4px; height: 22%; margin-left: -2px; border-radius: 2px; background: var(--accent-2); transform-origin: 50% 190%; transition: transform .12s; }
.knob.effort .ind { transform-origin: 50% 190%; transition: transform .35s cubic-bezier(.2, .8, .2, 1); }
.knob .ticks i { position: absolute; left: 50%; top: 1%; width: 2px; height: 6%; margin-left: -1px; background: #4a4a66; transform-origin: 50% 816%; }
.knob .val { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 10px; color: var(--ink-2); text-align: center; line-height: 1.15; pointer-events: none; }
.knob .val b { color: var(--ink); font-size: 12px; }
.fader .track { position: relative; width: 26%; min-width: 18px; flex: 1; border-radius: 10px; background: #0e0e14; border: 1px solid #2c2c3e; overflow: hidden; cursor: ns-resize; }
.fader .fill { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(0deg, var(--ctl), color-mix(in srgb, var(--ctl) 40%, transparent)); }
.fader .thumb { position: absolute; left: -2px; right: -2px; height: 16px; border-radius: 5px; background: #e5e5f0; box-shadow: 0 2px 6px rgba(0, 0, 0, .6); }
.fader .val, .xy .val { font-family: var(--mono); font-size: 10px; color: var(--ink-2); }
.xy .pad { position: relative; width: 100%; flex: 1; border-radius: 10px; background: #0e0e14; border: 1px solid #2c2c3e; overflow: hidden; cursor: crosshair; }
.xy .cross-x, .xy .cross-y { position: absolute; background: #22222f; } .xy .cross-x { left: 0; right: 0; top: 50%; height: 1px; } .xy .cross-y { top: 0; bottom: 0; left: 50%; width: 1px; }
.xy .puck { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: var(--ctl); box-shadow: 0 0 14px var(--ctl); pointer-events: none; transition: left .05s, top .05s; }

/* joystick */
.joy .base { position: relative; width: min(70%, calc(var(--cell, 90px) * .58)); flex: none; aspect-ratio: 1; border-radius: 50%; background: #14141c; border: 1.5px solid #34344a; display: grid; place-items: center; cursor: grab; }
.joy .nub { width: 42%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #8b5cf6, #4c2d93); box-shadow: 0 4px 10px rgba(0, 0, 0, .6); transition: transform .18s cubic-bezier(.2, .8, .2, 1); pointer-events: none; }
.joy .arr { position: absolute; width: 24%; height: 24%; color: #55556f; font-size: 10px; display: grid; place-items: center; border-radius: 6px; }
.joy .arr:hover { color: var(--ink); }
.joy .arr.u { top: 0; left: 38%; } .joy .arr.d { bottom: 0; left: 38%; } .joy .arr.l { left: 0; top: 38%; } .joy .arr.r { right: 0; top: 38%; }
.radial { position: fixed; z-index: 40; pointer-events: none; opacity: 0; transform: translate(-50%, -50%) scale(.6); transition: opacity .18s, transform .22s cubic-bezier(.2, .9, .2, 1.2); }
.radial.open { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.radial .ring { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle, rgba(13, 13, 18, 0) 30%, rgba(20, 20, 30, .96) 32%); border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0, 0, 0, .7); }
.radial .sl { position: absolute; left: 50%; top: 50%; width: 76px; height: 46px; margin: -23px 0 0 -38px; border-radius: 12px; background: #1b1b26; border: 1px solid #2c2c3e; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; line-height: 1.15; transition: background .12s, border-color .12s, transform .12s; }
.radial .sl small { font-family: var(--mono); font-weight: 500; color: var(--ink-2); font-size: 9.5px; }
.radial .sl.hot { background: #2d2440; border-color: var(--accent); transform: var(--rt) scale(1.12) !important; color: #fff; }
.radial .ctr { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-family: var(--mono); font-size: 10px; color: var(--ink-2); text-align: center; }

/* ---------- agents panel ---------- */
#agentsView { padding: 10px; }
.agentview { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(170px, 230px) 1fr; gap: 10px; }
.inbox { display: flex; flex-direction: column; gap: 6px; overflow: auto; min-height: 0; }
.inbox-empty { color: var(--ink-2); font-size: 13px; padding: 10px; }
.sess { text-align: left; background: #1b1b26; border: 1.5px solid #2c2c3e; border-radius: 12px; padding: 8px 10px; display: grid; gap: 3px; transition: border-color .2s, box-shadow .2s; flex: none; }
.sess.sel { border-color: var(--accent); box-shadow: 0 0 14px rgba(139, 92, 246, .3); }
.sess.needs { border-color: var(--warn); }
.sess .v { font-family: var(--mono); font-size: 10px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; }
.sess .v i { width: 14px; height: 14px; border-radius: 4px; display: inline-grid; place-items: center; font-size: 8px; font-style: normal; font-weight: 800; color: #fff; }
.sess .v em { margin-left: auto; font-style: normal; }
.sess .r { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess .st { font-family: var(--mono); font-size: 10px; display: flex; align-items: center; gap: 5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; }
.sess .st i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.chat { background: #0a0a0f; border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat .hd { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 11px; color: var(--ink-2); flex-wrap: wrap; }
.chat .hd b { color: var(--ink); }
.hd-acts { display: inline-flex; gap: 4px; }
.hd-acts button { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 11px; font-weight: 700; color: var(--ink); }
.hd-acts button.bad { color: #fca5a5; }
.msgs { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; min-height: 0; }
.m { max-width: 92%; border-radius: 12px; padding: 7px 10px; line-height: 1.42; white-space: pre-wrap; word-break: break-word; }
.m.u { align-self: flex-end; background: #2d2440; border: 1px solid var(--accent); }
.m.u.local { opacity: .7; }
.m.a { align-self: flex-start; background: #171722; border: 1px solid var(--line); }
.m.t { align-self: flex-start; font-family: var(--mono); font-size: 11px; color: var(--ink-2); border: 1px dashed var(--line); }
.m.sys { align-self: center; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.m.p { align-self: stretch; max-width: none; background: #2a1f0e; border: 1px solid var(--warn); white-space: normal; }
.m .acts, .sheet .acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.m .acts button { border-radius: 8px; padding: 6px 11px; font-size: 12px; font-weight: 800; }
.typing { font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.quick { display: flex; gap: 6px; padding: 6px 8px 0; overflow-x: auto; }
.quick button { flex: none; background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-family: var(--mono); font-size: 11px; }
.chat .in { display: flex; gap: 6px; padding: 8px; align-items: flex-end; }
.chat .in textarea { flex: 1; resize: none; background: #121219; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 120px; }
.chat .in #sendReply { border-radius: 10px; background: var(--accent); color: #fff; font-weight: 800; padding: 9px 14px; }
.chat .in .mic { width: 38px; height: 38px; border-radius: 10px; background: var(--bg-3); display: grid; place-items: center; color: var(--ink-2); opacity: .5; cursor: not-allowed; }
.chat .in .mic svg, .sheet .steer .mic svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.sheet .steer .mic { width: 38px; flex: none; border-radius: 10px; background: var(--bg-3); color: var(--ink-2); padding: 0; display: grid; place-items: center; opacity: .5; cursor: not-allowed; }
.chat .in .mic.live, .sheet .steer .mic.live { opacity: 1; cursor: pointer; color: var(--ink); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.chat .in .mic.rec, .sheet .steer .mic.rec { background: var(--bad); color: #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 30%, transparent); animation: micpulse 1.1s ease-in-out infinite; }
@keyframes micpulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--bad) 12%, transparent); } }
pre.cmd { font-family: var(--mono); font-size: 12px; background: #0d0d14; border: 1px solid #2a2a3c; border-radius: 9px; padding: 8px 10px; margin: 6px 0 0; color: #e8e8f5; white-space: pre-wrap; word-break: break-word; max-height: 8.6em; overflow: auto; }
@media (max-width: 640px) {
  .agentview { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .inbox { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }
  .sess { min-width: 150px; }
  .ctx { display: none; }
}

/* ---------- buttons shared ---------- */
.b-ok { background: var(--good); color: #04130d; } .b-always { background: #2f2f44; color: var(--ink); } .b-no { background: var(--bad); color: #fff; }
.b-opt { background: #2d2440; color: var(--ink); border: 1px solid var(--accent) !important; }
.b-opt.on { background: var(--accent); color: #fff; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5, 5, 8, .55); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; z-index: 30; left: 50%; bottom: calc(var(--safe-b) + 10px); width: min(560px, calc(100% - 20px)); transform: translate(-50%, 130%); background: #171722; border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 16px; transition: transform .32s cubic-bezier(.2, .9, .2, 1); box-shadow: 0 20px 60px rgba(0, 0, 0, .7); max-height: 80vh; overflow: auto; }
.sheet.open { transform: translate(-50%, 0); }
.sheet .hd { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 26px 8px 0; }
.sheet .who { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .who .mono { font-weight: 500; color: var(--ink-2); font-size: 11px; }
.sheet .who i { width: 18px; height: 18px; border-radius: 5px; display: inline-grid; place-items: center; font-size: 10px; font-style: normal; font-weight: 800; color: #fff; flex: none; }
.sheet .tag { font-family: var(--mono); font-size: 10.5px; color: var(--warn); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.sheet .title { font-family: var(--mono); font-size: 14px; font-weight: 600; word-break: break-word; }
.sheet .q { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.sheet .acts button { flex: 1; min-width: 92px; border-radius: 12px; padding: 12px 8px; font-weight: 800; font-size: 14px; transition: transform .12s; }
.sheet .acts button:active { transform: scale(.96); }
.sheet .opts { display: grid; gap: 8px; }
.sheet .opts .b-opt { border-radius: 12px; padding: 11px 12px; text-align: left; display: grid; gap: 2px; font-size: 14px; }
.sheet .opts .b-opt small { color: var(--ink-2); font-size: 12px; }
.sheet .opts .b-opt.on small { color: #ede9fe; }
.steer-hint { margin-top: 12px; font-size: 11.5px; color: var(--ink-2); }
.sheet .steer { display: flex; gap: 6px; margin-top: 6px; }
.sheet .steer input { flex: 1; min-width: 0; background: #0d0d14; border: 1px solid #2a2a3c; border-radius: 10px; padding: 9px 10px; font-size: 14px; }
.sheet .steer button { border-radius: 10px; background: var(--accent); color: #fff; font-weight: 800; padding: 0 14px; }
.sheet-x { position: absolute; top: 8px; right: 10px; width: 28px; height: 28px; border-radius: 50%; font-size: 18px; color: var(--ink-2); }

/* ---------- overlays ---------- */
.overlay { position: fixed; z-index: 30; left: 50%; top: 50%; width: min(420px, calc(100% - 24px)); max-height: 78vh; transform: translate(-50%, -46%) scale(.97); opacity: 0; pointer-events: none; background: #171722; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .7); display: flex; flex-direction: column; transition: opacity .16s, transform .2s; }
.overlay.wide { width: min(520px, calc(100% - 24px)); }
.overlay.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.ohd { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.ohd button { width: 28px; height: 28px; border-radius: 50%; font-size: 18px; color: var(--ink-2); }
.overlay .list { overflow: auto; padding: 8px; display: grid; gap: 6px; }
.overlay .row { text-align: left; background: #1b1b26; border: 1px solid #2c2c3e; border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; }
.overlay .row small { color: var(--ink-2); font-family: var(--mono); font-size: 11px; }
.overlay .row.sel { border-color: var(--accent); }
.overlay .row.bad { color: #fca5a5; }
.overlay .row.clip { display: flex; align-items: center; gap: 10px; }
.overlay .row.clip img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; }
.overlay .row.clip span { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.overlay .muted { padding: 10px; font-size: 13px; }
.subgrid { display: grid; gap: 8px; padding: 12px; --cell: 80px; }
.subgrid .key { aspect-ratio: 1; }
.promptrow { display: flex; gap: 8px; padding: 12px; }
.promptrow input { flex: 1; min-width: 0; background: #0d0d14; border: 1px solid #2a2a3c; border-radius: 10px; padding: 9px 10px; }
.overlay .body { padding: 6px 16px 16px; overflow: auto; display: grid; gap: 8px; }
.overlay h4 { margin: 10px 0 0; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2); font-weight: 600; }
.tg { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.tg small { color: var(--ink-2); }
.tg input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.tg select { background: #0d0d14; border: 1px solid #2a2a3c; border-radius: 8px; padding: 5px 8px; max-width: 58%; }
.glowgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.glowgrid label { display: grid; justify-items: center; gap: 3px; font-family: var(--mono); font-size: 10px; color: var(--ink-2); }
.glowgrid input { width: 38px; height: 30px; border: 0; background: none; padding: 0; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv span { color: var(--ink-2); } .kv b { font-weight: 600; word-break: break-all; }

/* ---------- toast / debug ---------- */
.toast { position: fixed; z-index: 50; left: 50%; top: calc(var(--safe-t) + 54px); transform: translate(-50%, -20px); opacity: 0; pointer-events: none; background: #232333; border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600; max-width: calc(100% - 30px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .2s, transform .2s; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.bad { border-color: var(--bad); } .toast.warn { border-color: var(--warn); background: #2a1f0e; }
.debuglog { position: fixed; z-index: 60; left: 8px; right: 8px; bottom: 8px; height: 120px; overflow: auto; background: rgba(10, 10, 15, .92); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); pointer-events: none; opacity: .85; }
.debuglog .o { color: var(--good); } .debuglog .i { color: var(--accent-2); } .debuglog .w { color: var(--warn); }

/* ---------- motion ---------- */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation: none !important; transition-duration: 0s !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition-duration: 0s !important; } }

/* ---------- narrow screens / small cells ---------- */
.tabs:not(:has(button:not([hidden]))) { display: none; }
.ctl { gap: 4px; padding: 6px; }
.ctl .lbl { font-size: 11px; }
@media (max-width: 480px) {
  #topbar { gap: 6px; }
  .conn small { display: none; }
  .tools button { width: 30px; height: 30px; }
  .tabs button { padding: 4px 9px; }
}

/* PTY-owned sessions: new session dialog, inbox header, live terminal */
.inbox-hd { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-2); padding: 0 2px; flex: none; }
.inbox-hd .newbtn { background: var(--accent); color: #fff; border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.newsessbody { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.newsessbody .seg { display: flex; background: var(--bg-3); border-radius: 10px; padding: 3px; gap: 3px; }
.newsessbody .seg button { flex: 1; border-radius: 8px; padding: 8px; font-weight: 700; font-size: 13px; color: var(--ink-2); }
.newsessbody .seg button.on { background: var(--accent); color: #fff; }
.newsessbody .cwdrow { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.newsessbody .cwdrow input { height: 40px; font-family: var(--mono); font-size: 13px; background: #0a0a0f; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 10px; }
.newsessbody .cwdrow input:focus { border-color: var(--accent); outline: none; }
.newsessbody .recent { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.newsessbody .recent .chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 11px; }
.newsessbody .acts2 { display: flex; justify-content: flex-end; gap: 8px; }
.chat.term-on .msgs, .chat.term-on .quick, .chat.term-on .in { display: none; }
.term { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.term[hidden] { display: none; }
.termbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; font-size: 11px; }
.termout { flex: 1; margin: 0; padding: 8px 10px; overflow: auto; min-height: 0; font-family: var(--mono); font-size: 12px; line-height: 1.35; color: #d8d8e4; background: #050508; white-space: pre-wrap; word-break: break-all; }
.termin { display: flex; gap: 6px; padding: 8px; }
.termin input { flex: 1; min-width: 0; height: 38px; font-family: var(--mono); font-size: 13px; background: #121219; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; }
.termin button { border-radius: 10px; background: var(--accent); color: #fff; font-weight: 800; padding: 0 14px; }
/* Away-from-home hand-off link */
.handoff { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.handoff .link { font-family: var(--mono); font-size: 11px; word-break: break-all; background: #0a0a0f; border: 1px solid var(--line); border-radius: 8px; padding: 8px; user-select: all; -webkit-user-select: all; width: 100%; }
.handoff canvas { background: #fff; border-radius: 8px; padding: 0; image-rendering: pixelated; width: 220px; height: 220px; }
.handoff .warn { color: #fcd34d; font-size: 12px; }
/* Edit Deck cross-page: key that will go back to the dragged key's old page */
.deck .displaced { opacity: .35; filter: grayscale(.6); outline: 2px dashed var(--line); outline-offset: -4px; }

/* Touch: grow the hit area of small chrome controls to ~44px without changing how they look. */
@media (pointer: coarse) {
  .tabs button, .tools button, .ohd button { position: relative; }
  .tools button::after, .ohd button::after, .sheet-x::after { content: ""; position: absolute; inset: -8px; }
  .tabs button::after { content: ""; position: absolute; inset: -9px -2px; }
}
