:root {
  --bg: #0f0a1a;
  --surface: #1a1228;
  --border: #3d2f5c;
  --text: #f0e8ff;
  --muted: #9a8ab8;
  --accent: #ff4d9d;
  --accent-dim: #c93a78;
  --hit: #5cff8a;
  --hit-glow: rgba(92, 255, 138, 0.45);
  --warn: #ffc14d;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #2a1848 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.header {
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.subtitle a {
  color: var(--accent);
}

.status {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 1rem 1rem;
}

.status-message {
  margin: 0;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.status-message.connected {
  border-color: var(--hit);
  color: var(--hit);
}

.status-message.waiting {
  border-color: var(--warn);
  color: var(--warn);
}

.pad-activate-banner {
  margin-bottom: 0.75rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, #2a1848 0%, var(--surface) 100%);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  text-align: center;
}

.pad-activate-banner[hidden] {
  display: none;
}

.pad-activate-banner .primary {
  margin: 0 0 0.5rem;
  padding: 0.65rem 1.4rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.pad-activate-banner .primary:hover {
  filter: brightness(1.08);
}

.pad-activate-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.device-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.5rem 1.5rem;
  margin: 0.75rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.device-info div {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.device-info dt {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.device-info dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr min(22rem, 100%);
  gap: 1.5rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.pad-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.pad-label {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.pad-grid {
  display: grid;
  grid-template-columns: repeat(3, 5.5rem);
  grid-template-rows: repeat(3, 5.5rem);
  gap: 0.5rem;
}

.pad-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 0.7rem;
  color: var(--muted);
  transition: border-color 0.08s, background 0.08s, box-shadow 0.08s, transform 0.06s;
  user-select: none;
  cursor: pointer;
}

.pad-cell .cell-label {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text);
}

.pad-cell .cell-index {
  font-family: var(--mono);
  font-size: 0.65rem;
}

.pad-cell.unmapped .cell-index::before {
  content: "btn ";
}

.pad-cell.pressed {
  border-color: var(--hit);
  background: #142818;
  box-shadow: 0 0 18px var(--hit-glow);
  transform: scale(0.96);
  color: var(--hit);
}

.pad-cell.pressed .cell-label,
.pad-cell.pressed .cell-index {
  color: var(--hit);
}

.pad-cell.panel-red .cell-label {
  color: #ff5c5c;
}

.pad-cell.panel-yellow .cell-label {
  color: #ffd54f;
}

.pad-cell.panel-symbol .cell-label {
  color: #e8e0ff;
  font-size: 1.15rem;
  font-weight: 700;
}

.pad-cell.no-panel {
  opacity: 0.35;
  cursor: default;
  border-style: dashed;
}

.pad-cell.no-panel .cell-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.pad-cell.assigning {
  border-color: var(--accent);
  animation: pulse 0.6s ease infinite alternate;
}

@keyframes pulse {
  from { box-shadow: 0 0 0 transparent; }
  to { box-shadow: 0 0 14px rgba(255, 77, 157, 0.5); }
}

.pad-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

button {
  font: inherit;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-dim);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

button.small {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.button-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 14rem;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
}

.button-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  border-bottom: 1px solid #2a2040;
}

.button-list li.active {
  color: var(--hit);
  font-weight: 600;
}

.log {
  margin: 0 0 0.5rem;
  padding-left: 1.25rem;
  max-height: 12rem;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.log li {
  margin-bottom: 0.2rem;
}

.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.footer a {
  color: var(--accent);
}

.footer code {
  font-family: var(--mono);
  font-size: 0.85em;
}
