:root {
  --bg: #0b0b0d;
  --bg-soft: #121215;
  --card: rgba(255, 255, 255, 0.045);
  --card-strong: rgba(255, 255, 255, 0.075);
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #f2f2f4;
  --muted: #8c8c95;
  --accent: #ff9a4d;
  --accent-soft: rgba(255, 154, 77, 0.16);
  --danger: #ff5d5d;
  --radius: 16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "MiSans", "PingFang SC",
    "Noto Sans SC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

body {
  background:
    radial-gradient(120% 80% at 0% -10%, rgba(255, 154, 77, 0.12), transparent 55%),
    radial-gradient(90% 60% at 110% 10%, rgba(90, 120, 255, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; }
.hide, [hidden] { display: none !important; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 22px 24px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.brand-mark {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(255, 154, 77, .22), rgba(255, 154, 77, .04));
  border: 1px solid rgba(255, 154, 77, .35);
  margin-bottom: 16px;
}
.brand-mark svg { width: 30px; height: 30px; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; margin: 0; }
.brand-mark.small svg { width: 21px; height: 21px; }

.login-card h1 { margin: 0 0 6px; font-size: 21px; letter-spacing: .3px; }
.sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }

label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
input {
  width: 100%; margin-top: 7px;
  height: 46px; padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .18s, background .18s;
}
input:focus { border-color: rgba(255, 154, 77, .6); background: rgba(255, 255, 255, .07); }
input::placeholder { color: #6d6d76; }

.btn {
  border: 1px solid transparent;
  border-radius: 13px;
  height: 44px;
  padding: 0 18px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: .2px;
  transition: transform .12s, filter .18s, background .18s;
}
.btn:active { transform: scale(.97); }
.btn.primary { width: 100%; margin-top: 6px; background: var(--accent); color: #1a1207; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: rgba(255, 255, 255, .06); border-color: var(--stroke); color: var(--text); height: 38px; font-size: 13px; }
.btn.ghost:hover { background: rgba(255, 255, 255, .1); }
.btn.wide { width: 100%; margin-top: 14px; }
.err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin: 10px 0 0; }

/* ---------- app shell ---------- */
.app { max-width: 780px; margin: 0 auto; padding: 0 14px calc(28px + env(safe-area-inset-bottom)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 16px 2px 12px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, rgba(11,11,13,.92), rgba(11,11,13,.72) 70%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: .4px; }
.whoami { font-size: 11.5px; color: var(--muted); }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { transform: scale(.95); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 6px 0 18px; }
.stat {
  padding: 14px 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--stroke);
}
.stat b { display: block; font-size: 19px; letter-spacing: .2px; margin-bottom: 3px; }
.stat span { color: var(--muted); font-size: 11.5px; }

/* ---------- sections ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 10px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.device-list { display: flex; flex-direction: column; gap: 10px; }
.device-card {
  padding: 15px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--stroke);
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 12px;
  align-items: center;
}
.device-ico {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent-soft);
  display: grid; place-items: center;
}
.device-ico svg { width: 21px; height: 21px; }
.device-name { font-size: 14.5px; font-weight: 600; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; }
.pill { font-size: 10.5px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--stroke); color: var(--muted); font-weight: 500; }
.pill.on { color: #6ee7a8; border-color: rgba(110, 231, 168, .35); background: rgba(110, 231, 168, .1); }
.pill.off { color: #ff9b9b; border-color: rgba(255, 120, 120, .35); background: rgba(255, 120, 120, .1); }
.device-sub { color: var(--muted); font-size: 11.5px; line-height: 1.55; }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch i {
  display: block; width: 48px; height: 28px; border-radius: 999px;
  background: rgba(255, 255, 255, .12); border: 1px solid var(--stroke);
  transition: background .18s;
  position: relative;
}
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #d8d8dd; transition: transform .18s, background .18s;
}
.switch input:checked + i { background: var(--accent); border-color: transparent; }
.switch input:checked + i::after { transform: translateX(20px); background: #1a1207; }

.device-actions { display: flex; gap: 8px; margin-top: 10px; grid-column: 1 / -1; }

/* ---------- device detail ---------- */
.back {
  margin: 4px 0 12px; background: none; border: none; color: var(--muted);
  font-size: 13px; padding: 6px 2px;
}
.device-hero {
  padding: 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--stroke);
  margin-bottom: 14px;
}
.hero-top { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; }
.hero-title { font-size: 16px; font-weight: 600; }
.hero-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.meta-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px; }
.meta-item { font-size: 11.5px; color: var(--muted); }
.meta-item b { display: block; color: var(--text); font-size: 13px; font-weight: 500; margin-top: 2px; word-break: break-all; }
.hero-switch { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--stroke); font-size: 13px; }

.album-bar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; scrollbar-width: none; }
.album-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 13px; border-radius: 999px;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--stroke);
  color: var(--muted); font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--accent-soft); border-color: rgba(255, 154, 77, .45); color: var(--text); }

.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 9px; overflow: hidden; background: #1a1a1e; border: 1px solid rgba(255,255,255,.04); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute; right: 5px; bottom: 5px;
  background: rgba(0,0,0,.55); border-radius: 6px; padding: 2px 5px;
  font-size: 10px; color: #ddd; display: inline-flex; align-items: center; gap: 3px;
}
.thumb .badge svg { width: 11px; height: 11px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 14px 2px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 360px;
  background: #16161a; border: 1px solid var(--stroke);
  border-radius: 20px; padding: 24px 20px 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,.55);
}
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.code {
  margin: 18px 0 6px; text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 30px; letter-spacing: 6px; color: var(--accent);
  padding: 14px 8px; border-radius: 14px;
  background: rgba(255, 154, 77, .08); border: 1px dashed rgba(255, 154, 77, .4);
}
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 80;
  background: #08080a;
  display: flex; flex-direction: column;
}
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px calc(8px + env(safe-area-inset-top));
  gap: 10px;
  border-bottom: 1px solid var(--stroke);
}
.viewer-meta { font-size: 12px; color: var(--muted); line-height: 1.5; overflow: hidden; }
.viewer-meta b { color: var(--text); display: block; font-size: 13px; font-weight: 500; }
.viewer-actions { display: flex; gap: 8px; }
.viewer-body { flex: 1; display: grid; place-items: center; padding: 10px; overflow: auto; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (max-width: 420px) {
  .stats { gap: 7px; }
  .stat b { font-size: 17px; }
  .device-card { grid-template-columns: 38px 1fr auto; padding: 13px; }
}
