:root {
  color-scheme: dark;
  --bg: #07090f;
  --panel: #11151f;
  --panel-2: #181f2c;
  --text: #f3f6fb;
  --muted: #9aa7bb;
  --edge: #344057;
  --red: #f04b5f;
  --blue: #45a3ff;
  --green: #4de1a1;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 980px;
  min-height: 100vh;
  color: var(--text);
  font-family: "Segoe UI", "Microsoft JhengHei UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(69, 163, 255, 0.14), transparent 28%),
    radial-gradient(circle at 78% 74%, rgba(240, 75, 95, 0.13), transparent 30%),
    linear-gradient(135deg, #07090f, #111722 58%, #090c12);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(1420px, calc(100vw - 40px));
  margin: 20px auto;
  padding: 22px;
  border: 1px solid rgba(154, 167, 187, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(17, 21, 31, 0.96), rgba(24, 31, 44, 0.92)),
    repeating-linear-gradient(112deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 22px);
  box-shadow: 0 24px 60px var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 50px;
  height: 20px;
  border-top: 3px solid var(--red);
  border-bottom: 3px solid var(--blue);
  transform: skewX(-22deg);
  filter: drop-shadow(0 0 14px rgba(69, 163, 255, 0.32));
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
  white-space: nowrap;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.version-badge {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid rgba(77, 225, 161, 0.44);
  border-radius: 999px;
  color: var(--green);
  background: rgba(77, 225, 161, 0.08);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

p {
  margin: 3px 0 0;
  color: var(--muted);
  max-width: 460px;
  line-height: 1.35;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

select,
.primary-button,
.secondary-button,
.system-toggle {
  border: 1px solid rgba(154, 167, 187, 0.36);
  border-radius: 6px;
  color: var(--text);
  background: rgba(7, 9, 15, 0.7);
}

select {
  width: 300px;
  min-height: 38px;
  padding: 0 10px;
}

#mappingMode {
  width: 120px;
}

.primary-button {
  min-height: 38px;
  padding: 0 18px;
  border-color: rgba(77, 225, 161, 0.7);
  background: linear-gradient(135deg, rgba(77, 225, 161, 0.22), rgba(69, 163, 255, 0.16));
  cursor: pointer;
}

.secondary-button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
  cursor: pointer;
}

.compact-button {
  padding: 0 10px;
  white-space: nowrap;
}

.nav-button {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  white-space: nowrap;
}

.system-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 10px;
  color: #c9d8ec;
  white-space: nowrap;
  cursor: pointer;
}

.system-toggle input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--green);
}

.status-strip {
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr) 80px 250px 170px;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
  padding: 12px 14px;
  min-height: 88px;
  border: 1px solid rgba(154, 167, 187, 0.22);
  border-radius: 8px;
  background: rgba(7, 9, 15, 0.34);
}

.status-strip > div,
.threshold-control {
  display: grid;
  gap: 4px;
  min-width: 0;
  align-content: center;
}

.status-strip strong {
  display: -webkit-box;
  min-height: 38px;
  max-height: 38px;
  overflow: hidden;
  line-height: 19px;
  word-break: break-word;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 14px;
  white-space: nowrap;
}

#rawInput {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 14px;
}

.threshold-control input {
  width: 150px;
  accent-color: var(--green);
}

.tester-deck {
  display: grid;
  grid-template-columns: 460px minmax(520px, 620px);
  gap: 18px;
  align-items: start;
  justify-content: start;
}

.zone-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 14px;
  color: var(--muted);
}

.zone-heading span {
  color: var(--text);
  font-weight: 700;
}

.zone-heading small {
  color: var(--muted);
}

.stick-stage {
  display: grid;
  place-items: center;
  min-height: 380px;
  border: 1px solid rgba(154, 167, 187, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    rgba(7, 9, 15, 0.28);
  background-size: 28px 28px;
}

.stick-map {
  position: relative;
  width: 300px;
  aspect-ratio: 1;
}

.gate {
  position: absolute;
  inset: 31%;
  border: 2px solid rgba(154, 167, 187, 0.38);
  border-radius: 50%;
  box-shadow: 0 0 0 22px rgba(255, 255, 255, 0.04);
}

.lever {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--green) 40%, #198a75 76%);
  box-shadow: 0 0 0 6px rgba(77, 225, 161, 0.18), 0 0 24px rgba(77, 225, 161, 0.5);
  transition: left 80ms linear, top 80ms linear;
}

