/* =================================================================
   Keyboard, Mouse & Gamepad Tester — v2.0
   Modern, dependency-free, responsive dark UI.
   ================================================================= */

:root {
  /* Palette */
  --bg: #0b0f17;
  --bg-2: #0e1320;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.18);
  --fg: #e7ecf3;
  --fg-dim: #8a96a8;
  --fg-faint: #5b6677;

  /* Accent */
  --c1: #22d3ee;
  --c2: #6366f1;
  --c3: #d946ef;
  --accent: linear-gradient(135deg, var(--c1), var(--c2) 55%, var(--c3));
  --accent-soft: linear-gradient(135deg, rgba(34, 211, 238, .16), rgba(217, 70, 239, .16));
  --glow: 0 0 0 1px rgba(34, 211, 238, .6), 0 0 18px rgba(34, 211, 238, .55), 0 0 40px rgba(99, 102, 241, .35);

  /* Keyboard metrics — fixed "design" size; the board is scaled to fit
     its container in JS (Keyboard.fit), so it never needs a scrollbar. */
  --u: 46px;
  --gap: 6px;
  --fn-h: calc(var(--u) * 0.72);

  --radius: 14px;
  --radius-key: 9px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--fg);
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(99, 102, 241, .18), transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, rgba(217, 70, 239, .12), transparent 55%),
    radial-gradient(900px 500px at 50% 120%, rgba(34, 211, 238, .10), transparent 60%),
    var(--bg);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Splash ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  transition: opacity .45s ease, visibility .45s;
}
#splash.hidden { opacity: 0; visibility: hidden; }
#splash p { color: var(--fg-dim); letter-spacing: .04em; font-size: 14px; }
.splash-mark {
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--accent);
  box-shadow: var(--glow);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(.85); opacity: .65; } 50% { transform: scale(1); opacity: 1; } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  background: rgba(11, 15, 23, .72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand-logo { display: block; filter: drop-shadow(0 2px 8px rgba(34, 211, 238, .4)); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .01em; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--fg-faint); }
.brand-ver {
  font: 600 11px/1 var(--mono);
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--line-strong);
  color: var(--c1);
}

.tabs { display: flex; gap: 6px; margin: 0 auto; }
.tab {
  appearance: none;
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 14px/1 var(--sans);
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 9px 15px;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
}
.tab:hover { color: var(--fg); background: var(--surface); }
.tab.is-active {
  color: #061018;
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 6px 20px -8px rgba(34, 211, 238, .8);
}
.tab-ico { font-size: 16px; }

.toolbar { display: flex; align-items: center; gap: 8px; }
.icon-btn, .text-btn {
  appearance: none;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  transition: all .15s;
}
.icon-btn { width: 38px; height: 38px; font-size: 16px; display: grid; place-items: center; }
.icon-btn:not(.is-on) { opacity: .4; }
.icon-btn:not(.is-on) .ib-ico { filter: grayscale(1); }
.icon-btn:hover, .text-btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.text-btn { font: 600 13px/1 var(--sans); padding: 0 14px; height: 38px; }
.text-btn.accent {
  background: var(--accent-soft);
  border-color: var(--line-strong);
  color: var(--fg);
}

