/* ============================================================
   Switch Controller Tester — "precision diagnostic console"
   Bricolage Grotesque (display) + IBM Plex Mono (instrument data)
   ============================================================ */

:root {
  --bg0: #07080a; --bg1: #0d0f14; --bg2: #12151c; --bg3: #181c25;
  --line: rgba(255,255,255,.07); --line2: rgba(255,255,255,.13);
  --fg: #e8ebf3; --muted: #8b92a6; --faint: #5a6173;
  --accent: #46d6ff; --accent-deep: #1aa6d6; --accent-ink: #042430;
  --accent-glow: rgba(70,214,255,.30);
  --hot: #ff5d7a;
  --good: #74e08c; --warn: #f2c14e; --bad: #ff5d7a;
  --radius: 16px; --radius-sm: 10px;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --display: "Bricolage Grotesque", var(--mono);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg0); color: var(--fg);
  font-family: var(--mono); font-size: 14px; line-height: 1.55;
  letter-spacing: .005em; overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- background atmosphere ---------- */
.bg-glow, .bg-grid, .bg-grain { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.bg-glow {
  background:
    radial-gradient(58% 46% at 50% -6%, rgba(70,214,255,.16), transparent 62%),
    radial-gradient(46% 44% at 92% 108%, rgba(255,93,122,.11), transparent 60%),
    radial-gradient(40% 40% at 6% 40%, rgba(70,214,255,.06), transparent 60%);
}
.bg-grid {
  background-image: radial-gradient(circle, rgba(255,255,255,.045) 1px, transparent 1.4px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(120% 90% at 50% 0%, #000 35%, transparent 85%);
          mask-image: radial-gradient(120% 90% at 50% 0%, #000 35%, transparent 85%);
}
.bg-grain {
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.wrap { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: 40px 24px 64px; }

/* ---------- reveal ---------- */
.reveal { opacity: 0; transform: translateY(16px); animation: rise .75s cubic-bezier(.2,.7,.15,1) forwards; animation-delay: calc(var(--d, 0) * .09s); }
@keyframes rise { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .reveal { animation: none; opacity: 1; transform: none; } }

/* ---------- hero ---------- */
.hero { margin-bottom: 26px; }
.hero-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 16px; }
.mark {
  width: 46px; height: 46px; flex: none; border-radius: 13px;
  background: linear-gradient(150deg, #11151d, #0a0c11); border: 1px solid var(--line2);
  display: grid; place-items: center; box-shadow: 0 0 0 1px rgba(70,214,255,.08), 0 10px 30px rgba(0,0,0,.5);
}
.mark-dot { width: 13px; height: 13px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 14px 2px var(--accent-glow); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.kicker { margin: 0 0 2px; font-size: 11px; letter-spacing: .28em; text-transform: uppercase; color: var(--accent); }
h1 {
  margin: 0; font-family: var(--display); font-weight: 800; line-height: .95;
  font-size: clamp(30px, 5.2vw, 52px); letter-spacing: -.02em;
  background: linear-gradient(180deg, #fff, #aeb6c8); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.sub { max-width: 640px; margin: 18px 0 0; color: var(--muted); font-size: 13.5px; }

.led {
  display: inline-flex; align-items: center; gap: 9px; padding: 8px 14px; border-radius: 999px;
  background: var(--bg1); border: 1px solid var(--line); color: var(--muted);
  font-size: 12px; letter-spacing: .04em; white-space: nowrap;
}
.led .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px rgba(255,255,255,.04); flex: none; }
.led.on { color: var(--good); border-color: rgba(116,224,140,.3); }
.led.on .dot { background: var(--good); box-shadow: 0 0 10px 1px rgba(116,224,140,.6); }

.hero-aside { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.aside-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.gh-star {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  font-family: var(--mono); font-size: 13px; color: var(--fg);
  background: var(--bg2); border: 1px solid var(--line2); border-radius: 999px;
  padding: 8px 14px; transition: transform .12s ease, border-color .15s, box-shadow .15s, background .15s;
}
.gh-star:hover { transform: translateY(-1px); border-color: rgba(242,193,78,.5); box-shadow: 0 8px 24px -10px rgba(242,193,78,.55); background: var(--bg3); }
.gh-logo { flex: none; opacity: .95; }
.star-count { color: var(--muted); }
.star-count:not(:empty)::before { content: "·"; margin-right: 6px; color: var(--faint); }
.lang { display: inline-flex; border: 1px solid var(--line2); border-radius: 999px; overflow: hidden; background: var(--bg1); }
.lang button { font-family: var(--mono); font-size: 12px; letter-spacing: .06em; color: var(--muted); background: transparent; border: 0; padding: 7px 12px; cursor: pointer; transition: background .15s, color .15s; }
.lang button:hover { color: var(--fg); }
.lang button.active { background: rgba(70,214,255,.16); color: #d6f6ff; }

.support:not(:empty) {
  background: linear-gradient(180deg, rgba(255,93,122,.12), rgba(255,93,122,.05));
  border: 1px solid rgba(255,93,122,.4); color: #ffd9e0;
  padding: 15px 18px; border-radius: var(--radius-sm); margin-top: 18px; max-width: 720px;
}
.support .sup-title { display: block; font-size: 14.5px; color: #fff; margin-bottom: 7px; }
.support p { margin: 5px 0; font-size: 13px; }
.support .sup-ok { color: #b6f0c4; }
.support .sup-no { color: #ffc9d2; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 16px; margin: 0 0 26px; flex-wrap: wrap; }
.devinfo { color: var(--muted); font-size: 13px; }
.devinfo .ok { color: var(--good); }
.devinfo .dim { color: var(--faint); }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--fg);
  background: var(--bg2); border: 1px solid var(--line2); border-radius: var(--radius-sm);
  padding: 10px 15px; cursor: pointer; transition: transform .12s ease, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--bg3); border-color: rgba(70,214,255,.35); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); }
.btn.active { background: rgba(70,214,255,.14); border-color: var(--accent); color: #d6f6ff; box-shadow: inset 0 0 18px rgba(70,214,255,.12); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.btn-primary {
  font-weight: 600; color: var(--accent-ink);
  background: linear-gradient(180deg, #6fe0ff, var(--accent-deep)); border: none;
  padding: 12px 20px; box-shadow: 0 0 0 1px rgba(70,214,255,.4), 0 8px 26px rgba(70,214,255,.28);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 0 0 1px rgba(70,214,255,.6), 0 12px 34px rgba(70,214,255,.4); }
.btn-ico { font-size: 14px; }

.seg { display: inline-flex; gap: 6px; }

.sel { color: var(--faint); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; display: inline-flex; align-items: center; gap: 8px; }
.sel select {
  font-family: var(--mono); font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--fg);
  background: var(--bg2); border: 1px solid var(--line2); border-radius: var(--radius-sm); padding: 9px 10px;
}

/* ---------- panels ---------- */
main { display: flex; flex-direction: column; gap: 22px; }
.panel {
  position: relative; background: linear-gradient(180deg, rgba(255,255,255,.025), transparent 40%), var(--bg1);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 24px 60px -30px rgba(0,0,0,.8);
}
/* view gating: instrument panels show only once a controller is connected;
   incompatible/insecure browsers see just the warning. */
body:not(.connected) main > section.panel { display: none; }
.idle-hint { display: none; }
body:not(.unsupported):not(.connected) .idle-hint { display: block; }
body.unsupported main,
body.unsupported .toolbar { display: none; }

.idle-card { background: var(--bg1); border: 1px dashed var(--line2); border-radius: var(--radius); padding: 44px 28px; text-align: center; max-width: 560px; margin: 4px auto; }
.idle-ico { font-size: 34px; display: block; margin-bottom: 12px; opacity: .9; }
.idle-card h2 { font-family: var(--display); font-weight: 700; font-size: 22px; margin: 0 0 10px; color: var(--fg); }
.idle-card p { color: var(--muted); margin: 0 auto; font-size: 14px; max-width: 420px; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.panel h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: -.01em; display: flex; align-items: center; gap: 12px; }
.tag { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--accent); border: 1px solid rgba(70,214,255,.3); border-radius: 6px; padding: 2px 7px; letter-spacing: .1em; }
.subhead { margin: 22px 0 12px; font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); }
.legend { color: var(--muted); font-size: 12px; }
.badge { font-family: var(--mono); font-size: 12px; color: var(--good); border: 1px solid rgba(116,224,140,.3); border-radius: 999px; padding: 3px 11px; }
.dim { color: var(--faint); }

/* ---------- controls ---------- */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 22px; }
.controls .spacer { flex: 1; min-width: 8px; }

/* ---------- sticks / scopes ---------- */
.sticks { display: flex; gap: 30px; flex-wrap: wrap; }
.stick { flex: 1; min-width: 270px; }
.scope-label { font-family: var(--mono); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.scope {
  position: relative; width: 100%; max-width: 340px; aspect-ratio: 1 / 1;
  border-radius: 18px; padding: 12px;
  background: radial-gradient(circle at 50% 42%, #161a23, #0c0e13 78%);
  border: 1px solid var(--line2);
  box-shadow: inset 0 0 40px rgba(0,0,0,.6), 0 0 0 1px rgba(70,214,255,.05), 0 18px 50px -24px rgba(0,0,0,.9);
}
.scope::before, .scope::after { content: ""; position: absolute; width: 14px; height: 14px; border: 1px solid rgba(70,214,255,.35); }
.scope::before { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.scope::after { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }
.pad { width: 100%; height: 100%; display: block; border-radius: 10px; }
.stat { font-family: var(--mono); background: transparent; margin: 12px 0 0; font-size: 13px; color: var(--fg); }
.hint { color: var(--faint); margin-top: 18px; font-size: 12.5px; }

/* ---------- result tables ---------- */
.result:not(:empty) { margin-top: 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
table { border-collapse: collapse; width: 100%; font-family: var(--mono); font-size: 13px; }
thead th { background: var(--bg2); color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
.result p { margin: 0; padding: 11px 14px; background: var(--bg2); }

/* ---------- buttons panel ---------- */
.btn-named { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--mono); font-size: 13px; padding: 8px 14px; border-radius: 999px;
  background: var(--bg2); border: 1px solid var(--line2); color: var(--muted);
  transition: all .12s ease;
}
.chip.on { background: linear-gradient(180deg, #6fe0ff, var(--accent-deep)); color: var(--accent-ink); border-color: transparent; box-shadow: 0 0 18px var(--accent-glow); transform: translateY(-1px); }

.dpad { display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); gap: 5px; margin: 18px 0; }
.dbtn { display: flex; align-items: center; justify-content: center; background: var(--bg2); border: 1px solid var(--line2); color: var(--muted); font-size: 13px; transition: all .1s ease; }
.dpad-up { grid-column: 2; grid-row: 1; border-radius: 9px 9px 4px 4px; }
.dpad-left { grid-column: 1; grid-row: 2; border-radius: 9px 4px 4px 9px; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 4px 9px 9px 4px; }
.dpad-down { grid-column: 2; grid-row: 3; border-radius: 4px 4px 9px 9px; }
.dbtn.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 0 16px var(--accent-glow); }

.ident { color: var(--warn); margin: 4px 0 6px; min-height: 20px; font-size: 13px; }

.btn-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; max-width: 640px; }
.cell { background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 4px; text-align: center; transition: all .1s ease; }
.cell b { display: block; font-size: 13px; font-weight: 600; }
.cell span { color: var(--faint); font-size: 10px; }
.cell.on { background: linear-gradient(180deg, #6fe0ff, var(--accent-deep)); color: var(--accent-ink); border-color: transparent; box-shadow: 0 0 16px var(--accent-glow); transform: translateY(-1px); }
.cell.on span { color: rgba(4,36,48,.75); }

/* ---------- raw ---------- */
.raw { font-family: var(--mono); background: var(--bg2); padding: 14px; border-radius: var(--radius-sm); white-space: pre-wrap; word-break: break-all; font-size: 12.5px; color: var(--muted); border: 1px solid var(--line); }

/* ---------- footer ---------- */
footer { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--faint); font-size: 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.foot-links { display: flex; gap: 18px; flex-wrap: wrap; }
.foot-link { color: var(--muted); text-decoration: none; }
.foot-link:hover { color: var(--accent); }

@media (max-width: 560px) {
  .wrap { padding: 28px 16px 48px; }
  .btn-grid { grid-template-columns: repeat(4, 1fr); }
}
