:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #08111f;
  color: #f6f9ff;
  --surface: rgba(19, 34, 55, 0.92);
  --line: #34506e;
  --muted: #9fb2ca;
  --accent: #55d6ff;
  --success: #55e39d;
  --danger: #ff8c9f;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #08111f; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% -10%, rgba(34, 118, 170, 0.3), transparent 38%),
    linear-gradient(165deg, #0b1728 0%, #08111f 62%, #07101c 100%);
  overscroll-behavior: none;
}

button,
input { font: inherit; }

button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 13px;
  color: #f6f9ff;
  background: linear-gradient(180deg, #24415f, #1a304b);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.18);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 90ms ease, border-color 120ms ease, background 120ms ease;
}

button:active {
  transform: translateY(1px) scale(0.975);
  border-color: #6fa3ce;
  background: #2b5278;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
#pad:focus-visible {
  outline: 3px solid rgba(85, 214, 255, 0.68);
  outline-offset: 2px;
}

.remote-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: max(15px, env(safe-area-inset-top)) 14px max(30px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 13px;
}

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

.status-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #6f7f92;
  box-shadow: 0 0 0 5px rgba(111, 127, 146, 0.12);
}

.status-dot.good {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(85, 227, 157, 0.13), 0 0 15px rgba(85, 227, 157, 0.42);
}

h1 { margin: 0; font-size: clamp(1.15rem, 5vw, 1.55rem); line-height: 1.15; letter-spacing: -0.02em; }

#status {
  max-width: 68vw;
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status.good { color: var(--success); }

.quiet-button {
  min-height: 40px;
  flex: 0 0 auto;
  padding: 8px 12px;
  color: #c8d8ea;
  font-size: 0.86rem;
  background: rgba(26, 48, 75, 0.7);
  box-shadow: none;
}

.trackpad {
  min-height: clamp(230px, 35dvh, 365px);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 5px;
  border: 1px solid #456b91;
  border-radius: 28px;
  color: #b9cee5;
  text-align: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(63, 126, 184, 0.44), transparent 36%),
    linear-gradient(155deg, rgba(32, 65, 99, 0.96), rgba(13, 28, 47, 0.98));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.05), 0 20px 42px rgba(0, 0, 0, 0.25);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.trackpad strong { color: #edf7ff; font-size: 1rem; font-weight: 650; }
.trackpad span:last-child { font-size: 0.88rem; }
.trackpad-mark { color: var(--accent); font-size: 2.4rem; line-height: 1; transform: rotate(-18deg); }

.panel {
  margin-top: 13px;
  border: 1px solid rgba(64, 88, 116, 0.72);
  border-radius: 20px;
  padding: 12px;
  background: var(--surface);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
}

.quick-row,
.volume-row,
.key-row,
.more-grid,
.power-row { display: grid; gap: 8px; }

.quick-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.quick-row button { min-height: 44px; padding-inline: 7px; font-size: 0.86rem; }

.dpad {
  width: min(100%, 310px);
  margin: 11px auto;
  display: grid;
  grid-template: repeat(3, 56px) / repeat(3, minmax(56px, 1fr));
  gap: 7px;
}

.dpad button { min-height: 56px; padding: 0; font-size: 1.05rem; }
.dpad-up { grid-area: 1 / 2; }
.dpad-left { grid-area: 2 / 1; }
.dpad-ok { grid-area: 2 / 2; border-color: #4bb8e5; background: linear-gradient(180deg, #197bb1, #11618f); font-weight: 750; }
.dpad-right { grid-area: 2 / 3; }
.dpad-down { grid-area: 3 / 2; }

.volume-row { grid-template-columns: repeat(3, 1fr); }

.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 1px 1px 9px; }
.section-heading label { color: #e7f2ff; font-size: 1rem; font-weight: 700; }

.live-badge {
  min-width: 52px;
  border: 1px solid rgba(85, 227, 157, 0.35);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--success);
  background: rgba(85, 227, 157, 0.08);
  font-size: 0.76rem;
  line-height: 1;
  text-align: center;
}

.live-badge.sending { border-color: rgba(85, 214, 255, 0.38); color: var(--accent); background: rgba(85, 214, 255, 0.08); }
.live-badge.error { border-color: rgba(255, 140, 159, 0.45); color: var(--danger); background: rgba(255, 140, 159, 0.08); }

.text-row { display: flex; gap: 8px; }

input {
  min-width: 0;
  min-height: 50px;
  flex: 1;
  border: 1px solid #44617f;
  border-radius: 14px;
  padding: 12px 14px;
  color: #f8fbff;
  background: #0d1d30;
  caret-color: var(--accent);
}

input::placeholder { color: #7890aa; }

.clear-button { width: 50px; min-height: 50px; padding: 0; color: #adc0d5; font-size: 1.45rem; box-shadow: none; }

.input-help { margin: 7px 2px 10px; color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.key-row { grid-template-columns: 1.2fr 1fr 1fr; }
.accent-button { border-color: #3e9ed0; color: #e9f8ff; background: #145e89; }

.power-row { grid-template-columns: 1.35fr 1fr; margin-top: 13px; }
.wake-button { border-color: #397ca5; background: linear-gradient(180deg, #1d5d80, #174663); }
.danger-button { border-color: #744456; color: #ffdce3; background: linear-gradient(180deg, #542b3b, #3c202d); }

.more-controls { padding: 0; overflow: hidden; }
.more-controls summary { min-height: 48px; display: flex; align-items: center; padding: 0 14px; color: #c5d6e8; cursor: pointer; list-style: none; user-select: none; }
.more-controls summary::-webkit-details-marker { display: none; }
.more-controls summary::after { margin-left: auto; content: "+"; color: var(--accent); font-size: 1.25rem; }
.more-controls[open] summary::after { content: "−"; }
.more-grid { grid-template-columns: repeat(3, 1fr); padding: 0 12px 12px; }

@media (max-width: 420px) {
  .remote-shell { padding-inline: 10px; }
  .trackpad { min-height: clamp(220px, 33dvh, 320px); border-radius: 24px; }
  button { padding-inline: 9px; font-size: 0.92rem; }
  .quick-row { gap: 6px; }
  .quick-row button { font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
