/* wonderworld web simulator. Sizes are millimetres x --u (px per mm): the Captain's 1.54" LCD
   (27.7 mm) is exactly 240 device pixels at 1x, everything else is drawn at the same scale. */
:root {
  --u: 8.66px;
  --bg: #1b1d22;
  --panel: #23262d;
  --card: #2b2f37;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #ffb36b;
  --oled: #4aa8ff;      /* lit pixel colour of the transparent OLEDs (blue, per the brief; not measured) */
  --ok: #7fd18b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* One deliberate look (a lit desk + a dark control panel) in every theme: colours are set
   explicitly, color-scheme is dark for the panel's form controls. */
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, "PingFang SC", "Microsoft YaHei", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: #15171b; border-bottom: 1px solid #333; flex-wrap: wrap; gap: 8px; }
.brand { font-weight: 700; font-size: 17px; }
.brand span { font-weight: 400; color: var(--muted); font-size: 13px; }
.clockbox { font-variant-numeric: tabular-nums; }
.clockbox .lbl { color: var(--muted); margin-right: 8px; font-size: 12px; }
#clock { font-size: 16px; color: var(--accent); }

.layout { display: grid; grid-template-columns: 1fr 360px; min-height: calc(100% - 48px); }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------ the desk + what is behind the glass */
.desk { position: relative; overflow: auto; padding: 18px 16px 40px; background: none; min-height: 760px; }   /* no backdrop: the devices sit on the page */

.devices { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 40px; flex-wrap: wrap; padding-top: 40px; max-width: 100%; margin: 0 auto; transform-origin: top center; }
.dev-title { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 4px; white-space: nowrap; }
.dev-title small { color: var(--muted); }
.dev-meta { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); margin-top: 6px; gap: 6px; min-height: 22px; }
.mini { font-size: 11px; padding: 2px 8px; border-radius: 10px; border: 1px solid #4a505c; background: #2b2f37; color: var(--text); }
.desk-hint { position: relative; margin: 28px auto 0; max-width: 900px; text-align: center; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------ devices, drawn from the vendors' photos
   Every part is placed in millimetres (--x --y --w --h) times one shared scale --u (px per mm), so
   all three devices are to the same scale. Desktop 1x: --u = 8.66 px/mm, i.e. the Captain's
   27.7 mm LCD is exactly its 240 pixels. Sources and remaining uncertainties: README "Devices". */
.dev { position: relative; display: flex; flex-direction: column; align-items: center; user-select: none; -webkit-user-select: none; }
.p { position: absolute; left: calc(var(--x) * var(--u)); top: calc(var(--y) * var(--u)); width: calc(var(--w) * var(--u)); height: calc(var(--h) * var(--u)); box-sizing: border-box; }
.dev-title { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 6px; white-space: nowrap; }
.dev-title small { color: var(--muted); }
.dev-meta { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); margin-top: 6px; gap: 8px; min-height: 22px; }

/* Chain Captain: light-grey ABS frame, four round bosses with Phillips screws, a recessed screen
   window, red PWR + grey A/B/C keys, printed colour labels down both sides. */
.captain { position: relative; width: calc(56 * var(--u)); height: calc(40 * var(--u)); border-radius: calc(3.2 * var(--u));
  background: #d3d4d5; box-shadow: inset 0 0 0 calc(0.35 * var(--u)) #c2c3c5, inset 0 calc(-0.5 * var(--u)) 0 #bdbec0; touch-action: none; }
.captain.grab { cursor: grabbing; }
.captain.shaking { animation: shake .11s linear infinite; }
@keyframes shake { 0% { transform: translate(-6px, 2px) rotate(-2deg); } 50% { transform: translate(6px, -2px) rotate(2deg); } 100% { transform: translate(-6px, 2px) rotate(-2deg); } }
.boss { border-radius: 50%; background: radial-gradient(circle, #9fa2a6 0 30%, #b9bcc0 31% 52%, #c9cbce 53%); box-shadow: inset 0 0 0 calc(0.25 * var(--u)) #a9acb0; }
.boss::before, .boss::after { content: ""; position: absolute; left: 50%; top: 50%; width: 34%; height: 7%; background: #6f7276; transform: translate(-50%, -50%); }
.boss::after { transform: translate(-50%, -50%) rotate(90deg); }
.window { background: #1a1b1d; border-radius: calc(0.5 * var(--u)); box-shadow: 0 0 0 calc(0.35 * var(--u)) #bfc1c3; }
.window .lcd { position: absolute; left: 50%; top: calc(0.25 * var(--u)); transform: translateX(-50%); width: calc(27.7 * var(--u)); height: calc(27.7 * var(--u)); image-rendering: pixelated; background: #000; display: block; }
.window .shade { position: absolute; left: 50%; top: calc(0.25 * var(--u)); transform: translateX(-50%); width: calc(27.7 * var(--u)); height: calc(27.7 * var(--u)); background: #000; opacity: 0; pointer-events: none; }
.captain.off .shade { opacity: 1 !important; }
.keyguard { border-radius: calc(0.8 * var(--u)); background: #c6c7c9; }
.key { border: none; padding: 0; border-radius: calc(0.9 * var(--u)); background: #6c6e71; box-shadow: inset 0 calc(-0.35 * var(--u)) 0 #55575a, 0 calc(0.15 * var(--u)) 0 #a9abae; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; }
.key.pwr { background: #e8455a; box-shadow: inset 0 calc(-0.35 * var(--u)) 0 #c3354a, 0 calc(0.15 * var(--u)) 0 #a9abae; }
.key.down { transform: translateY(calc(0.2 * var(--u))); box-shadow: none; filter: brightness(.9); }
.lbl { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: calc(0.35 * var(--u)); font: 700 calc(1.05 * var(--u))/1 system-ui, sans-serif; color: #fff; text-align: center; overflow: hidden; }
.lbl b { font-size: calc(1.15 * var(--u)); }
.lbl em { font-style: normal; font-size: calc(2.6 * var(--u)); line-height: 1.1; flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
.lbl small { font-size: calc(0.95 * var(--u)); font-weight: 700; }
.lbl.red { background: #d62d3a; }
.lbl.black { background: #1c1c1e; }
.lbl.plain { background: transparent; color: #45474a; font-size: calc(0.95 * var(--u)); }
.lbl.vert { writing-mode: vertical-rl; transform: rotate(180deg); }
.lbl.yellow { background: #f2c21b; color: #1c1c1e; }
.lbl.yellow em { background: #f6d23e; }
.lbl.yellow b, .lbl.yellow small { background: #2b2b2b; color: #f2c21b; width: 100%; padding: calc(0.25 * var(--u)) 0; }
.lbl.green { background: #138a4e; }
.lbl.green em { background: #1aa35d; }
.lbl.green b, .lbl.green small { width: 100%; padding: calc(0.25 * var(--u)) 0; }
.lbl.blue { background: #0e7f97; }
.lbl.blue em { background: #20a6d8; }
.lbl.blue b, .lbl.blue small { width: 100%; padding: calc(0.25 * var(--u)) 0; }
.mic { background: #222; border-radius: calc(0.35 * var(--u)); }
.irwin { background: #19191b; border-radius: calc(0.5 * var(--u)); box-shadow: inset 0 0 0 calc(0.2 * var(--u)) #333; }
.led { border-radius: calc(0.3 * var(--u)); background: #2a2a2a; }
.captain.off .led { background: #2a2a2a !important; box-shadow: none !important; }
.captain.second { filter: hue-rotate(0deg); }

/* transparent OLED glass: only the firmware's lit pixels; unlit = transparent */
.glass canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Unit Glass2: glass panel with a smoked frame over a black PCB, white Grove sockets each side,
   two mounting tabs with gold rings at the bottom. */
.g2 { position: relative; width: calc(42 * var(--u)); height: calc(40 * var(--u)); }
.g2glass { border-radius: calc(0.6 * var(--u)); background: rgba(40, 42, 46, .35); box-shadow: inset 0 0 0 calc(1.6 * var(--u)) rgba(25, 26, 28, .85), inset 0 0 0 calc(1.7 * var(--u)) rgba(255, 255, 255, .12); }
.g2pcb { background: #141516; border-radius: calc(0.4 * var(--u)); overflow: hidden; }
.g2name { position: absolute; left: 0; right: 0; top: 4%; text-align: center; color: #fff; font: 800 calc(2.1 * var(--u))/1 system-ui, sans-serif; letter-spacing: .02em; }
.g2pins { position: absolute; top: 34%; display: flex; flex-direction: column; gap: calc(0.2 * var(--u)); font: 700 calc(1 * var(--u))/1.1 system-ui, sans-serif; }
.g2pins.l { left: 3%; } .g2pins.r { right: 3%; align-items: flex-end; }
.g2pins b { padding: 0 calc(0.35 * var(--u)); color: #111; }
.g2pins .k { background: #222; color: #fff; } .g2pins .r { background: #d62d3a; color: #fff; } .g2pins .y { background: #f2c21b; } .g2pins .w { background: #f2f2f2; }
.g2screw { position: absolute; top: 40%; width: calc(2.4 * var(--u)); height: calc(2.4 * var(--u)); border-radius: 50%; background: radial-gradient(circle, #555 0 28%, #c9ccd0 30%); }
.g2fpc { position: absolute; left: 30%; right: 30%; bottom: 0; height: 16%; background: #c9842a; }
.grove { background: #f4f4f2; border-radius: calc(0.4 * var(--u)); box-shadow: inset 0 0 0 calc(0.3 * var(--u)) #d9d9d6; }
.tab { border-radius: 50%; background: radial-gradient(circle, transparent 0 34%, #c9a227 35% 62%, #141516 63%); }
.glass-unit.unplugged .g2 { opacity: .45; }
.unplugged-note { display: none; font-size: 12px; color: var(--muted); margin-top: 4px; }
.glass-unit.unplugged .unplugged-note { display: block; }

/* LilyGO T-TV: clear 42 x 24 x 2 mm glass standing on a black cap, a black cylindrical body with
   the USB-C port and an embossed LILYGO logo. */
.tv { position: relative; width: calc(45 * var(--u)); height: calc(50 * var(--u)); }
.tvglass { border-radius: calc(0.4 * var(--u)); background: rgba(200, 215, 225, .07); box-shadow: inset 0 0 0 calc(0.45 * var(--u)) rgba(210, 225, 235, .35); }
.tvdriver { background: rgba(160, 165, 170, .45); border-radius: calc(0.2 * var(--u)); }
.tvcap { background: #1d1e20; border-radius: calc(1.2 * var(--u)) calc(1.2 * var(--u)) calc(0.6 * var(--u)) calc(0.6 * var(--u)); box-shadow: inset 0 calc(-0.4 * var(--u)) 0 #121314; }
.tvbody { border-radius: 0 0 calc(2.5 * var(--u)) calc(2.5 * var(--u)); background: linear-gradient(90deg, #121314 0%, #2a2b2e 22%, #303134 45%, #26272a 70%, #111214 100%); }
.tvlogo { position: absolute; left: 12%; top: 18%; writing-mode: vertical-rl; color: #3a3b3f; font: 800 calc(1.6 * var(--u))/1 system-ui, sans-serif; letter-spacing: .08em; }
.tvusb { position: absolute; left: 50%; top: 52%; width: calc(8.6 * var(--u)); height: calc(3 * var(--u)); transform: translateX(-50%); border-radius: calc(1.5 * var(--u)); background: #0b0b0c; box-shadow: inset 0 0 0 calc(0.45 * var(--u)) #7d8085; }
.tvir { background: transparent; }
.tvctl { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.touch { min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid #4a505c; background: #2b2f37; color: var(--text); font-size: 12px; touch-action: none; }
.touch.down { background: var(--accent); color: #222; }
.switch { width: 44px; height: 24px; border-radius: 12px; border: none; background: #555; position: relative; padding: 0; }
.switch i { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #ddd; transition: left .15s; }
.ttv:not(.off) .switch { background: #4caf6a; }
.ttv:not(.off) .switch i { left: 23px; }

/* phones: the mirrored key strip (the real keys stay where they are on the device) */
.keystrip { display: none; }

/* ------------------------------------------------------------ side panel */
.panel { background: var(--panel); border-left: 1px solid #333; padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: calc(100vh - 48px); position: sticky; top: 0; }
@media (max-width: 1100px) { .panel { max-height: none; position: static; } }
.card { background: var(--card); border-radius: 8px; padding: 10px 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; color: var(--accent); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h3 select { font-size: 12px; }
.card button { background: #3a3f49; border: 1px solid #4a505c; border-radius: 6px; padding: 5px 10px; }
.card button:hover { background: #454b57; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.seg button { padding: 3px 8px; font-size: 12px; }
.seg button.on { background: var(--accent); color: #222; border-color: var(--accent); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.tg, .sel { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.sel select, .sel input[type=range] { flex: 1; }
select { background: #1f2228; color: var(--text); border: 1px solid #4a505c; border-radius: 5px; padding: 2px 4px; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.status { font-size: 12px; }
.st-row { display: flex; justify-content: space-between; margin-top: 6px; }
.st-sub { color: var(--muted); font-variant-numeric: tabular-nums; word-break: break-all; }
.st-sub.hl { color: var(--accent); }
.st-conv { margin-top: 8px; color: var(--muted); }
.st-conv.ok { color: var(--ok); }
.role { padding: 0 8px; border-radius: 9px; background: #444; font-size: 11px; }
.r-HOST, .r-HOSTING { background: #2f6f45; }
.r-CONTROLLER, .r-HELD { background: #2f5a8f; }
.r-HANDOVER { background: #8f6a2f; }
.r-ALONE { background: #555d6b; }
.r-off { background: #333; color: #888; }
.bar { height: 6px; background: #1d2026; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.log { height: 220px; overflow-y: auto; background: #15171b; border-radius: 5px; padding: 6px; font: 11px/1.35 ui-monospace, Consolas, monospace; color: #b8c0cc; white-space: pre-wrap; word-break: break-all; }
.danger button { width: 100%; background: #5a2b2b; border-color: #7a3b3b; }
.danger button.armed { background: #a33c3c; border-color: #d05a5a; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .captain.shaking { animation: none; } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #000d; color: #fff; padding: 8px 16px; border-radius: 8px; opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #000a; font-size: 18px; z-index: 10; }

.zoombar { position: absolute; top: 8px; right: 12px; z-index: 2; display: flex; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.zoombar button { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid #4a505c; background: #2b2f37; color: var(--text); }
.zoombar button.on { background: var(--accent); color: #222; border-color: var(--accent); }

/* ------------------------------------------------------------ shared additions */
body { touch-action: manipulation; padding-bottom: env(safe-area-inset-bottom, 0px); }
.top { padding-top: max(10px, env(safe-area-inset-top, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.back { color: var(--accent); text-decoration: none; font-weight: 400; font-size: 14px; margin-right: 10px; white-space: nowrap; }
.captain, .ttv, .glass-unit, .thumbbar, .keystrip, .key, .touch, .switch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.glasses { display: flex; align-items: flex-end; gap: 40px; }
.firsthint { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); background: #3a2f22; color: #ffe1bd; font-size: 14px; }
.firsthint[hidden] { display: none; }
.firsthint a { color: var(--accent); }
.firsthint button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid #806a4f; background: transparent; color: inherit; }
.loading .ld { display: grid; gap: 12px; width: min(80vw, 340px); text-align: center; }
.ldbar { height: 8px; border-radius: 4px; background: #ffffff22; overflow: hidden; }
.ldbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.thumbbar, .sheet-head { display: none; }
/* body gestures under the Captain (desktop); on phones the same buttons live in the thumb bar */
.tiltro { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tiltro b { color: var(--text); font-weight: 600; }
.gest { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; width: 100%; max-width: 420px; }
.gest button { min-height: 34px; border-radius: 10px; border: 1px solid #4a505c; background: #2b2f37; color: var(--text); font-size: 13px; touch-action: none; -webkit-user-select: none; user-select: none; }
.gest button:active, .gest button.down, .thumbbar button.down { background: var(--accent); color: #222; }
.captain { transition: transform .05s linear; transform-origin: 50% 50%; }

/* ------------------------------------------------------------ phones (portrait first) */
@media (max-width: 819px) {
  .top { flex-wrap: nowrap; }
  .brand { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .brand span, .clockbox .lbl, .zoombar, .desk-hint { display: none; }
  #clock { font-size: 14px; white-space: nowrap; }
  .layout { display: block; }
  .desk { min-height: 0; padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(222px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); overflow: visible; }
          .devices { flex-direction: column; align-items: center; gap: 8px; width: 100%; padding-top: 0; zoom: 1 !important; }
  /* phones: the same mm scale for all three (set by ui.js so the Captain spans the width);
     the transparent screens in a swipe strip above the Captain */
  .glasses { order: -1; width: 100%; gap: 14px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 4px 2px 8px; align-items: flex-end; scrollbar-width: thin; }
  .glasses > * { flex: none; scroll-snap-align: center; }
  .glasses .ttv { order: -1; }
  #cap1-wrap .dev-meta .mini { display: none; }
  .dev-title { font-weight: 600; }
  .dev-meta { flex-wrap: wrap; margin-top: 2px; min-height: 0; }
  .dev-title { margin-bottom: 3px; }
  .tvctl { margin-top: 4px; }
  .cap2-slot { width: 100%; }
  .touch { min-height: 48px; }
  .switch { width: 52px; height: 28px; border-radius: 14px; }
  .switch i { width: 22px; height: 22px; }
  .ttv:not(.off) .switch i { left: 27px; }
  /* mirrored keys in the thumb zone: same functions as the keys drawn on the Captain */
  .gest { display: none; }
  .keystrip { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 8px; position: fixed; left: 0; right: 0; bottom: calc(134px + env(safe-area-inset-bottom, 0px)); z-index: 14;
    padding: 8px max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px)); background: #15171bf2; }
  .keystrip button { min-height: 56px; border-radius: 16px; border: 1px solid #4a505c; background: #3a3f49; color: var(--text); font-size: 22px; line-height: 1.1; display: grid; place-items: center; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .keystrip button span { font-size: 11px; color: var(--muted); }
  .keystrip button.down { background: var(--accent); color: #222; }
  body.nostrip .keystrip { display: none; }
  /* the thumb bar */
  .thumbbar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    padding: 8px max(10px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
    background: #15171bf2; border-top: 1px solid #333; }
  .thumbbar button { min-height: 48px; border-radius: 12px; border: 1px solid #3a3f49; background: #2b2f37; color: var(--text); font-size: 18px; line-height: 1.05; display: grid; place-items: center; padding: 2px 0; touch-action: none; }
  .thumbbar button span { font-size: 11px; color: var(--muted); }
  .thumbbar button:active { background: #3d434f; }
  /* the control panel as a bottom sheet */
  .panel { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 20; max-height: 78vh; max-height: 78dvh; border-left: none; border-radius: 18px 18px 0 0;
    transform: translateY(105%); transition: transform .22s ease; box-shadow: 0 -12px 30px #0008;
    padding: 0 max(12px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }
  .panel.open { transform: none; }
  .sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 10px 2px; font-weight: 600; }
  .sheet-head::before { content: ""; position: absolute; left: 50%; top: 4px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: #555; }
  .sheet-head button { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid #4a505c; background: #3a3f49; }
  .card button, .seg button { min-height: 44px; }
  .tg { min-height: 40px; }
  .tg input { width: 22px; height: 22px; }
  .toast { bottom: calc(212px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) { .panel { transition: none; } }

.devices > *, .glasses > * { flex-shrink: 0; }
