:root {
  color-scheme: dark;
  --bg: #111412;
  --panel: rgba(10, 16, 13, 0.74);
  --panel-soft: rgba(255, 255, 255, 0.055);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f5fff7;
  --muted: #aeb8af;
  --brand: #23d160;
  --brand-soft: rgba(35, 209, 96, 0.22);
  --brand-strong: #87ffaa;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app[data-device="keyboard"] {
  --brand: #2f8cff;
  --brand-soft: rgba(47, 140, 255, 0.22);
  --brand-strong: #8cc0ff;
}

.app[data-device="mouse"] {
  --brand: #e0c62f;
  --brand-soft: rgba(224, 198, 47, 0.22);
  --brand-strong: #ffe98c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #0d0f0e;
  color: var(--text);
}

button {
  font: inherit;
}

.app {
  height: 100vh;
  padding: 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 62% 22%, var(--brand-soft), transparent 35rem),
    linear-gradient(140deg, #0b0d0c 0%, var(--bg) 54%, #101210 100%);
}

.brand-gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  gap: 22px;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(12, 14, 13, 0.98), rgba(12, 14, 13, 0.86)),
    radial-gradient(circle at 72% 52%, var(--brand-soft), transparent 32rem);
}

.brand-gate.hidden {
  display: none;
}

.gate-copy {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(34px, 6vw, 72px);
  line-height: 1.02;
}

h2 {
  margin-bottom: 0;
  font-size: 28px;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.gate-copy p:last-child {
  max-width: 620px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
}

.brand-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 220px));
  justify-content: center;
  gap: 14px;
}

@media (max-width: 640px) {
  .brand-grid {
    grid-template-columns: minmax(0, 220px);
  }
}

.brand-card {
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.brand-card.active,
.brand-card:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.brand-card strong,
.brand-card small {
  display: block;
}

.brand-card strong {
  margin-top: 18px;
  font-size: 21px;
}

.brand-card small {
  margin-top: 4px;
  color: var(--muted);
}

.brand-mark {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.06);
}

.brand-mark.xbox {
  background: #23d160;
}

.brand-mark.keyboard {
  border-radius: 8px;
  background: #2fd0e0;
}

.brand-mark.mouse {
  border-radius: 40% 40% 50% 50%;
  background: #e0c62f;
}

.hidden {
  display: none;
}

.gate-actions,
.toolbar,
.footer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-action,
.ghost-action,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.primary-action {
  min-height: 46px;
  padding: 0 18px;
  background: var(--brand);
  color: #061207;
  font-weight: 900;
}

.primary-action.compact {
  min-width: 92px;
  white-space: nowrap;
}

.ghost-action,
.icon-button {
  min-height: 46px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line);
}

.icon-button {
  width: 46px;
  padding: 0;
  font-size: 20px;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.workspace[hidden] {
  display: none;
}

.topbar,
.model-stage,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.topbar,
.detail-panel {
  /* model-stage는 매 프레임 렌더링되는 WebGL 캔버스를 담고 있어서, 여기에 backdrop-filter를
     적용하면 브라우저가 매 프레임 캔버스 아래를 다시 블러 처리해야 해서 랙의 주요 원인이 됩니다.
     정적인 패널에만 블러를 남겨둡니다. */
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.24);
  white-space: nowrap;
}

.status-pill span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff5d5d;
}

.status-pill.connected span {
  background: var(--brand);
  box-shadow: 0 0 16px var(--brand);
}

.stage-row {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr) minmax(280px, 340px);
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.stage-row > * {
  min-width: 0;
}

.model-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.32);
}

.model-stage.is-focusing {
  box-shadow: inset 0 0 110px rgba(0, 0, 0, 0.3), inset 0 0 96px var(--brand-soft);
}

#modelCanvas {
  position: absolute;
  inset: -1px;
  z-index: 0;
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  display: block;
  background: transparent;
  
}

