:root {
  --bg: #050507;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-strong: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.10);
  --text: #f5f5f7;
  --muted: #9a9aa2;
  --faint: #5a5a60;
  --accent: #0a84ff;
  --ok: #30d158;
  --warn: #ff9f0a;
  --bad: #ff453a;
  --radius: 20px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, #1b1b24 0%, var(--bg) 60%) fixed;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
}

/* ---------- login ---------- */
body.login { display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); padding: 36px 32px 24px; text-align: center; }
.login-card h1 { margin: 14px 0 2px; font-size: 26px; letter-spacing: 0.04em; }
.login-card label { display: block; text-align: left; margin-top: 16px; font-size: 13px; color: var(--muted); }
.login-card input { margin-top: 6px; }
.login-card .btn { margin-top: 22px; }
.login-card .foot { margin-top: 26px; font-size: 12px; color: var(--faint); }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 18px;
  display: grid; place-items: center; font-weight: 800; font-size: 30px;
  background: linear-gradient(145deg, #fff, #9a9aa2); color: #000;
}
.alert { margin-top: 16px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 69, 58, .15); color: #ff8a80; font-size: 14px; }

/* ---------- form controls ---------- */
input, select, textarea {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border);
  background: rgba(0, 0, 0, .35); color: var(--text); font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10, 132, 255, .25); }
textarea { resize: vertical; min-height: 150px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--glass-strong); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .08s, background .15s;
}
.btn:hover { background: rgba(255, 255, 255, .18); }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); border-color: transparent; }
.btn.danger { background: rgba(255, 69, 58, .18); color: #ff8a80; }
.btn.wide { width: 100%; padding: 13px; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 12px; z-index: 10; margin: 12px auto 0; width: min(1240px, calc(100% - 32px));
  display: flex; align-items: center; gap: 14px; padding: 10px 14px 10px 18px;
}
.topbar .title { font-weight: 700; letter-spacing: .02em; }
.topbar .title span { color: var(--muted); font-weight: 400; margin-left: 6px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: rgba(0, 0, 0, .35); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.off { background: var(--bad); }
.spacer { flex: 1; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: rgba(0, 0, 0, .3); }
.tabs button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 10px; cursor: pointer; }
.tabs button.active { background: var(--glass-strong); color: var(--text); }
main { width: min(1240px, calc(100% - 32px)); margin: 20px auto 40px; }
.view { display: none; }
.view.active { display: block; }
.grid { display: grid; gap: 18px; grid-template-columns: 1.35fr 1fr; }
.col { display: grid; gap: 18px; align-content: start; }
.card { padding: 20px; }
.card h2 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; }
.row > .btn, .row > .fit { flex: 0 0 auto; }
.stack { display: grid; gap: 12px; }

/* ---------- live screen ---------- */
.screen { position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #000; border: 1px solid var(--border); }
.screen img { width: 100%; height: 100%; object-fit: cover; display: block; }
.screen .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.screen .badge { position: absolute; top: 10px; left: 10px; padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, .6); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.stat { padding: 10px 12px; border-radius: 12px; background: rgba(0, 0, 0, .3); }
.stat b { display: block; font-size: 15px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- remote ---------- */
.remote { display: grid; grid-template-columns: 1fr auto; gap: 22px; align-items: center; }
.dpad { position: relative; width: 210px; height: 210px; margin: 0 auto; border-radius: 50%; background: rgba(0, 0, 0, .35); border: 1px solid var(--border); }
.dpad button { position: absolute; border: 0; background: none; color: var(--text); font-size: 22px; cursor: pointer; width: 64px; height: 64px; border-radius: 50%; }
.dpad button:hover { background: var(--glass-strong); }
.dpad button:active { background: rgba(255, 255, 255, .25); }
.dpad .up { top: 4px; left: 73px; } .dpad .down { bottom: 4px; left: 73px; }
.dpad .left { left: 4px; top: 73px; } .dpad .right { right: 4px; top: 73px; }
.dpad .ok { top: 60px; left: 60px; width: 90px; height: 90px; background: var(--glass-strong); font-size: 16px; font-weight: 700; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.volume { display: grid; gap: 12px; justify-items: center; min-width: 120px; }
.volume .level { font-size: 34px; font-weight: 200; }
input[type=range] { -webkit-appearance: none; appearance: none; padding: 0; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); border: 0; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 0; }

/* ---------- apps ---------- */
.apps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.app { display: grid; justify-items: center; gap: 8px; padding: 12px 6px; border-radius: 16px; border: 1px solid transparent; background: rgba(0, 0, 0, .25); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.app:hover { border-color: var(--border); background: var(--glass-strong); }
.app i { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; font-style: normal; font-weight: 800; font-size: 20px; color: #fff; }

/* ---------- tables / lists ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.days { display: flex; gap: 4px; }
.days label { flex: 1; text-align: center; padding: 8px 0; border-radius: 9px; background: rgba(0, 0, 0, .35); border: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--accent); border-color: transparent; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 6px; background: rgba(255, 255, 255, .08); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .25s; padding: 12px 18px; border-radius: 14px; background: rgba(30, 30, 34, .95); border: 1px solid var(--border); font-size: 14px; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: max-content; }
footer { text-align: center; color: var(--faint); font-size: 12px; margin: 10px 0 30px; }

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; }
  .tabs { order: 5; width: 100%; overflow-x: auto; }
}
@media (max-width: 520px) {
  .apps { grid-template-columns: repeat(3, 1fr); }
  .remote { grid-template-columns: 1fr; }
  .dpad { width: 190px; height: 190px; }
  .dpad .up, .dpad .down { left: 63px; } .dpad .left, .dpad .right { top: 63px; }
  .dpad .ok { top: 50px; left: 50px; }
}
