/* Theme variables: dark by default, light via system preference or data-theme */
:root {
  --bg: #0f1218;
  --surface: #181d27;
  --surface-2: #212838;
  --text: #e7ebf3;
  --muted: #9aa5b8;
  --accent: #5aa2ff;
  --accent-text: #08111f;
  --border: #2d3548;
  --ok: #4cd08a;
  --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f5f7fb; --surface: #ffffff; --surface-2: #eef1f7; --text: #1a2030;
    --muted: #596277; --accent: #1f6feb; --accent-text: #ffffff; --border: #d6dbe6;
    --ok: #12804a; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f7fb; --surface: #ffffff; --surface-2: #eef1f7; --text: #1a2030;
  --muted: #596277; --accent: #1f6feb; --accent-text: #ffffff; --border: #d6dbe6;
  --ok: #12804a; color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--accent);
  color: var(--accent-text); padding: .5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 0; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 1rem; }
main { flex: 1; padding: 2rem 0 3rem; }

/* Header & nav */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-inner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .6rem 1rem; }
.logo { font-weight: 800; font-size: 1.25rem; color: var(--text); text-decoration: none; margin-right: auto; }
.logo span { color: var(--accent); }
.nav-list { display: flex; flex-wrap: wrap; gap: .25rem; list-style: none; margin: 0; padding: 0; }
.nav-list a { display: block; padding: .35rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav-list a:hover { background: var(--surface-2); }
.nav-list a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.nav-toggle { display: none; }

/* Buttons */
.btn {
  font: inherit; cursor: pointer; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.icon-btn { padding: .4rem .6rem; line-height: 1; }

@media (max-width: 720px) {
  .nav-toggle { display: inline-block; }
  .nav { display: none; width: 100%; order: 3; }
  .nav.open { display: block; }
  .nav-list { flex-direction: column; }
}

/* Hero */
.hero { text-align: center; padding: 2.5rem 0 2rem; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.15; margin: 0 0 .75rem; }
.hero p { color: var(--muted); max-width: 40rem; margin: 0 auto 1.5rem; font-size: 1.1rem; }

/* Card grid */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  display: block; padding: 1.25rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); text-decoration: none;
  transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-icon { width: 40px; height: 40px; color: var(--accent); margin-bottom: .5rem; }
.card h2 { margin: 0 0 .25rem; font-size: 1.15rem; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }

.note {
  margin-top: 2rem; padding: 1rem 1.25rem; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: var(--radius);
}

/* Tool pages */
.tool-head h1 { margin: 0 0 .25rem; }
.tool-head p { color: var(--muted); margin: 0 0 1.25rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.support { margin-top: 1.5rem; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); }
.support h2 { margin: 0 0 .5rem; font-size: 1.05rem; }
.support ul { margin: 0; padding-left: 1.2rem; color: var(--muted); font-size: .95rem; }
.support-ok { color: var(--ok); }
.support-no { color: #e5484d; }

/* Gamepad tester */
.gp-wait { text-align: center; font-size: 1.2rem; padding: 2rem 1rem; margin: 0; }
.gp-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.gp-tabs .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.gp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.gp-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.gp-box h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.gp-box h2 small { color: var(--muted); font-weight: 400; }
.gp-layout-control { display: flex; align-items: center; gap: .45rem; margin-bottom: .5rem; }
.gp-layout-control select { max-width: 100%; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); font: inherit; }
.gp-svg { width: 100%; max-width: 460px; display: block; margin: 0 auto; }
.gp-svg[hidden] { display: none; }
.gp-body { fill: var(--surface); stroke: var(--border); stroke-width: 2; }
.gp-well { fill: var(--bg); stroke: var(--border); }
.gp-part { fill: var(--surface); stroke: var(--muted); stroke-width: 1.5; }
.gp-part.on { fill: var(--ok); stroke: var(--ok); }
.gp-touchpad { fill: var(--bg); stroke: var(--border); stroke-width: 1.5; }
.gp-symbol { fill: var(--muted); stroke: none; font: 12px sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.gp-note { color: var(--muted); font-size: .9rem; margin: .5rem 0 0; }
.gp-dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 0; }
.gp-dl dt { color: var(--muted); }
.gp-dl dd { margin: 0; overflow-wrap: anywhere; }
.gp-btns { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .4rem; }
.gp-b { border: 1px solid var(--border); border-radius: 8px; padding: .25rem .5rem; font-size: .85rem; background: var(--surface); }
.gp-b.tested { border-color: var(--ok); }
.gp-b.on { background: var(--ok); color: var(--accent-text); }
.gp-b span { display: block; opacity: .8; }
.gp-bar { display: grid; grid-template-columns: 90px 1fr 56px; align-items: center; gap: .5rem; margin-bottom: .35rem; font-size: .85rem; }
.gp-track { position: relative; height: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.gp-fill { position: absolute; top: 0; bottom: 0; background: var(--accent); }
.gp-sticks { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.gp-sticks figure { margin: 0; text-align: center; }
.gp-sticks canvas { max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 50%; }
.gp-report { margin: .5rem 0 0; padding-left: 1.2rem; }
.gp-row { display: flex; justify-content: space-between; margin-top: .5rem; }
.gp-box input[type="range"] { width: 100%; accent-color: var(--accent); }
.status { color: var(--muted); min-height: 1.5em; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); padding: 1.25rem 0; font-size: .9rem; text-align: center; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Keyboard tester */
kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .35em; font-size: .85em; }
.kb-controls { margin-bottom: 1rem; justify-content: space-between; }
.kb-wrap { overflow-x: auto; padding: .75rem; }
.kb { --u: 44px; display: grid; margin: 0 auto; user-select: none; }
.key {
  margin: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
  color: var(--text); display: flex; align-items: center; justify-content: center;
  font-size: .7rem; text-align: center; line-height: 1.1; overflow: hidden;
}
.key.tested { background: color-mix(in srgb, var(--ok) 40%, var(--surface-2)); border-color: var(--ok); }
.key.down { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.key.stuck { background: #e5484d; color: #fff; border-color: #e5484d; }
@media (max-width: 720px) { .kb { --u: 34px; } .key { font-size: .6rem; } }
.kb-stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.kb-stats .panel, .panel h2 { margin-top: 0; }
.panel h2 { font-size: 1.05rem; margin-bottom: .5rem; }
progress { width: 100%; height: 14px; accent-color: var(--ok); }
.info { display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.history { margin: 0; padding-left: 0; list-style: none; columns: 2 260px; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.history time { color: var(--muted); margin-right: .5rem; }
.sample { font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; background: var(--surface-2); padding: .75rem; border-radius: 8px; margin-top: 0; }
.sample .ok { color: var(--ok); }
.sample .bad { background: #e5484d; color: #fff; }
.sample .cur { outline: 2px solid var(--accent); }
textarea { width: 100%; font: inherit; padding: .5rem; margin: .25rem 0 .75rem; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; resize: vertical; }

/* Mouse tester */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mouse-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 1rem; }
.mouse-area .panel { margin-bottom: 0; }
.mouse-area > .panel { margin-top: 1rem; }
.mouse-area h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.live-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.live-row .info { flex: 1; min-width: 200px; }
.pad {
  display: grid; place-items: center; text-align: center; min-height: 110px; padding: .75rem;
  border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted);
  user-select: none; background: var(--bg); font: inherit; width: 100%;
}
#main-pad { width: 190px; min-height: 0; padding: .25rem; border-style: solid; width: auto; }
.pad-btn { cursor: pointer; min-height: 130px; margin: .5rem 0; color: var(--text); }
.pad-btn:hover { border-color: var(--accent); }
.mouse-svg { width: 170px; height: auto; display: block; }
.mouse-body { fill: var(--surface-2); stroke: var(--border); stroke-width: 3; }
.mbtn { fill: var(--surface); stroke: var(--border); stroke-width: 2; transition: fill .05s; }
.mbtn.tested { fill: color-mix(in srgb, var(--ok) 40%, var(--surface)); stroke: var(--ok); }
.mbtn.down { fill: var(--accent); stroke: var(--accent); }
.arrow { fill: var(--border); }
.arrow.on { fill: var(--accent); }
.mlabel { fill: var(--muted); font-size: 11px; pointer-events: none; }
.table-wrap { overflow-x: auto; }
.mtable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.mtable th, .mtable td { padding: .25rem .5rem; text-align: left; border-bottom: 1px solid var(--border); }
.history .warn { color: #e5484d; }
.dir { font-size: 1.5rem; font-weight: 700; margin: .5rem 0; min-height: 2rem; }
#trail { width: 100%; height: 260px; display: block; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; cursor: crosshair; touch-action: none; }
.drag-zone { position: relative; height: 120px; margin-top: 1rem; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--bg); overflow: hidden; touch-action: none; }
.puck { position: absolute; width: 70px; height: 70px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 700; cursor: grab; user-select: none; }
.puck.dragging { cursor: grabbing; background: var(--ok); }

/* Webcam tester */
.cam-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr); align-items: start; margin-bottom: 1rem; }
.cam-layout .panel, .cam-side .panel { margin-bottom: 1rem; }
.cam-layout h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
@media (max-width: 860px) { .cam-layout { grid-template-columns: 1fr; } }
.cam-controls { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.field { display: flex; flex-direction: column; gap: .2rem; flex: 1; min-width: 180px; }
select { font: inherit; padding: .45rem; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; max-width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); }
a.btn { display: inline-block; text-decoration: none; }
.video-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; margin: .75rem 0; display: grid; place-items: center; }
.video-wrap video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-wrap video.mirrored { transform: scaleX(-1); }
.video-placeholder { position: absolute; color: #9aa5b8; }
.video-placeholder[hidden] { display: none; }
.fps-badge, .rec-badge { position: absolute; top: .5rem; padding: .15rem .5rem; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; font: .8rem ui-monospace, Consolas, monospace; }
.fps-badge { left: .5rem; }
.rec-badge { right: .5rem; color: #ff5a5f; animation: blink 1s steps(2) infinite; }
.fps-badge[hidden], .rec-badge[hidden] { display: none; }
@keyframes blink { 50% { opacity: .3; } }
.video-wrap:fullscreen { aspect-ratio: auto; border-radius: 0; }
.filters { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; display: grid; gap: .5rem; }
.filters legend { padding: 0 .4rem; color: var(--muted); }
.filters label { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.filters input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--accent); }
.filters output { min-width: 3.5ch; font-family: ui-monospace, Consolas, monospace; }
.caps { margin: 0; padding-left: 1.1rem; font-size: .9rem; overflow-wrap: anywhere; }
.caps .status { margin-left: -1.1rem; list-style: none; }
#clip { width: 100%; max-height: 360px; background: #000; border-radius: 8px; margin-bottom: .75rem; }
.gallery { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.shot { margin: 0; }
.shot img { width: 100%; border-radius: 8px; border: 1px solid var(--border); display: block; }
.shot figcaption { margin-top: .4rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.shot .btn { padding: .25rem .6rem; font-size: .85rem; color: var(--text); }
[hidden] { display: none !important; }

/* Audio tester */
.sub { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: 1rem 0; }
.sub h3 { margin: 0 0 .5rem; font-size: .95rem; color: var(--muted); }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.warn-box { padding: .75rem 1rem; border: 1px solid #e5a50a; border-left: 4px solid #e5a50a; border-radius: var(--radius); background: color-mix(in srgb, #e5a50a 12%, var(--surface)); }
.mic-actions { margin: .75rem 0 0; }
.meter { position: relative; height: 22px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.meter-bar { height: 100%; width: 0; background: var(--ok); transition: width .05s linear; }
.meter-bar.hot { background: #e5484d; }
.meter-peak { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--text); margin-left: -2px; }
.viz { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.viz figure { margin: 0; }
.viz figcaption { color: var(--muted); font-size: .85rem; margin-bottom: .25rem; }
.viz canvas { width: 100%; height: 140px; display: block; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }

/* Screen tester */
body.no-scroll { overflow: hidden; }
.test-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.test-card { font: inherit; text-align: left; cursor: pointer; }
.test-card h3 { margin: 0 0 .25rem; font-size: 1.05rem; }
.hz { font-size: 1.8rem; font-weight: 700; margin: 0 0 .25rem; }
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); max-width: 34rem; padding: 1.25rem; }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog h2 { margin-top: 0; }
.overlay { position: fixed; inset: 0; z-index: 1000; background: #000; color: #fff; outline: none; }
.overlay.idle { cursor: none; }
.stage { position: absolute; inset: 0; overflow: hidden; }
.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-fps { position: absolute; right: 1rem; top: 1rem; padding: .25rem .6rem; background: rgba(0,0,0,.75); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 6px; font: .9rem ui-monospace, Consolas, monospace; }
.ov-ui { position: absolute; left: 50%; transform: translateX(-50%); max-width: calc(100% - 1rem); background: rgba(0,0,0,.78); color: #fff; border: 1px solid rgba(255,255,255,.45); border-radius: 10px; padding: .5rem .75rem; transition: opacity .25s; z-index: 2; }
.ov-top { top: .75rem; display: flex; flex-direction: column; gap: .15rem; text-align: center; font-size: .9rem; }
.ov-top span { color: #ccc; }
.ov-bar { bottom: .75rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; justify-content: center; }
.ov-ui .btn { background: #222; color: #fff; border-color: #777; }
.ov-extra { display: flex; align-items: center; gap: .4rem; font-size: .9rem; }
.ov-extra input[type="range"] { width: 120px; }
.overlay.idle .ov-ui:not(:focus-within) { opacity: 0; pointer-events: none; }
.bars { display: flex; height: 100%; }
.bar { flex: 1; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12vh; font: .8rem ui-monospace, Consolas, monospace; }
.bands { display: flex; flex-direction: column; height: 100%; }
.bands > div { flex: 1; }
.text-sample { padding: 4rem 2rem 2rem; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.5; overflow: hidden; height: 100%; }
