:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #161a22;
  --key: #1f2530;
  --key-active: #323b4d;
  --accent: #3d8bfd;
  --danger: #e05252;
  --text: #e8ebf1;
  --text-dim: #8890a0;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  padding: 4px 8px;
  cursor: pointer;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}
.status-dot.connected { background: #4caf50; }
.status-dot.connecting { background: #e0a852; }

.status-text {
  font-size: 13px;
  color: var(--text-dim);
}

.remote {
  max-width: 480px;
  margin: 0 auto;
  padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.row {
  display: flex;
  gap: 12px;
}

.key {
  flex: 1;
  background: var(--key);
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  padding: 16px 8px;
  cursor: pointer;
  transition: background 0.08s ease, transform 0.08s ease;
}

.key:active, .key.pressed {
  background: var(--key-active);
  transform: scale(0.96);
}

.power-row .key-power {
  color: var(--danger);
  font-size: 22px;
  flex: 1;
}
.power-row .key-mute { flex: 1; font-size: 20px; }
.power-row .key-source { flex: 1.4; }

.nums-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.nums-row .key { padding: 14px 8px; font-size: 17px; }

.dpad-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.vol-col, .ch-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pill-btn {
  width: 64px;
  padding: 18px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.dpad {
  position: relative;
  width: 200px;
  height: 200px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  background: var(--panel);
  border-radius: 50%;
  overflow: hidden;
}

.dpad .key {
  background: transparent;
  border-radius: 0;
  font-size: 18px;
}
.dpad .key:active { background: var(--key-active); }

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center {
  grid-column: 2; grid-row: 2;
  background: var(--key);
  border-radius: 50%;
  margin: 6px;
  font-weight: 700;
  color: var(--accent);
}
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

.nav-row .key, .transport-row .key, .apps-row .key {
  font-size: 15px;
  padding: 14px 6px;
}

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  width: min(90vw, 380px);
  padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }

dialog h2 { margin: 0 0 12px; font-size: 18px; }

dialog label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

dialog input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #2a3140;
  background: #0f131a;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 8px;
}

.hint { font-size: 12px; color: var(--text-dim); margin: 4px 0 0; }
.pair-hint { color: var(--accent); margin-top: 12px; }

.debug-log {
  background: #0f131a;
  border: 1px solid #2a3140;
  border-radius: 10px;
  padding: 10px;
  font-size: 11px;
  line-height: 1.5;
  color: #9fb0c9;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0 0;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
}

.primary-btn, .ghost-btn {
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  cursor: pointer;
}
.primary-btn { background: var(--accent); color: #fff; flex: 1; }
.ghost-btn { background: transparent; color: var(--danger); border: 1px solid #3a2530; }
