/* ===== Walftech Gamepad Tester ===== */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e3e5ea;
  --text: #14161a;
  --muted: #71757f;
  --accent: #5b5bf0;
  --accent-soft: #ecebff;
  --good: #17c964;
  --warn: #f5a524;
  --danger: #f31260;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(20,22,26,.06), 0 8px 24px rgba(20,22,26,.05);
  --sidebar-w: 260px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0c0d10;
  --surface: #16181d;
  --surface-2: #1e2128;
  --border: #262a33;
  --text: #eceef2;
  --muted: #8b909c;
  --accent: #7c7cff;
  --accent-soft: #23233a;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 12px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; padding: 0 6px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px;
  object-fit: cover; display: block;
  box-shadow: 0 6px 18px rgba(91,91,240,.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: none; background: transparent;
  color: var(--muted); font-size: 14.5px; font-weight: 500;
  border-radius: 12px; cursor: pointer; text-align: left;
  transition: all .18s ease; font-family: inherit;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-foot { margin-top: 16px; display: flex; gap: 10px; align-items: center; }
.lang-select {
  flex: 1; padding: 9px 10px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px; font-family: inherit;
  cursor: pointer; transition: all .16s;
}
.lang-select:hover { border-color: var(--accent); }
.theme-toggle {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; display: grid; place-items: center;
  transition: all .18s;
}
.theme-toggle:hover { background: var(--accent-soft); color: var(--accent); }
.theme-toggle svg { width: 20px; height: 20px; }
.ico-sun { display: none; }
[data-theme="dark"] .ico-moon { display: none; }
[data-theme="dark"] .ico-sun { display: block; }

/* ===== Main ===== */
.main { padding: 40px 48px; max-width: 1100px; }
.view { display: none; animation: fade .3s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 28px; }
.view-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.view-head p { color: var(--muted); margin-top: 6px; font-size: 14.5px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card h4 { font-size: 15px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  padding: 10px 18px; border-radius: 11px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: all .16s; font-family: inherit;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.mini { padding: 7px 12px; font-size: 12.5px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.mini:hover { border-color: var(--accent); color: var(--accent); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.center { justify-content: center; }
.btn-row.presets { margin-top: 10px; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center; padding: 70px 20px; position: relative;
  border: 2px dashed var(--border); border-radius: var(--radius);
}
.empty-state svg { width: 64px; height: 64px; color: var(--muted); opacity: .5; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; margin-bottom: 6px; }
.empty-state p { color: var(--muted); font-size: 14px; }
.pulse-ring {
  position: absolute; top: 92px; left: 50%; width: 64px; height: 64px;
  border: 2px solid var(--accent); border-radius: 50%;
  transform: translateX(-50%); animation: pulse 1.8s ease-out infinite; opacity: 0;
}
@keyframes pulse { 0% { transform: translateX(-50%) scale(.6); opacity: .6; } 100% { transform: translateX(-50%) scale(1.8); opacity: 0; } }

/* ===== Gamepad ===== */
.gp-info { display: flex; justify-content: space-between; align-items: center; }
.gp-info strong { display: block; font-size: 17px; margin-top: 3px; }
.gp-info-meta { display: flex; gap: 20px; font-size: 13px; color: var(--muted); }
.gp-info-meta b { color: var(--accent); font-size: 16px; }
.gp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.buttons-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; }
.gp-btn {
  aspect-ratio: 1; border-radius: 11px; background: var(--surface-2);
  border: 1px solid var(--border); display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--muted);
  position: relative; overflow: hidden; transition: all .08s;
}
.gp-btn .val { position: absolute; bottom: 3px; font-size: 9px; opacity: .6; }
.gp-btn.pressed { background: var(--accent); color: #fff; border-color: var(--accent); transform: scale(.94); box-shadow: 0 0 0 3px var(--accent-soft); }

.sticks-wrap { display: flex; gap: 18px; justify-content: center; margin-bottom: 16px; }
.stick-pad {
  width: 110px; height: 110px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  position: relative;
}
.stick-pad::after { content: ""; position: absolute; inset: 50% auto auto 50%; width: 1px; height: 100%; background: var(--border); transform: translateX(-50%); }
.stick-pad::before { content: ""; position: absolute; inset: 50% 0 auto 0; height: 1px; background: var(--border); }
.stick-dot {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  position: absolute; top: 50%; left: 50%; margin: -13px 0 0 -13px;
  transition: transform .04s linear; box-shadow: 0 2px 8px rgba(91,91,240,.5); z-index: 2;
}
.axes-list { display: flex; flex-direction: column; gap: 8px; }
.axis-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.axis-row span { width: 44px; color: var(--muted); }
.axis-track { flex: 1; height: 6px; background: var(--surface-2); border-radius: 4px; position: relative; }
.axis-thumb { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); transform: translate(-50%, -50%); left: 50%; }
.axis-val { width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Gamepad visual ===== */
.gp-viz-card { text-align: center; }
.gp-viz-head { display: flex; align-items: center; justify-content: center; gap: 10px; }
.tag { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.gp-viz { max-width: 440px; margin: 6px auto 0; }
.gp-svg, #gp-svg { width: 100%; height: auto; }
.gp-viz-hint { margin-top: 6px; }

#gp-svg .body { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; }
#gp-svg .pad { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; transition: fill .06s, stroke .06s; }
#gp-svg .dpad { fill: var(--muted); stroke: none; opacity: .55; }
#gp-svg .small, #gp-svg .guide { fill: var(--muted); stroke: none; opacity: .5; }
#gp-svg #st-left, #gp-svg #st-right { transition: transform .05s linear; }
#gp-svg .stick-base { fill: var(--border); }
#gp-svg .stick-top { fill: var(--muted); opacity: .7; transition: fill .06s; }
#gp-svg .face { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; transition: fill .06s, stroke .06s; }
#gp-svg .flbl, #gp-svg .tlbl { fill: var(--text); font-size: 15px; font-weight: 700; text-anchor: middle; pointer-events: none; }
#gp-svg .tlbl { font-size: 11px; fill: var(--muted); }
#gp-svg .trig-bg { fill: var(--border); }
#gp-svg .touchpad { fill: var(--surface); stroke: var(--border); stroke-width: 2; }
#gp-svg .small.vert { opacity: .55; }
#gp-svg .trig { fill: var(--accent); transform-box: fill-box; transform-origin: center; transition: transform .05s; }

/* pressed states */
#gp-svg .pad.on, #gp-svg .face.on { fill: var(--accent); stroke: var(--accent); }
#gp-svg .face.on { filter: drop-shadow(0 0 6px var(--accent)); }
#gp-svg .stick-top.on { fill: var(--accent); }
#gp-svg .dpad.on { fill: var(--accent); opacity: 1; }
#gp-svg .small.on, #gp-svg .guide.on { fill: var(--accent); opacity: 1; }

/* ===== Mic recorder ===== */
.rec-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.rec-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #fff; margin-right: 4px; }
#rec-start.recording { background: var(--danger); }
#rec-start.recording .rec-dot { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec-progress { flex: 1; min-width: 120px; height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.rec-progress-fill { height: 100%; width: 0%; background: var(--danger); transition: width .1s linear; }
.rec-count { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; min-width: 26px; text-align: center; }
.rec-audio { width: 100%; margin-top: 16px; }
.rec-actions { margin-top: 12px; }

/* ===== CPS ===== */
.cps-controls { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 4px; gap: 4px; }
.seg button { border: none; background: transparent; color: var(--muted); padding: 7px 16px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; font-family: inherit; transition: all .15s; }
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.cps-arena {
  height: 260px; display: grid; place-items: center; cursor: pointer;
  user-select: none; -webkit-user-select: none; text-align: center;
  transition: background .1s, border-color .1s; position: relative; overflow: hidden;
}
.cps-arena.active { border-color: var(--accent); }
.cps-arena.flash { background: var(--accent-soft); }
.cps-arena h2 { font-size: 64px; font-weight: 800; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.cps-idle span { display: block; font-size: 14px; color: var(--muted); letter-spacing: .1em; margin-top: 4px; }
.cps-idle p { margin-top: 14px; }

.cps-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { text-align: center; padding: 16px; margin: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.stat.best strong { color: var(--accent); }

.mouse-buttons { margin-top: 8px; }
.mb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.mb {
  padding: 18px 10px; text-align: center; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted); transition: all .1s; user-select: none;
}
.mb.hit { background: var(--good); color: #fff; border-color: var(--good); }

/* ===== Tug of war minigame ===== */
.tug-card { margin-top: 8px; }
.tug-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tug-scores { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.tug-scores b { color: var(--text); font-variant-numeric: tabular-nums; }
.tug-scores .best b { color: var(--accent); }

.tug-field { display: flex; align-items: center; gap: 14px; margin: 20px 0 8px; }
.tug-player { display: flex; flex-direction: column; align-items: center; font-size: 34px; line-height: 1; flex-shrink: 0; transition: transform .1s; }
.tug-player small { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.tug-player.pull-you { transform: translateX(-4px) scale(1.08); }
.tug-player.pull-rival { transform: translateX(4px) scale(1.08); }

.tug-track {
  flex: 1; height: 60px; border-radius: 14px; position: relative;
  background: linear-gradient(90deg, rgba(23,201,100,.14), transparent 45%, transparent 55%, rgba(243,18,96,.14));
  border: 1px solid var(--border); overflow: hidden;
}
.tug-center-line { position: absolute; left: 50%; top: 8px; bottom: 8px; width: 2px; background: var(--border); transform: translateX(-50%); }
.tug-rope {
  position: absolute; top: 50%; left: 50%; height: 6px; width: 78%;
  transform: translate(-50%, -50%);
  background: repeating-linear-gradient(90deg, var(--muted) 0 10px, transparent 10px 16px);
  opacity: .7; transition: none;
}
.tug-knot {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 26px; transition: left .05s linear; z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
}
.tug-track.win { border-color: var(--good); box-shadow: inset 0 0 0 2px var(--good); }
.tug-track.lose { border-color: var(--danger); box-shadow: inset 0 0 0 2px var(--danger); }
.tug-controls { margin-top: 14px; }
#tug-pull { min-width: 220px; font-size: 15px; padding: 14px 22px; }
#tug-pull:active { transform: scale(.97); }

/* ===== Meter / Mic ===== */
.mic-top { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.select {
  flex: 1; min-width: 180px; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14px; font-family: inherit;
}
.meter-wrap { margin-bottom: 16px; }
.meter { height: 22px; border-radius: 11px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.meter-fill { height: 100%; width: 0%; border-radius: 11px; background: linear-gradient(90deg, var(--good), var(--warn) 70%, var(--danger)); transition: width .05s linear; }
.meter-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.wave { width: 100%; height: 140px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); display: block; margin-bottom: 16px; }
.mic-stats { display: flex; gap: 30px; }
.mic-stats .stat { text-align: left; padding: 0; background: none; border: none; box-shadow: none; }
.mic-stats .stat strong { font-size: 20px; }

/* ===== Audio ===== */
.chan-indicator { display: flex; gap: 14px; margin-top: 16px; }
.chan {
  flex: 1; height: 56px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); transition: all .12s;
}
.chan.on { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.freq-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.freq-row input[type=range] { flex: 1; accent-color: var(--accent); height: 6px; }
.freq-row output { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 90px; text-align: right; }
.sweep-bar { height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); margin-top: 14px; overflow: hidden; }
.sweep-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 4px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 12px 22px; border-radius: 12px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: all .3s; z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Footer ===== */
.site-footer {
  grid-column: 1 / -1;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 48px 48px 24px;
  margin-top: 40px;
}
.footer-top {
  max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 40px;
}
.footer-brand p { color: var(--muted); font-size: 13.5px; line-height: 1.6; margin: 14px 0 18px; max-width: 300px; }
.footer-logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.footer-logo img { width: 34px; height: 34px; border-radius: 9px; }
.footer-logo b { background: linear-gradient(90deg, var(--accent), #c05bf0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.footer-social { display: flex; gap: 10px; }
.footer-social a {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); transition: all .16s;
}
.footer-social a:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-2px); }
.footer-social svg { width: 18px; height: 18px; }
.footer-col h5 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: 16px; position: relative; padding-left: 26px;
}
.footer-col h5::before { content: ""; position: absolute; left: 0; top: 50%; width: 18px; height: 2px; background: linear-gradient(90deg, var(--accent), transparent); transform: translateY(-50%); }
.footer-col a {
  display: block; color: var(--text); opacity: .75; text-decoration: none;
  font-size: 14px; margin-bottom: 11px; transition: all .15s;
}
.footer-col a:hover { opacity: 1; color: var(--accent); padding-left: 4px; }
.footer-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 14px; }
.footer-bottom {
  max-width: 1100px; margin: 36px auto 0; padding-top: 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  font-size: 13px; color: var(--muted);
}
.footer-bottom b { color: var(--accent); }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; height: auto; width: 100%;
    flex-direction: row; z-index: 50; padding: 8px 10px; border-right: none; border-top: 1px solid var(--border);
    justify-content: space-between; align-items: center;
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; justify-content: space-around; width: 100%; }
  .nav-item { flex-direction: column; gap: 3px; padding: 8px; font-size: 11px; }
  .nav-item span { font-size: 10.5px; }
  .main { padding: 24px 18px 100px; }
  .gp-grid, .cps-stats { grid-template-columns: 1fr; }
  .cps-stats { grid-template-columns: repeat(2, 1fr); }
  .site-footer { padding: 36px 20px 90px; }
  .footer-top { grid-template-columns: 1fr 1fr; gap: 28px; }
  .footer-bottom { flex-direction: column; text-align: center; }
}
@media (max-width: 520px) {
  .footer-top { grid-template-columns: 1fr; }
}
