:root {
  --bg: #0d0f14;
  --surface: #171a22;
  --surface-2: #20242f;
  --border: #2a2f3c;
  --text: #eef1f7;
  --muted: #8b93a7;
  --accent: #7c8cff;
  --accent-text: #0d0f14;
  --hbo: #6d3cf5;
  --ok: #3ddc97;
  --warn: #f5b041;
  --danger: #ff5d6c;
  --radius: 18px;
  --tap: 56px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  user-select: none; -webkit-user-select: none;
}
[hidden] { display: none !important; }
.screen { max-width: 440px; margin: 0 auto; }
.muted { color: var(--muted); }
h1 { margin: 8px 0 4px; font-size: 26px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 24px 4px 10px; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; min-height: var(--tap); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .06s ease, background .15s ease;
}
button:active { transform: scale(.95); background: var(--surface-2); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; padding: 0 20px; }
button.danger { color: var(--danger); }
button.busy { opacity: .55; }

/* --- auth --- */
#auth { display: grid; place-items: center; min-height: 80dvh; }
.auth-card { width: 100%; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 32px 24px; }
.auth-card button { width: 100%; margin-top: 16px; }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; color: var(--accent); }
.logo svg { width: 36px; height: 36px; }
.field { display: block; text-align: left; margin-top: 16px; }
.field span { font-size: 13px; color: var(--muted); }
input {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-top: 6px; user-select: text; -webkit-user-select: text;
}
.error { color: var(--danger); min-height: 1.4em; margin: 12px 0 0; }

/* --- status --- */
.status { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.off { background: var(--danger); }
.status-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.status-text strong, .status-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-text span { font-size: 13px; }
.icon-btn { min-height: 40px; width: 40px; background: transparent; border: none; color: var(--muted); }

.hbo {
  width: 100%; margin-top: 14px; min-height: 64px; font-size: 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--hbo), #9a5bff); border: none; color: #fff;
}

/* --- d-pad --- */
.dpad {
  margin: 20px auto 6px; width: min(300px, 82vw); aspect-ratio: 1; position: relative;
  border-radius: 50%; background: var(--surface); border: 1px solid var(--border);
}
.d { position: absolute; border: none; background: transparent; border-radius: 50%; }
.d svg { width: 30px; height: 30px; }
.d.up { top: 4%; left: 33%; width: 34%; height: 30%; }
.d.down { bottom: 4%; left: 33%; width: 34%; height: 30%; }
.d.left { left: 4%; top: 33%; width: 30%; height: 34%; }
.d.right { right: 4%; top: 33%; width: 30%; height: 34%; }
.d.ok { left: 32%; top: 32%; width: 36%; height: 36%; background: var(--surface-2); border: 1px solid var(--border); font-weight: 700; font-size: 18px; }
.d:active { background: var(--surface-2); }

.row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; margin-top: 12px; }
.volume { height: 4px; background: var(--surface-2); border-radius: 2px; margin: 10px 4px 0; overflow: hidden; }
#vol-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.apps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.apps button { min-height: 64px; font-size: 14px; font-weight: 600; padding: 0 6px; text-align: center; }
.apps button.current { border-color: var(--accent); color: var(--accent); }

.text-form { display: flex; gap: 10px; }
.text-form input { margin: 0; }
.footer { margin-top: 24px; }

.devices { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px 14px; }
.devices ul { list-style: none; margin: 0 0 12px; padding: 0; }
.devices li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.devices li:last-child { border-bottom: none; }
.devices .dev-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.devices .dev-text span { font-size: 13px; }
.devices .badge { font-size: 11px; color: var(--ok); border: 1px solid var(--ok); border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.devices li button { min-height: 36px; padding: 0 12px; font-size: 14px; }
#add-device { width: 100%; }
.enroll-box { margin-top: 12px; }
.enroll-box input { font-size: 13px; }

.install { width: 100%; margin-top: 12px; color: var(--accent); border-style: dashed; }

.sheet {
  width: min(400px, calc(100vw - 32px)); background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px; padding: 24px;
}
.sheet::backdrop { background: rgb(0 0 0 / .6); }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
.sheet ol { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 10px; }
.sheet button { width: 100%; margin-top: 8px; }
svg.inline { width: 18px; height: 18px; vertical-align: -3px; color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 12px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--danger); color: var(--danger); }
