:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b2740;
  --line: #24314c;
  --text: #eaf0fb;
  --muted: #8b9ab5;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --on: #34d399;
  --on-soft: rgba(52, 211, 153, 0.16);
  --star: #fbbf24;
  --danger: #f87171;
  --radius: 18px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef2f9;
    --line: #dfe5f0;
    --text: #121a2b;
    --muted: #64748b;
    --accent: #0284c7;
    --accent-soft: rgba(2, 132, 199, 0.12);
    --on: #059669;
    --on-soft: rgba(5, 150, 105, 0.12);
    --star: #d97706;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.45; cursor: default; }
input { font: inherit; color: inherit; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar { display: flex; align-items: flex-start; gap: 12px; padding: 8px 4px 16px; }
.title h1 { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }
.clock { margin-left: auto; text-align: right; }
.clock-time { font-size: 23px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.05; }
.clock-date { color: var(--muted); font-size: 11px; margin-top: 3px; white-space: nowrap; }
.status { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.ok::before { background: var(--on); }
.status.bad::before { background: var(--danger); }

.banner { background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.3); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }

.icon-btn { position: relative; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.hero { display: flex; align-items: center; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.power { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); flex: none; transition: background 0.2s, border-color 0.2s; }
.power svg { width: 28px; height: 28px; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; }
.power.on { background: var(--on-soft); border-color: var(--on); }
.power.on svg { stroke: var(--on); }
.power.busy svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.power:active { transform: scale(0.95); }
.now { flex: 1; min-width: 0; }
.now-label { color: var(--muted); font-size: 13px; }
.now-name { font-size: 19px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.remote { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0 18px; }
.remote button { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 0; font-size: 14px; font-weight: 500; }
.remote button:active { background: var(--accent-soft); }

.tabs { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tab { flex: 1; padding: 8px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--surface-2); color: var(--text); }

.tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.tools input[type="search"] { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; }
.tools input[type="search"]:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; white-space: nowrap; }

.list { list-style: none; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ch { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px 6px 4px 4px; }
.ch.playing { border-color: var(--accent); background: var(--accent-soft); }
.ch-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px 6px; text-align: left; }
.ch-num { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; width: 38px; flex: none; text-align: right; }
.ch-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.badge { font-size: 10px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 4px; flex: none; }
.star, .mini { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); flex: none; font-size: 18px; }
.star.on { color: var(--star); }
.mini { font-size: 14px; width: 28px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 15px; }
.more { color: var(--muted); text-align: center; font-size: 13px; padding: 8px; }

.footer { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 24px 0 8px; }
.who { color: var(--muted); font-size: 12px; }
.link { color: var(--accent); font-size: 14px; padding: 6px; }
.link.danger { color: var(--danger); }

.primary { background: var(--accent); color: #fff; font-weight: 600; border-radius: 12px; padding: 12px 16px; width: 100%; }
.form-error { color: var(--danger); font-size: 14px; }
.hint { color: var(--muted); font-size: 14px; }

.sheet { margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88dvh; border: 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text); padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.sheet-head h2 { font-size: 21px; }
.sheet-head p { color: var(--muted); font-size: 13px; }
.sched-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.sched-item { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border-radius: 14px; padding: 12px; }
.sched-item.off { opacity: 0.55; }
.sched-info { flex: 1; min-width: 0; }
.sched-info b { font-size: 18px; font-variant-numeric: tabular-nums; }
.sched-info span { display: block; color: var(--muted); font-size: 13px; }
.sched-info .err { color: var(--danger); }
.sched-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.switch { width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch.on { background: var(--on); }
.switch.on::after { transform: translateX(18px); }
.sched-form { display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.field input[type="time"] { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 18px; }
.days, .modes { display: flex; gap: 6px; }
.day, .mode { flex: 1; padding: 9px 0; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; }
.day.active, .mode.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.device-item { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 14px; padding: 12px; }
.device-item div { flex: 1; }
.device-item span { display: block; color: var(--muted); font-size: 13px; }
.invite-code { font-size: 30px; font-weight: 700; letter-spacing: 0.12em; text-align: center; padding: 8px; font-variant-numeric: tabular-nums; }

.gate { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.gate-card h1 { font-size: 32px; }
.gate-card p { color: var(--muted); }
.gate-card label { display: block; color: var(--muted); font-size: 13px; text-align: left; margin-bottom: 6px; }
.gate-card input { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 20px; letter-spacing: 0.15em; text-align: center; margin-bottom: 10px; }
.gate-diag { font-size: 11px; }
.url-box { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; user-select: all; -webkit-user-select: all; }
a.mode { text-align: center; text-decoration: none; color: inherit; }
