:root {
  color-scheme: light;
  --ink: #172126;
  --muted: #68777d;
  --canvas: #f4f7f8;
  --panel: #ffffff;
  --soft: #edf2f3;
  --line: #dce5e7;
  --accent: #0f766e;
  --accent-dark: #0b5e58;
  --accent-soft: #dff3f0;
  --danger: #a33b32;
  --danger-soft: #fde8e5;
  --shadow: 0 8px 28px rgba(23, 43, 50, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100dvh; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
[hidden] { display: none !important; }

.app-shell { min-height: 100dvh; }
.view { width: min(100%, 960px); min-height: 100dvh; margin: 0 auto; }
.view:not([hidden]) { animation: view-enter .18s ease both; }
@keyframes view-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.login-view {
  display: grid;
  align-content: center;
  gap: 28px;
  padding: max(44px, env(safe-area-inset-top)) 24px max(32px, env(safe-area-inset-bottom));
  color: white;
  background: linear-gradient(145deg, #0f766e, #124e5a);
}
.brand-block { width: min(100%, 420px); margin: 0 auto; }
.brand-mark { display: block; width: 52px; height: 52px; border-radius: 16px; object-fit: cover; box-shadow: 0 8px 24px rgba(3,34,39,.24); }
.brand-block h1 { margin: 18px 0 6px; font-size: 28px; line-height: 36px; letter-spacing: -.5px; }
.brand-block p { margin: 0; color: rgba(255,255,255,.78); }
.restoring-spinner { display: block; width: 22px; height: 22px; margin-top: 24px; border: 3px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: restoring-spin .8s linear infinite; }
@keyframes restoring-spin { to { transform: rotate(360deg); } }
.service-status { display: inline-flex; margin-top: 16px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.12); font-size: 12px; font-weight: 700; }
.login-card, .surface { display: grid; width: min(100%, 420px); margin: 0 auto; padding: 20px; gap: 14px; border-radius: 20px; color: var(--ink); background: var(--panel); box-shadow: 0 18px 45px rgba(4,40,45,.18); }
.login-card label, .form-stack label { color: var(--muted); font-size: 13px; font-weight: 700; }
input, select { width: 100%; height: 52px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #f7f9fa; outline: 0; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.password-field, .field-with-action { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.primary, .secondary, .text-button, .back-button, .icon-button, .drawer-action, .home-switcher, .device-switch { border: 0; }
.primary { min-height: 52px; border-radius: 14px; color: white; background: var(--accent); font-weight: 750; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
.full-button { width: 100%; }
.secondary { min-height: 44px; padding: 0 14px; border-radius: 12px; color: var(--ink); background: var(--soft); font-weight: 700; }
.text-button, .back-button { min-height: 44px; padding: 8px; color: var(--muted); background: transparent; font-weight: 650; }
.icon-button { min-width: 44px; min-height: 44px; border-radius: 12px; color: var(--muted); background: var(--soft); }
.message { min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; line-height: 20px; }
.message.error { color: var(--danger); }
.probe-line { display: flex; justify-content: center; gap: 18px; color: rgba(255,255,255,.75); font-size: 12px; }
.agreement-check { display: flex; align-items: flex-start; gap: 10px; color: var(--muted); font-size: 13px; line-height: 20px; font-weight: 400 !important; }
.agreement-check input { flex: 0 0 20px; width: 20px; height: 20px; margin: 0; padding: 0; accent-color: var(--accent); }
.agreement-check a, .agreement-card a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.agreement-check a:focus-visible, .agreement-card a:focus-visible, .agreement-back:focus-visible { outline: 3px solid rgba(15,118,110,.22); outline-offset: 3px; }

.agreement-page { width: min(100%, 760px); min-height: 100dvh; margin: 0 auto; padding: max(24px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom)); }
.agreement-back { display: inline-flex; min-height: 44px; align-items: center; color: var(--accent); font-weight: 700; text-decoration: none; }
.agreement-card { margin-top: 12px; padding: clamp(22px, 5vw, 40px); border: 1px solid var(--line); border-radius: 20px; background: var(--panel); box-shadow: var(--shadow); }
.agreement-eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 13px; font-weight: 750; }
.agreement-card h1 { margin: 0; font-size: clamp(26px, 5vw, 34px); line-height: 1.3; }
.agreement-meta { margin: 10px 0 24px; color: var(--muted); font-size: 13px; }
.agreement-card section { padding-top: 12px; }
.agreement-card h2 { margin: 20px 0 10px; font-size: 18px; line-height: 1.4; }
.agreement-card p { margin: 0 0 14px; line-height: 1.75; overflow-wrap: anywhere; }
.agreement-alert { margin: 12px 0; padding: 4px 16px 0; border-left: 4px solid var(--danger); border-radius: 0 12px 12px 0; background: #fff7f5; }
.agreement-alert h2 { color: var(--danger); }

.bind-view { padding: max(24px, env(safe-area-inset-top)) 18px max(32px, env(safe-area-inset-bottom)); }
.view-heading { width: min(100%, 560px); margin: 26px auto 18px; }
.view-heading h2 { margin: 0 0 6px; font-size: 26px; }
.view-heading p { margin: 0; color: var(--muted); }
.form-stack { width: min(100%, 560px); box-shadow: var(--shadow); }
.chooser-layer { position: fixed; z-index: 40; inset: 0; width: 100%; background: transparent; }
.chooser-backdrop { position: absolute; inset: 0; background: rgba(10,20,24,.38); }
.chooser-sheet { position: absolute; right: 0; bottom: 0; left: 0; width: min(100%, 560px); margin: 0 auto; padding: 10px 20px max(20px, env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: white; box-shadow: 0 -12px 40px rgba(10,20,24,.18); }
.chooser-sheet .view-heading { margin: 0 0 18px; }

.control-view { padding-bottom: max(28px, env(safe-area-inset-bottom)); }
.home-header { position: sticky; z-index: 10; top: 0; display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; border-bottom: 1px solid #e2e9eb; background: rgba(255,255,255,.94); backdrop-filter: blur(14px); }
.home-switcher { display: flex; min-height: 36px; align-items: center; gap: 6px; padding: 0; color: var(--ink); background: transparent; font-size: 19px; font-weight: 750; }
.connection-status { display: inline-flex; min-height: 28px; align-items: center; margin-top: 4px; padding: 0 10px; border-radius: 999px; color: #087a61; background: #dcf4ec; font-size: 12px; font-weight: 700; }
.connection-status.error { color: var(--danger); background: var(--danger-soft); }
.device-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 18px; padding: 12px; border-radius: 16px; color: #285b58; background: #e5f3f1; }
.device-summary div { display: grid; justify-items: center; gap: 2px; }
.device-summary strong { font-size: 20px; }
.device-summary span { font-size: 12px; }
.room-filters { display: flex; gap: 8px; overflow-x: auto; padding: 0 18px 12px; scrollbar-width: none; }
.room-filters::-webkit-scrollbar { display: none; }
.room-chip { flex: 0 0 auto; min-height: 40px; padding: 0 15px; border: 0; border-radius: 999px; color: #56656b; background: var(--soft); font-weight: 700; }
.room-chip[aria-pressed="true"] { color: white; background: var(--accent); }
.device-grid { display: grid; gap: 10px; padding: 0 14px; }
.device-card { display: grid; grid-template-columns: 44px minmax(0,1fr) 44px 52px; min-height: 96px; align-items: center; gap: 12px; padding: 16px; border: 1px solid #e1e8ea; border-radius: 18px; background: white; box-shadow: var(--shadow); }
.device-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 14px; color: #66777e; background: var(--soft); font-size: 22px; }
.device-card.is-on .device-icon { color: var(--accent); background: var(--accent-soft); }
.device-copy { min-width: 0; }
.device-copy h3 { overflow: hidden; margin: 0; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.device-copy > p:not(.message) { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.device-switch { position: relative; width: 52px; height: 32px; padding: 0; border-radius: 999px; background: #c4ced2; transition: background-color .15s ease; }
.device-switch span { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: white; box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .18s ease; }
.device-switch[aria-checked="true"] { background: var(--accent); }
.device-switch[aria-checked="true"] span { transform: translateX(20px); }
.device-switch[hidden] { display: none; }
.skeleton-card { pointer-events: none; }
.skeleton-block { border-radius: 999px; background: linear-gradient(90deg, #edf2f3, #f7f9fa, #edf2f3); background-size: 200% 100%; animation: skeleton-pulse 1.2s ease infinite; }
.skeleton-icon { width: 44px; height: 44px; border-radius: 14px; }
.skeleton-title { width: 70%; height: 16px; }
.skeleton-line { width: 48%; height: 12px; margin-top: 8px; }
.skeleton-switch { width: 52px; height: 32px; }
@keyframes skeleton-pulse { to { background-position: -200% 0; } }
.empty { padding: 36px 18px; color: var(--muted); text-align: center; }

.drawer-layer { position: fixed; z-index: 50; inset: 0; }
.drawer-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(10,20,24,.38); }
.drawer { position: absolute; right: 0; bottom: 0; left: 0; max-height: 82dvh; overflow: auto; padding: 10px 20px max(20px, env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: white; }
.drawer-handle { width: 42px; height: 4px; margin: 0 auto 14px; border-radius: 999px; background: #ced7da; }
.drawer h2 { margin: 0 0 8px; font-size: 18px; }
.drawer-action { width: 100%; min-height: 52px; padding: 0; border-bottom: 1px solid var(--line); color: var(--ink); background: transparent; text-align: left; font-weight: 700; }
.danger-text { color: var(--danger); }
.debug-panel { padding: 14px 0; border-bottom: 1px solid var(--line); }
.debug-panel summary { min-height: 44px; cursor: pointer; font-weight: 700; }
.events { display: grid; gap: 8px; margin-top: 10px; }
.events details { padding: 8px; border-radius: 10px; background: #f7f9fa; }
pre { max-height: 280px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; }
.file-warning { position: fixed; z-index: 100; inset: 12px 12px auto; padding: 12px; border-radius: 12px; color: #7b461a; background: #fff6ea; }

button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(15,118,110,.22); outline-offset: 2px; }

@media (min-width: 641px) {
  .login-view { border-radius: 0; }
  .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .drawer { left: 50%; width: min(560px, 100%); transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .restoring-spinner { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