/* ---------- Main ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  min-width: 0; /* don't let wide content (the keyboard) stretch the page */
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); }
.stat-value { font: 700 22px/1.1 var(--mono); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-coverage { grid-column: span 2; }
.coverage-bar { margin-top: 8px; height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.coverage-fill { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .35s ease; }
@media (max-width: 560px) { .stat-coverage { grid-column: span 2; } }

/* ---------- Panels ---------- */
.panel { display: none; min-width: 0; animation: fade .25s ease; }
.panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Readout ---------- */
.readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 110px;
  margin-bottom: 22px;
  padding: 18px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
}
.readout-key {
  font: 800 clamp(28px, 6vw, 52px)/1 var(--mono);
  background: var(--accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
  word-break: break-word;
}
.readout-code { font: 500 13px/1.2 var(--mono); color: var(--fg-faint); text-align: center; }
.readout.flash { animation: flash .3s ease; }
@keyframes flash { 0% { box-shadow: var(--glow); } 100% { box-shadow: none; } }

/* ---------- Keyboard ---------- */
/* The board is rendered at a fixed natural size, then scaled down with a
   transform (set by Keyboard.fit) to always fit the viewport — no scrollbar. */
.kb-scroll {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
  min-width: 0;
}
.keyboard {
  display: flex;
  gap: calc(var(--gap) * 3);
  align-items: flex-start;
  width: max-content;
  margin: 0 auto;
  transform-origin: top center;
  padding: clamp(12px, 1.6vw, 20px);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(0, 0, 0, .25));
  border: 1px solid var(--line);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .9);
}
.kb-main { display: flex; flex-direction: column; gap: var(--gap); }
.kb-row { display: flex; gap: var(--gap); }
.kb-extras { display: flex; gap: calc(var(--gap) * 2); }
.kb-nav { display: flex; flex-direction: column; gap: var(--gap); }
.kb-nav-rows { display: flex; flex-direction: column; gap: var(--gap); }
.kb-nav-row { display: flex; gap: var(--gap); }
.kb-arrows {
  margin-top: var(--gap);
  display: grid;
  grid-template-columns: repeat(3, var(--u));
  grid-template-rows: repeat(2, var(--u));
  gap: var(--gap);
}
.kb-arrows .arrow-up { grid-column: 2; grid-row: 1; }
.kb-arrows .arrow-left { grid-column: 1; grid-row: 2; }
.kb-arrows .arrow-down { grid-column: 2; grid-row: 2; }
.kb-arrows .arrow-right { grid-column: 3; grid-row: 2; }
.kb-numpad {
  display: grid;
  grid-template-columns: repeat(4, var(--u));
  grid-auto-rows: var(--u);
  gap: var(--gap);
  /* drop numpad down so NumLock aligns with the number row */
  margin-top: calc(var(--fn-h) + var(--gap));
}
/* Let the grid size these (so the tall +/Enter spans and the wide 0 fill
   their cells) instead of the fixed width/height on the base .key rule. */
.kb-numpad .key { width: auto; height: auto; }

/* Keycap */
.key {
  position: relative;
  height: var(--u);
  width: calc(var(--u) * var(--w, 1) + var(--gap) * (var(--w, 1) - 1));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: var(--radius-key);
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .015));
  border: 1px solid var(--line-strong);
  border-bottom: 3px solid rgba(0, 0, 0, .45);
  color: var(--fg);
  font: 600 14px/1 var(--sans);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .04s ease, box-shadow .12s ease, background .12s ease, color .12s ease, border-color .12s ease;
}
.key.fn { height: var(--fn-h); font-size: 11px; }
.key.mod { font-size: 11px; color: var(--fg-dim); }
.key .k-sub { font-size: .72em; opacity: .55; line-height: 1; }
.key .k-label { line-height: 1; }
.key-spacer { background: transparent !important; border: 0 !important; pointer-events: none; }

.key:hover { border-color: var(--c1); }
.key.is-tested {
  border-color: rgba(34, 211, 238, .55);
  background: linear-gradient(180deg, rgba(34, 211, 238, .14), rgba(99, 102, 241, .07));
  color: var(--fg);
}
.key.is-press {
  transform: translateY(2px);
  border-bottom-width: 1px;
  background: var(--accent);
  color: #04121a;
  border-color: transparent;
  box-shadow: var(--glow);
}
.key.is-press .k-sub { opacity: .8; }

/* ---------- Mouse ---------- */
.mouse-wrap {
  display: flex;
  gap: 32px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 20px 0;
}
.mouse {
  position: relative;
  width: 190px;
  height: 300px;
  border-radius: 95px 95px 70px 70px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line-strong);
  box-shadow: 0 30px 60px -25px rgba(0, 0, 0, .9), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.mouse-tail {
  position: absolute; left: 50%; top: -26px; transform: translateX(-50%);
  width: 6px; height: 30px; border-radius: 6px;
  background: var(--line-strong);
}
.mouse-btn {
  position: absolute; top: 0; height: 132px; width: 50%;
  display: grid; place-items: start center;
  padding-top: 22px;
  font: 700 14px var(--mono); color: var(--fg-faint);
  cursor: pointer; transition: all .1s;
}
.m-left { left: 0; border-radius: 95px 0 0 0; border-right: 1px solid var(--line); }
.m-right { right: 0; border-radius: 0 95px 0 0; }
.mouse-wheel {
  position: absolute; left: 50%; top: 30px; transform: translateX(-50%);
  width: 26px; height: 64px; border-radius: 13px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 4px 0; cursor: pointer; z-index: 3; transition: all .1s;
}
.wheel-up, .wheel-down { font-size: 9px; color: var(--fg-faint); transition: all .1s; }
.wheel-grip { flex: 1; width: 60%; margin: 3px 0; border-radius: 6px; background: repeating-linear-gradient(0deg, var(--line) 0 2px, transparent 2px 4px); }
.mouse-side {
  position: absolute; left: -14px; width: 14px; height: 30px;
  border-radius: 6px 0 0 6px; background: var(--surface-2);
  border: 1px solid var(--line-strong); border-right: 0;
  display: grid; place-items: center; font: 700 10px var(--mono); color: var(--fg-faint);
  cursor: pointer; transition: all .1s;
}
.m-back { top: 96px; }
.m-fwd { top: 132px; }
.mouse [data-button].is-press,
.mouse .mouse-wheel.is-press,
.mouse .wheel-up.is-press, .mouse .wheel-down.is-press {
  background: var(--accent); color: #04121a; box-shadow: var(--glow);
}
.mouse-info {
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 16px;
}
.mi-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.mi-row:last-of-type { border-bottom: 0; }
.mi-row span { color: var(--fg-dim); font-size: 13px; }
.mi-row b { font: 700 15px var(--mono); color: var(--c1); }
.mouse-area-hint { color: var(--fg-faint); font-size: 12px; margin: 12px 0 4px; }