.button-layout {
  display: grid;
  gap: 32px;
  padding-top: 28px;
}

.system-row,
.round-row,
.bottom-row {
  display: grid;
  justify-content: start;
}

.system-row {
  grid-template-columns: repeat(5, 104px);
  gap: 13px;
}

.round-row {
  grid-template-columns: repeat(4, 104px);
  gap: 22px;
}

.bottom-row {
  grid-template-columns: repeat(2, 104px);
  gap: 22px;
  padding-left: 126px;
}

.key-cell {
  display: grid;
  justify-items: center;
  gap: 0;
}

.count-key {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid rgba(154, 167, 187, 0.5);
  color: var(--text);
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.22), transparent 36%),
    linear-gradient(145deg, #303848, #131823 72%);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.3), 0 10px 18px rgba(0, 0, 0, 0.28);
  cursor: default;
}

body.mapping-mode .count-key {
  cursor: crosshair;
}

body.mapping-mode .count-key:hover,
.count-key.learning-key {
  border-color: var(--green);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.3), 0 0 22px rgba(77, 225, 161, 0.42);
}

.count-key.learning-key::after {
  content: "";
  position: absolute;
  inset: -7px;
  border: 1px solid rgba(77, 225, 161, 0.7);
  border-radius: inherit;
}

.round-key {
  width: 82px;
  height: 82px;
  border-radius: 50%;
}

.pill-key {
  width: 96px;
  height: 44px;
  border-radius: 999px;
}

.secondary-button:hover,
.primary-button:hover {
  border-color: var(--green);
}

.count-key.pressed {
  border-color: var(--green);
  transform: translateY(2px);
  box-shadow: inset 0 7px 14px rgba(0, 0, 0, 0.34), 0 0 18px rgba(77, 225, 161, 0.34);
}

.count-key.disabled-key {
  opacity: 0.52;
  border-color: rgba(154, 167, 187, 0.28);
  color: rgba(243, 246, 251, 0.7);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.36);
}

.count-key.disabled-key.pressed {
  transform: none;
  border-color: rgba(154, 167, 187, 0.28);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.36);
}

.count-key.system-key {
  border-style: dashed;
}

.count-key.system-key:not(.pressed) {
  border-color: rgba(77, 225, 161, 0.52);
}

.accent-red {
  border-color: rgba(240, 75, 95, 0.7);
}

.accent-blue {
  border-color: rgba(69, 163, 255, 0.72);
}

.key-label {
  position: absolute;
  top: -26px;
  left: 50%;
  display: inline-grid;
  place-items: center;
  min-height: 18px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
}

.input-interval {
  position: absolute;
  z-index: 2;
  top: -27px;
  left: calc(50% + 22px);
  display: inline-grid;
  place-items: center;
  min-width: 54px;
  min-height: 16px;
  padding: 0 6px;
  border: 1px solid rgba(77, 225, 161, 0.38);
  border-radius: 999px;
  color: var(--green);
  background: rgba(77, 225, 161, 0.08);
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
}

.input-interval:empty {
  display: none;
}

.ps-symbol {
  display: inline-grid;
  place-items: center;
  width: 14px;
  font-family: "Segoe UI Symbol", "Arial Unicode MS", "Microsoft JhengHei UI", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
  text-align: center;
  color: var(--muted);
}

