:root {
  --bg: #0b1220;
  --elev: #121b2e;
  --elev2: #1a2540;
  --line: #24304a;
  --gold: #e8c87a;
  --text: #f2f5fa;
  --muted: #93a1ba;
  --accent: #4fd1a5;
  --danger: #f07b7b;
  --radius: 14px;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: env(safe-area-inset-top) 16px calc(88px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.55;
}

main { max-width: 640px; margin: 0 auto; }

h1 { font-size: 1.5rem; margin: 20px 0 4px; color: var(--gold); }
h2 { font-size: 1.1rem; margin: 22px 0 10px; color: var(--gold); }
.sub { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }

.card {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  min-height: 46px;
  cursor: pointer;
  background: var(--gold);
  color: #1a1408;
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--danger); border: 1px solid #4a2a33; }
button.small { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
button:disabled { opacity: .5; }
.wide { width: 100%; margin-top: 14px; }

.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > .fit { flex: 0 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 38px;
  font-weight: 400;
}
.chip[aria-pressed="true"] { background: var(--elev2); color: var(--gold); border-color: var(--gold); }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; background: transparent; color: var(--muted); min-height: 38px; font-weight: 400; }
.seg button[aria-pressed="true"] { background: var(--elev2); color: var(--gold); }

.child-head { display: flex; justify-content: space-between; align-items: baseline; }
.child-head h3 { margin: 0; color: var(--accent); font-size: 1.1rem; }
.count { color: var(--muted); font-size: .85rem; }

.task {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.task:first-of-type { border-top: 0; }
.task .body { flex: 1; min-width: 0; }
.task .title { overflow-wrap: anywhere; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .when { color: var(--muted); font-size: .8rem; }
.task .off { opacity: .55; }

.check {
  width: 30px; height: 30px; min-height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  border: 2px solid var(--muted);
  background: transparent;
  padding: 0;
  color: var(--bg);
  font-size: 18px;
  line-height: 1;
}
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }

.del { background: none; color: var(--muted); min-height: 36px; padding: 4px 8px; font-weight: 400; }

.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

.list-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.badge { font-size: .75rem; color: var(--gold); border: 1px solid var(--gold); border-radius: 999px; padding: 1px 8px; margin-inline-start: 6px; }

nav.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  background: rgba(11, 18, 32, .96);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  backdrop-filter: blur(8px);
}
nav.tabs button {
  flex: 1;
  background: none;
  color: var(--muted);
  font-weight: 400;
  font-size: .85rem;
  min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
nav.tabs button .ic { font-size: 1.25rem; line-height: 1; }
nav.tabs button[aria-current="page"] { color: var(--gold); }

.login { max-width: 380px; margin: 12vh auto 0; }
.logo { font-size: 3rem; text-align: center; color: var(--gold); line-height: 1; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.4em; margin-top: 8px; }

#toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 420px;
  background: var(--elev2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

.center { text-align: center; }
.mt0 { margin-top: 0; }
.mt10 { margin-top: 10px; }
.ltr-r { text-align: right; }

/* ---------- home ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: start; background: var(--elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; color: var(--text); font-weight: 400; min-height: 118px;
}
.tile.soon { opacity: .5; }
.tile-ic { font-size: 1.6rem; line-height: 1.2; }
.tile-name { font-weight: 600; }
.tile-room { color: var(--muted); font-size: .8rem; min-height: 1.2em; }
.dot { font-size: .75rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #5b667c; }
.dot.on { color: var(--accent); }
.dot.on::before { background: var(--accent); box-shadow: 0 0 0 3px rgba(79, 209, 165, .18); }
.dot.small { margin-inline-start: 8px; }
.summary { display: block; width: 100%; text-align: start; color: var(--text); font-weight: 400; }
.sum-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.sum-name { flex: 0 0 30%; overflow-wrap: anywhere; }
.bar { flex: 1; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.w0 { width: 0%; }
.w10 { width: 10%; }
.w20 { width: 20%; }
.w30 { width: 30%; }
.w40 { width: 40%; }
.w50 { width: 50%; }
.w60 { width: 60%; }
.w70 { width: 70%; }
.w80 { width: 80%; }
.w90 { width: 90%; }
.w100 { width: 100%; }

/* ---------- remote ---------- */
.remote { padding-bottom: 8px; }
.remote-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 10px; }
.remote-head h1 { margin: 0; }
.remote-head select { max-width: 60%; }
.dpad {
  position: relative; width: min(78vw, 290px); aspect-ratio: 1; margin: 18px auto 14px;
  border-radius: 50%; background: radial-gradient(circle at 50% 40%, #1b2742, var(--elev));
  border: 1px solid var(--line);
  display: grid; grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.d { background: transparent; color: var(--muted); font-size: 1.3rem; border-radius: 50%; min-height: 0; padding: 0; font-weight: 400; }
.d:active { color: var(--gold); background: rgba(232, 200, 122, .08); }
.d.up { grid-area: 1 / 2; } .d.left { grid-area: 2 / 1; } .d.right { grid-area: 2 / 3; } .d.down { grid-area: 3 / 2; }
.d.ok {
  grid-area: 2 / 2; margin: 10%; background: var(--elev2); color: var(--gold);
  border: 1px solid var(--gold); font-weight: 700; font-size: 1.05rem;
}
.d.ok:active { background: var(--gold); color: #1a1408; }
.pill-row { display: flex; gap: 8px; justify-content: center; margin: 10px 0; }
.pill { flex: 1; max-width: 140px; background: var(--elev); color: var(--text); border: 1px solid var(--line); border-radius: 999px; font-weight: 400; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.pill:active { border-color: var(--gold); color: var(--gold); }
.side { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 12px 4px; }
.rocker { display: flex; flex-direction: column; align-items: center; background: var(--elev); border: 1px solid var(--line); border-radius: 999px; padding: 4px; width: 70px; }
.rk { background: transparent; color: var(--text); font-size: 1.5rem; width: 100%; min-height: 56px; border-radius: 999px; font-weight: 400; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.rk:active { color: var(--gold); background: rgba(232, 200, 122, .08); }
.rk-label { font-size: .7rem; color: var(--muted); }
.mid-col { display: flex; flex-direction: column; gap: 12px; }
.round { width: 64px; height: 64px; min-height: 64px; border-radius: 50%; padding: 0; background: var(--elev); border: 1px solid var(--line); color: var(--text); font-size: 1.3rem; }
.round:active { border-color: var(--gold); }
.typing { margin: 14px 0; }
.apps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.app { background: var(--elev); color: var(--text); border: 1px solid var(--line); font-weight: 400; font-size: .85rem; min-height: 54px; overflow-wrap: anywhere; }
.app:active { border-color: var(--gold); }
.token { margin-top: 12px; display: grid; gap: 6px; }
.token code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow-wrap: anywhere; font-size: .8rem; }
section h2 { margin-top: 26px; }

/* ---------- alerts ---------- */
.bell { background: none; min-height: 36px; padding: 4px 6px; font-size: 1.05rem; filter: grayscale(1); opacity: .7; }
.bell.ringing { filter: none; opacity: 1; }
.alert-card { border-color: var(--gold); background: linear-gradient(180deg, #2a2412, var(--elev)); }

textarea { resize: vertical; min-height: 64px; line-height: 1.6; }