/* ---------- Gamepad ---------- */
.gp-status {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; color: var(--fg-dim); font-size: 14px;
}
.gp-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--fg-faint); box-shadow: 0 0 0 0 rgba(34,211,238,.5); }
.gp-status.connected { color: var(--fg); }
.gp-status.connected .gp-dot { background: var(--c1); animation: blip 1.6s infinite; }
@keyframes blip { 0% { box-shadow: 0 0 0 0 rgba(34,211,238,.5);} 70%{box-shadow:0 0 0 8px rgba(34,211,238,0);} 100%{box-shadow:0 0 0 0 rgba(34,211,238,0);} }
.gp-stage { margin-top: 18px; display: grid; gap: 22px; }
.gp-pad-name { font: 600 13px var(--mono); color: var(--fg-dim); margin-bottom: 12px; word-break: break-all; }
.gp-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.gp-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 6px; text-align: center; transition: all .08s;
}
.gp-btn-name { font: 700 11px var(--mono); color: var(--fg-dim); display: block; }
.gp-btn-val { font: 500 10px var(--mono); color: var(--fg-faint); }
.gp-btn.pressed { background: var(--accent); color: #04121a; border-color: transparent; box-shadow: var(--glow); }
.gp-btn.pressed .gp-btn-name, .gp-btn.pressed .gp-btn-val { color: #04121a; }
.gp-axes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.gp-stick { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; }
.gp-stick-pad { position: relative; width: 110px; height: 110px; margin: 10px auto 8px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.gp-stick-dot { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: var(--accent); box-shadow: var(--glow); transition: transform .04s linear; }
.gp-stick-label { font: 600 12px var(--mono); color: var(--fg-dim); }
.gp-stick-val { font: 500 11px var(--mono); color: var(--fg-faint); }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 26px clamp(16px, 3vw, 30px) 34px;
  text-align: center;
  color: var(--fg-dim);
}
.dedication { font-size: 15px; line-height: 1.6; max-width: 720px; margin: 0 auto 10px; }
.dedication strong { color: var(--fg); }
.footer-meta { font-size: 13px; color: var(--fg-faint); }
.link-like { appearance: none; background: none; border: 0; color: var(--c1); cursor: pointer; font: inherit; padding: 0; }
.link-like:hover { text-decoration: underline; }

/* ---------- About dialog ---------- */
.about {
  width: min(620px, 92vw);
  max-height: 85vh;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  color: var(--fg);
  padding: 28px;
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, .9);
}
.about::backdrop { background: rgba(3, 5, 10, .7); backdrop-filter: blur(4px); }
.about h2 { margin: 0 0 8px; font-size: 24px; }
.about h3 { margin: 22px 0 10px; font-size: 14px; color: var(--c1); text-transform: uppercase; letter-spacing: .06em; }
.about p { color: var(--fg-dim); line-height: 1.6; font-size: 14px; }
.about-close-form { position: absolute; top: 16px; right: 16px; margin: 0; }
.about-close { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; font-size: 14px; }
.about-close:hover { background: var(--surface-2); }
.people { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.people a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--fg); font-size: 13px; text-decoration: none; transition: all .12s;
}
.people a:hover { border-color: var(--c1); background: var(--surface-2); text-decoration: none; transform: translateY(-1px); }
.people a::before { content: "@"; color: var(--fg-faint); }
.about-foot { margin-top: 22px; font-size: 13px; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .tabs { order: 3; width: 100%; margin: 4px 0 0; justify-content: center; }
  .tab-txt { display: none; }
  .tab { padding: 9px 14px; }
  .tab-ico { font-size: 18px; }
  .brand-ver { display: none; }
  .toolbar { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