.model-loading {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.model-loading.hidden {
  opacity: 0;
}

.focus-wash {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(circle at var(--focus-x, 50%) var(--focus-y, 12%), var(--brand-soft), transparent 17rem);
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.model-stage.is-focusing .focus-wash {
  opacity: 1;
}

.focus-label {
  position: absolute;
  z-index: 2;
  left: 16px;
  top: 16px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--brand-strong);
  background: rgba(0, 0, 0, 0.44);
  font-size: 13px;
  font-weight: 900;
}

.hotspot {
  /* 요청에 따라 화면 위 라벨 버튼(핫스팟)은 더 이상 표시하지 않습니다. */
  display: none;
}

/* ---------- 진동 위치 표시(와이파이 모양 파동) ---------- */
.vibe-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.vibe-site {
  position: absolute;
  left: var(--vx, 50%);
  top: var(--vy, 50%);
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
}

/* 진동원 중심의 은은한 코어 발광 (활성 상태일 때만 애니메이션 재생 → 유휴 시 GPU/CPU 사용 없음) */
.vibe-site::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand-strong);
  box-shadow: 0 0 14px 4px var(--brand);
  transform: translate(-50%, -50%);
  opacity: 0;
}

.vibe-site.active::before {
  animation: vibe-core 1.05s ease-in-out infinite;
}

.vibe-ring {
  position: absolute;
  left: 0;
  top: 0;
  width: 16px;
  height: 16px;
  border: 3px solid var(--brand-strong);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  /* transform: scale() 대신 실제 width/height를 애니메이션합니다.
     scale()는 작은 링을 텍스처로 렌더링한 뒤 몇 배씩 확대(업스케일)하는 방식이라
     테두리가 흐리게 뭉개져 보였습니다. 크기를 직접 바꾸면 매 프레임 테두리를
     다시 그리므로 화질이 또렷하게 유지됩니다. */
  will-change: width, height, border-width, opacity;
}

.vibe-site.active .vibe-ring {
  animation: vibe-ripple 1.05s cubic-bezier(0.2, 0.7, 0.3, 1) infinite;
}

.vibe-ring.r2 {
  animation-delay: 0.35s;
}

.vibe-ring.r3 {
  animation-delay: 0.7s;
}

@keyframes vibe-ripple {
  0% {
    width: 16px;
    height: 16px;
    opacity: 0.9;
    border-width: 3px;
  }
  100% {
    width: 150px;
    height: 150px;
    opacity: 0;
    border-width: 0.5px;
  }
}

@keyframes vibe-core {
  0%, 100% {
    opacity: 0;
  }
  15%, 55% {
    opacity: 0.9;
  }
  80% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .vibe-ring,
  .vibe-site::before {
    animation: none;
    display: none;
  }
}

/* 위치는 app.js에서 3D 카메라 투영으로 매 프레임 픽셀 단위로 계산되어 적용됩니다 */

.detail-panel {
  display: grid;
  grid-template-rows: repeat(4, auto);
  align-content: start;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
}

.panel-section {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.16);
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-head span {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 900;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.button-cell {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.button-cell.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #061207;
}

.stick-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stick-meter {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  background:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    rgba(255, 255, 255, 0.045);
  background-size: 50% 50%;
}

.stick-meter span {
  position: absolute;
  left: 10px;
  top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.stick-meter i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 20px var(--brand);
  transform: translate(-50%, -50%);
}

.axis-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin-top: 8px;
}

