:root {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1b2130;
  --line: rgba(255, 255, 255, 0.08);
  --ink: #f4f6fa;
  --dim: #8b93a3;
  --accent: #ff7a2f;
  --ok: #5fd39a;
  --bad: #ff6b6b;
  --r: 20px;
  --gutter: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); color-scheme: dark; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.screen { max-width: 520px; margin: 0 auto; padding: calc(var(--gutter) + env(safe-area-inset-top)) var(--gutter) 110px; }
.center { display: flex; flex-direction: column; justify-content: center; min-height: 100dvh; padding-bottom: 40px; }

h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); margin: 28px 4px 10px; }
.lead { color: var(--dim); margin: 6px 0 24px; }
.small { font-size: 13px; color: var(--dim); }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.status { display: inline-flex; align-items: center; font-size: 13px; color: var(--dim); }
.status i { width: 8px; height: 8px; border-radius: 4px; background: var(--dim); margin-right: 8px; }
.status.on i { background: var(--ok); }
.status.off i { background: var(--bad); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; }
.row + .row { margin-top: 12px; }

.btn {
  display: block; width: 100%; min-height: 52px; border-radius: 16px; background: var(--surface-2);
  border: 1px solid var(--line); font-weight: 500; padding: 0 18px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--ink); color: #0b0d12; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 40px; width: auto; font-size: 14px; border-radius: 12px; }
.btn[disabled] { opacity: 0.45; }

.field {
  width: 100%; min-height: 52px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); padding: 0 16px;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.stack > * + * { margin-top: 10px; }

/* Tabbalk */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: rgba(11, 13, 18, 0.88); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs nav { display: flex; width: 100%; max-width: 520px; }
.tabs button { flex: 1; min-height: 58px; font-size: 12.5px; color: var(--dim); position: relative; }
.tabs button[aria-current="true"] { color: var(--ink); }
.tabs button[aria-current="true"]::after { content: ""; position: absolute; left: 30%; right: 30%; top: 0; height: 2px; background: var(--accent); border-radius: 2px; }

/* Afstandsbediening */
.pad { position: relative; width: 252px; height: 252px; margin: 8px auto 6px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); }
.pad button { position: absolute; width: 84px; height: 84px; color: var(--dim); font-size: 13px; letter-spacing: 0.04em; }
.pad button:active { color: var(--ink); background: var(--surface-2); border-radius: 50%; }
.pad .u { top: 4px; left: 84px; } .pad .d { bottom: 4px; left: 84px; } .pad .l { left: 4px; top: 84px; } .pad .r { right: 4px; top: 84px; }
.pad .ok { top: 84px; left: 84px; border-radius: 50%; background: var(--surface-2); color: var(--ink); font-weight: 600; }
.pad .ok:active { background: var(--ink); color: #0b0d12; }
.pad svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.rowbtns { display: flex; }
.rowbtns > * { flex: 1; }
.rowbtns > * + * { margin-left: 10px; }

.chips { display: flex; flex-wrap: wrap; margin: -4px; }
.chip { margin: 4px; min-height: 44px; padding: 0 16px; border-radius: 22px; background: var(--surface-2); border: 1px solid var(--line); font-size: 15px; }
.chip[aria-pressed="true"] { background: var(--ink); color: #0b0d12; border-color: transparent; }

.appgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.apptile { min-height: 84px; padding: 10px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); text-align: center; overflow: hidden; }
.apptile b { display: block; font-size: 22px; font-weight: 300; margin-bottom: 4px; }
.apptile span { display: block; font-size: 12.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apptile img { width: 40px; height: 40px; border-radius: 10px; display: block; margin: 0 auto 4px; object-fit: cover; }

.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 3px; border: 1px solid var(--line); }
.seg button { flex: 1; min-height: 40px; border-radius: 11px; font-size: 14px; color: var(--dim); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #0b0d12; font-weight: 600; }

.swatches { display: flex; flex-wrap: wrap; }
.sw { width: 44px; height: 44px; border-radius: 50%; margin: 4px 10px 4px 0; border: 2px solid transparent; outline: 1px solid var(--line); }
.sw[aria-pressed="true"] { border-color: var(--bg); outline: 2px solid var(--ink); }

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: var(--surface-2); border: 2px solid transparent; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb[aria-pressed="true"] { border-color: var(--accent); }
.thumb .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 14px; background: rgba(0, 0, 0, 0.6); font-size: 16px; line-height: 28px; }

input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }

.faces { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.face { padding: 14px 10px 10px; border-radius: 18px; background: var(--surface); border: 2px solid transparent; text-align: center; }
.face[aria-pressed="true"] { border-color: var(--accent); }
.face .demo { height: 74px; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.face .name { font-size: 13px; color: var(--dim); margin-top: 6px; }
.demo.thin { font-size: 40px; font-weight: 100; letter-spacing: -0.02em; }
.demo.bold { font-size: 38px; font-weight: 700; letter-spacing: -0.03em; }
.demo.minimal { font-size: 22px; font-weight: 300; letter-spacing: 0.3em; }
.demo.none { font-size: 14px; color: var(--dim); }
.demo svg { width: 70px; height: 70px; }

.switch { position: relative; width: 52px; height: 32px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px; background: var(--dim); transition: transform 0.16s; }
.switch[aria-checked="true"] { background: var(--ok); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: #0b0d12; }

.applist { list-style: none; }
.appitem { padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 8px; }
.appitem .top2 { display: flex; align-items: center; }
.appitem .acts { display: flex; flex-wrap: wrap; margin: 8px 0 0 52px; }
.act { min-height: 36px; padding: 0 14px; margin: 0 8px 4px 0; border-radius: 18px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13.5px; color: var(--ink); }
.appitem.hidden-app { opacity: 0.5; }
.appitem .nm { flex: 1; min-width: 0; margin-left: 12px; }
.appitem .nm b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appitem .nm span { font-size: 12.5px; color: var(--dim); }
.appitem .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; font-size: 18px; }
.appitem .ic img { width: 100%; height: 100%; object-fit: cover; }
.mini { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); margin-left: 6px; font-size: 16px; }
.mini[disabled] { opacity: 0.3; }
.divider { text-align: center; font-size: 12px; color: var(--accent); letter-spacing: 0.08em; text-transform: uppercase; margin: 14px 0 10px; }

.pin { display: flex; justify-content: center; margin: 4px 0 16px; }
.pin i { width: 14px; height: 14px; border-radius: 7px; border: 2px solid var(--dim); margin: 0 8px; }
.pin i.on { background: var(--ink); border-color: var(--ink); }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keys button { min-height: 62px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); font-size: 24px; }
.keys button:active { background: var(--surface-2); }
.keys .blank { visibility: hidden; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin-top: 12px; text-align: center; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 16px; background: var(--ink); color: #0b0d12; font-size: 14.5px; z-index: 5; }
.toast.bad { background: var(--bad); color: #fff; }

.logbox { margin-top: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.5; word-break: break-word; }
.logbox div + div { margin-top: 6px; }