.key-value {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stick-count.up {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

.stick-count.down {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
}

.stick-count.down .key-label {
  top: auto;
  bottom: -28px;
}

.stick-count .direction-symbol {
  width: 0;
  height: 0;
  min-height: 0;
  overflow: hidden;
  color: transparent;
  font-size: 0;
  line-height: 0;
  filter: drop-shadow(0 0 5px rgba(69, 163, 255, 0.5));
}

.stick-count.up .direction-symbol {
  top: -25px;
  border-right: 7px solid transparent;
  border-bottom: 12px solid #cfe5ff;
  border-left: 7px solid transparent;
}

.stick-count.down .direction-symbol {
  top: auto;
  bottom: -25px;
  border-top: 12px solid #cfe5ff;
  border-right: 7px solid transparent;
  border-left: 7px solid transparent;
}

.stick-count.left .direction-symbol,
.stick-count.right .direction-symbol {
  top: 50%;
  transform: translateY(-50%);
}

.stick-count.left .direction-symbol {
  left: -24px;
  border-top: 7px solid transparent;
  border-right: 12px solid #cfe5ff;
  border-bottom: 7px solid transparent;
}

.stick-count.right .direction-symbol {
  left: auto;
  right: -24px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 12px solid #cfe5ff;
}

.stick-count.up .input-interval {
  top: -31px;
  left: calc(50% + 20px);
}

.stick-count.down .input-interval {
  top: auto;
  bottom: -31px;
  left: calc(50% + 20px);
}

.stick-count.left .input-interval,
.stick-count.right .input-interval {
  top: -27px;
  left: calc(50% + 20px);
}

.pill-key .input-interval {
  top: -28px;
  right: auto;
  left: calc(50% + 38px);
  min-width: 54px;
}

.stick-count.left {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.stick-count.right {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.manual-shell {
  max-width: 1180px;
}

.manual-topbar {
  align-items: flex-start;
}

.manual-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: end;
  margin-bottom: 26px;
  padding: 26px;
  border: 1px solid rgba(154, 167, 187, 0.22);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(69, 163, 255, 0.12), rgba(77, 225, 161, 0.08));
}

.manual-kicker {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.manual-hero h2 {
  max-width: 760px;
  margin: 0;
  font-size: 30px;
  line-height: 1.25;
  letter-spacing: 0;
}

.manual-hero p {
  max-width: 760px;
  margin-top: 12px;
  line-height: 1.7;
}

.manual-spec {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid rgba(77, 225, 161, 0.42);
  border-radius: 8px;
  background: rgba(7, 9, 15, 0.38);
}

.manual-spec span {
  color: var(--muted);
  font-size: 12px;
}

.manual-spec strong {
  line-height: 1.45;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.manual-card {
  padding: 20px;
  border: 1px solid rgba(154, 167, 187, 0.22);
  border-radius: 8px;
  background: rgba(7, 9, 15, 0.28);
}

.manual-card h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.manual-card p,
.manual-card li,
.manual-card dd {
  color: #c9d8ec;
  line-height: 1.65;
}

.manual-card ol {
  margin: 0;
  padding-left: 20px;
}

.manual-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.manual-card dt {
  color: var(--text);
  font-weight: 800;
}

.manual-card dd {
  margin: -4px 0 8px;
}

.manual-card a {
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
}

.manual-card a:hover {
  text-decoration: underline;
}

.stats-card {
  grid-column: span 2;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 180px));
  gap: 12px;
  margin: 16px 0;
}

.stats-summary > div {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid rgba(77, 225, 161, 0.32);
  border-radius: 8px;
  background: rgba(7, 9, 15, 0.36);
}

.stats-summary span,
.stats-status,
.controller-meta {
  color: var(--muted);
  font-size: 12px;
}

.stats-summary strong {
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stats-status {
  margin: 8px 0 0;
}

.controller-list {
  display: grid;
  gap: 10px;
  max-height: 272px;
  margin: 16px 0 0;
  padding: 0 8px 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-color: rgba(77, 225, 161, 0.62) rgba(154, 167, 187, 0.16);
  scrollbar-width: thin;
}

.controller-list::-webkit-scrollbar {
  width: 8px;
}

.controller-list::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(154, 167, 187, 0.14);
}

.controller-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(77, 225, 161, 0.58);
}

.controller-item {
  display: grid;
  gap: 5px;
  min-height: 84px;
  padding: 12px 14px;
  border: 1px solid rgba(154, 167, 187, 0.22);
  border-radius: 8px;
  background: rgba(7, 9, 15, 0.28);
}

.controller-name {
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 800;
}

.copyright-card {
  border-color: rgba(77, 225, 161, 0.34);
}

@media (max-width: 1120px) {
  body {
    min-width: 760px;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 144px;
  }

  .tester-deck {
    grid-template-columns: 1fr;
  }

  .system-row,
  .round-row,
  .bottom-row {
    justify-content: center;
  }

  .bottom-row {
    padding-left: 0;
  }

  .manual-hero,
  .manual-grid {
    grid-template-columns: 1fr;
  }

  .stats-card {
    grid-column: auto;
  }
}