.axis-readout p {
  display: flex;
  justify-content: space-between;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.axis-readout b {
  color: var(--text);
}

.trigger-bar {
  display: grid;
  grid-template-columns: 34px 1fr 42px;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

meter {
  width: 100%;
  height: 12px;
}

meter::-webkit-meter-bar {
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

meter::-webkit-meter-optimum-value {
  border-radius: 999px;
  background: var(--brand);
}

.vibration-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.vib-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.vib-button:hover {
  background: var(--brand);
  color: #061207;
}

.vib-button:active {
  transform: scale(0.97);
}

.vib-button.is-vibrating {
  border-color: var(--brand);
  background: var(--brand);
  color: #061207;
  box-shadow: 0 0 0 1px var(--brand), 0 0 18px var(--brand-soft);
}

.vib-button.ghost {
  grid-column: 1 / -1;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.vib-button.ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.vib-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.info-panel {
  grid-template-rows: auto auto 1fr;
}

.info-rows {
  display: grid;
  gap: 8px;
}

.info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.info-row span {
  flex: none;
  white-space: nowrap;
}

.info-row strong {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-text {
  margin: 0;
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.5;
}

.actions-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-self: end;
}

.actions-section button {
  min-width: 0;
}

/* ---------- 공용: 컴팩트 리셋 버튼 / 칩 ---------- */
.compact-reset {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 34px;
}

.chip {
  padding: 5px 10px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
}

.empty-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.legend-rows {
  display: grid;
  gap: 6px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  border: 1px solid var(--line);
}

.legend-dot.legend-active {
  border-color: var(--brand);
  background: var(--brand);
}

.legend-dot.legend-tested {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.legend-dot.legend-untested {
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- 키보드 테스터 ---------- */
.kb-visual-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.kb-hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.kb-hint.hidden {
  opacity: 0;
}

.keyboard-layout {
  display: flex;
  gap: 10px;
  width: 100%;
}

.kb-main {
  flex: 1;
  display: grid;
  gap: 6px;
}

.kb-side {
  display: grid;
  gap: 10px;
  align-content: start;
  width: 130px;
}

.kb-nav-cluster,
.kb-arrow-cluster {
  display: grid;
  gap: 6px;
}

.kb-row {
  display: flex;
  gap: 6px;
}

.kb-key {
  flex: 1 0 0;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  cursor: default;
  user-select: none;
}

.kb-key-spacer {
  border: none;
  background: transparent;
}

.kb-key.tested {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.kb-key.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #061207;
  box-shadow: 0 0 14px var(--brand-soft);
}

/* ---------- 마우스 테스터 ---------- */
.mouse-pad-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
}

#mouseTrailCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.mouse-pad-hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.mouse-pad-hint.hidden {
  opacity: 0;
}

.mouse-coords {
  position: absolute;
  z-index: 2;
  left: 16px;
  bottom: 16px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.44);
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
}

.mouse-drag-badge {
  position: absolute;
  z-index: 2;
  right: 16px;
  bottom: 16px;
  padding: 8px 12px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--brand);
  color: #061207;
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.mouse-drag-badge.hidden {
  opacity: 0;
}

.mouse-visual {
  display: block;
  width: 100%;
  max-width: 160px;
  margin: 4px auto 8px;
}

.mouse-visual .mouse-body {
  fill: rgba(255, 255, 255, 0.06);
  stroke: var(--line);
  stroke-width: 2;
}

.mouse-visual .mouse-divider {
  stroke: var(--line);
  stroke-width: 2;
}

.mouse-visual .mouse-btn {
  fill: rgba(255, 255, 255, 0.04);
  stroke: var(--line);
  stroke-width: 1.5;
  transition: fill 100ms ease, stroke 100ms ease;
}

.mouse-visual .mouse-btn.active {
  fill: var(--brand);
  stroke: var(--brand);
  filter: drop-shadow(0 0 8px var(--brand-soft));
}

.mouse-visual-caption {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.scroll-bar-track {
  position: relative;
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.scroll-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 120ms ease;
}

.scroll-bar-fill.scroll-up {
  background: #6fc8ff;
}

.scroll-bar-fill.scroll-down {
  background: var(--brand);
}

@media (max-width: 980px) {
  .app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 14px;
  }

  .workspace {
    height: auto;
  }

  .stage-row {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  /* 좁은 화면에서는 3D 컨트롤러를 맨 위로, 정보 패널과 컨트롤 패널을 그 아래로 쌓습니다. */
  .model-stage {
    order: 1;
    min-height: 54svh;
  }

  .info-panel {
    order: 2;
  }

  .controls-panel {
    order: 3;
  }

  .actions-section button {
    flex: 1;
  }
}

@media (max-width: 640px) {
  .brand-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .button-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}