:root {
  --bg: #08080d;
  --panel: rgba(20, 20, 30, 0.72);
  --panel-solid: #14141e;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #ececf4;
  --muted: #9a9ab0;
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --good: #34d399;
  --bad: #f87171;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }

#bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(56, 189, 248, 0.12), transparent 60%),
    var(--bg);
}

/* ------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); text-align: center; padding: 40px 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; backdrop-filter: blur(24px);
}
.login-card h1 { margin: 16px 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.logo-mark {
  width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #ec4899); font-weight: 800; font-size: 22px; letter-spacing: -0.04em;
  box-shadow: 0 10px 40px -10px var(--accent);
}
.logo-mark.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: rgba(255,255,255,0.04); color: var(--text);
  padding: 9px 16px; border-radius: 10px; font: 600 14px Inter, sans-serif; text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: rgba(255,255,255,0.08); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: rgba(248,113,113,.35); }
.btn.osu { margin-top: 24px; width: 100%; background: #ff66aa; color: #fff; border: 0; padding: 12px 16px; font-size: 15px; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
  border-right: 1px solid var(--line); background: rgba(10,10,16,.6); backdrop-filter: blur(20px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 500; }
#nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
#nav a:hover { background: rgba(255,255,255,.04); color: var(--text); }
#nav a.active { background: var(--accent-soft); color: var(--text); }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.me img { width: 32px; height: 32px; border-radius: 50%; }
.me .name { font-weight: 600; font-size: 14px; }
.me button { margin-left: auto; }

.content { padding: 32px clamp(16px, 4vw, 48px) 120px; max-width: 1180px; width: 100%; }
.sec { display: none; }
.sec.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { transform: translateY(6px); } to { transform: none; } }
.sec h2 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.02em; }
.sec > .lead { color: var(--muted); margin: 0 0 24px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  backdrop-filter: blur(16px); margin-bottom: 16px;
}
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card > .desc { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

/* ------------------------------------------------ form controls */
.field { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.field .lbl { font-weight: 500; }
.field .hint { color: var(--muted); font-size: 13px; }
.field.col { flex-direction: column; align-items: stretch; }
input[type=text], input[type=number], select, textarea {
  background: rgba(0,0,0,.35); color: var(--text); border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 8px 10px; font: 14px Inter, sans-serif; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { width: 100%; min-height: 140px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
input[type=range] { accent-color: var(--accent); width: 180px; }
input[type=color] { width: 44px; height: 32px; border: 1px solid var(--line-strong); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
.seg { display: inline-flex; background: rgba(0,0,0,.35); border: 1px solid var(--line-strong); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 7px; font: 600 13px Inter, sans-serif; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: relative; z-index: 1; }
.switch span { position: absolute; inset: 0; background: rgba(255,255,255,.14); border-radius: 99px; transition: background .15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.val { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 44px; text-align: right; font-size: 13px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: #fff; }

/* ------------------------------------------------ rows editor */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 12px; align-items: center;
  background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.row-item.off { opacity: .55; }
.row-item.dragging { opacity: .4; }
.row-item.over { border-color: var(--accent); }
.handle { cursor: grab; color: var(--muted); text-align: center; user-select: none; font-size: 18px; }
.row-main { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.row-main input[type=text] { flex: 1 1 180px; }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 99px; background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 60%, white); white-space: nowrap; }
.tag.al { background: rgba(56,189,248,.14); color: #7dd3fc; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { background: none; border: 1px solid var(--line); color: var(--muted); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ------------------------------------------------ TV preview */
.preview {
  position: relative; aspect-ratio: 16/9; border-radius: 16px; overflow: hidden; border: 1px solid var(--line-strong);
  background: #000; margin-bottom: 16px; box-shadow: 0 30px 80px -30px rgba(0,0,0,.8);
  container-type: inline-size;
}
.pv-bg { position: absolute; inset: 0; background-size: cover; background-position: center; transition: opacity .4s; }
.pv-bg.blur { filter: blur(18px) saturate(1.2); transform: scale(1.1); }
.pv-dim { position: absolute; inset: 0; }
.pv-ui { position: absolute; inset: 0; padding: 3.5cqw 4cqw; display: flex; flex-direction: column; }
.pv-nav { display: flex; gap: 2.2cqw; font-size: 1.5cqw; font-weight: 600; color: rgba(255,255,255,.7); align-items: center; }
.pv-nav b { color: #fff; }
.pv-nav .pill { padding: .5cqw 1.4cqw; border-radius: 99px; background: rgba(255,255,255,.12); }
.pv-nav .pv-name { margin-right: auto; color: #fff; font-weight: 800; }
.pv-hero { margin-top: auto; max-width: 52%; }
.pv-hero h4 { margin: 0; font-size: 3.6cqw; line-height: 1.05; letter-spacing: -.02em; }
.pv-hero p { margin: .8cqw 0 1.4cqw; font-size: 1.25cqw; color: rgba(255,255,255,.75); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pv-btn { display: inline-block; padding: .8cqw 2cqw; border-radius: .8cqw; font-size: 1.3cqw; font-weight: 700; background: #fff; color: #000; }
.pv-rows { margin-top: 2.4cqw; display: flex; flex-direction: column; gap: 1.4cqw; }
.pv-row h5 { margin: 0 0 .7cqw; font-size: 1.4cqw; color: rgba(255,255,255,.85); }
.pv-cards { display: flex; gap: 1cqw; overflow: hidden; }
.pv-card { flex: none; border-radius: .7cqw; background: #222 center/cover; }
.pv-card.focus { outline: .3cqw solid #fff; outline-offset: .2cqw; }

/* ------------------------------------------------ devices / connections */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,.25); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 10px var(--good); }
.pair-input { font: 700 26px/1 ui-monospace, Menlo, monospace !important; letter-spacing: .3em; text-transform: uppercase; width: 220px; text-align: center; padding: 12px !important; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line-strong); }
.al-user { display: flex; align-items: center; gap: 14px; }
.al-user img { width: 52px; height: 52px; border-radius: 12px; }
.stat { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }

/* ------------------------------------------------ save bar / toast */
.savebar {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%); display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 18px; background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 14px;
  box-shadow: 0 20px 60px -10px rgba(0,0,0,.7); transition: transform .25s cubic-bezier(.2,.9,.3,1.2); z-index: 10;
  max-width: calc(100vw - 32px);
}
.savebar.show { transform: translate(-50%, 0); }
.savebar span { font-weight: 600; margin-right: 8px; white-space: nowrap; }
.toast {
  position: fixed; top: 20px; right: 20px; padding: 10px 16px; border-radius: 10px; background: var(--panel-solid);
  border: 1px solid var(--line-strong); opacity: 0; transform: translateY(-10px); transition: all .2s; z-index: 20; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: var(--bad); }

/* ------------------------------------------------ tablet / phone */
@media (max-width: 1024px) and (min-width: 821px) {
  .shell { grid-template-columns: 200px 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  /* Slim sticky header: brand + account */
  .side {
    position: sticky; top: 0; height: auto; z-index: 6; flex-direction: row; align-items: center;
    padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line);
    padding-top: max(10px, env(safe-area-inset-top));
    /* backdrop-filter would make the fixed bottom nav position relative to this header */
    backdrop-filter: none; background: rgba(10,10,16,.96);
  }
  .brand { padding: 0; }
  .brand span { font-size: 15px; }
  .me { margin: 0 0 0 auto; border: 0; padding: 0; }
  .me .name, .me .tiny { display: none; }
  /* Bottom tab bar */
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; flex-direction: row; gap: 0;
    overflow-x: auto; scrollbar-width: none; background: rgba(12,12,18,.92); backdrop-filter: blur(20px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  #nav::-webkit-scrollbar { display: none; }
  #nav a { flex: 1 0 auto; min-width: 72px; flex-direction: column; gap: 2px; padding: 6px 6px; font-size: 11px; border-radius: 10px; white-space: nowrap; }
  #nav a i { font-size: 18px; width: auto; }
  .content { padding: 20px 16px 140px; }
  .sec h2 { font-size: 22px; }
  .card { padding: 16px; }
  .field { flex-wrap: wrap; gap: 10px; }
  .field > :last-child { margin-left: auto; }
  input[type=range] { width: 150px; }
  .seg button { padding: 6px 10px; }
  /* Row editor: controls wrap below the title */
  .row-item { grid-template-columns: 22px 1fr; row-gap: 8px; }
  .row-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .row-main input[type=text] { flex-basis: 100%; }
  .pair-input { width: 100%; }
  .list-item { flex-wrap: wrap; }
  .savebar { bottom: calc(76px + env(safe-area-inset-bottom)); left: 16px; right: 16px; transform: translateY(220%); max-width: none; }
  .savebar.show { transform: none; }
  .savebar span { flex: 1; }
  .toast { left: 16px; right: 16px; top: 12px; text-align: center; }
}

/* ------------------------------------------------ password login */
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; text-align: left; }
.login-form input { width: 100%; padding: 12px 14px; font-size: 15px; border-radius: 11px; }
.login-form .btn { padding: 12px; font-size: 15px; margin-top: 4px; }
#login-note.err { color: var(--bad); }
.avatar-letter { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: linear-gradient(135deg, var(--accent), #ec4899); flex: none; }
