:root {
  color-scheme: dark;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #060b14;
}

* { box-sizing: border-box; }

html,
body,
#xyzwAccountWorkspace,
#xyzwAccountStage {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

body { background: #060b14; }

#xyzwAccountWorkspace,
#xyzwAccountStage {
  position: fixed;
  inset: 0;
}

.empty-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 28px;
  color: #f8fafc;
  background:
    radial-gradient(circle at 50% 28%, rgba(37, 99, 235, .22), transparent 34%),
    linear-gradient(180deg, #0a1220, #050811);
  text-align: center;
}

.empty-stage[hidden] { display: none; }
.empty-stage img { width: 76px; height: 76px; border-radius: 20px; box-shadow: 0 16px 42px rgba(0, 0, 0, .42); }
.empty-stage h1 { margin: 18px 0 8px; font-size: 24px; }
.empty-stage p { max-width: 320px; margin: 0; color: #94a3b8; font-size: 14px; line-height: 1.65; }

.xyzw-account-instance {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.xyzw-account-instance.is-active {
  z-index: 2;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#xyzwPortalLauncher {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: 10px;
  z-index: 2147483647;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  padding: 4px;
  border: 1px solid rgba(148, 163, 184, .42);
  border-radius: 15px;
  color: #f8fafc;
  background: rgba(8, 15, 28, .92);
  box-shadow: 0 10px 32px rgba(0, 0, 0, .38);
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#xyzwPortalLauncher img { width: 34px; height: 34px; border-radius: 10px; }

.launcher-state {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border: 2px solid #08101d;
  border-radius: 50%;
  background: #64748b;
}

.launcher-state.is-authenticated { background: #3b82f6; }
.launcher-state.is-connected { background: #22c55e; }

#xyzwControlPanel {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 66px);
  right: 10px;
  z-index: 2147483647;
  width: min(390px, calc(100vw - 20px));
  max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 82px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(148, 163, 184, .32);
  border-radius: 20px;
  color: #f8fafc;
  background: rgba(7, 13, 24, .97);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .58);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

#xyzwControlPanel[hidden],
#xyzwLoggedInView[hidden],
#xyzwLoggedOutView[hidden],
.tab-panel[hidden],
.panel-tabs button[hidden],
#xyzwWorkspaceNotice[hidden],
.form-error[hidden],
.empty-copy[hidden] { display: none; }

.panel-header,
.panel-brand,
.user-strip,
.section-heading,
.script-heading,
.account-main,
.account-state,
.switch-row {
  display: flex;
  align-items: center;
}

.panel-header {
  position: sticky;
  top: 0;
  z-index: 2;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 7px 9px;
  border-bottom: 1px solid rgba(148, 163, 184, .16);
  background: rgba(7, 13, 24, .96);
  cursor: pointer;
}

.panel-brand { min-width: 0; gap: 8px; }
.panel-brand > img { width: 28px; height: 28px; border-radius: 8px; }
.panel-brand h1 { margin: 0; font-size: 13px; line-height: 1.15; }
.panel-brand p { margin: 2px 0 0; color: #7f8da3; font-size: 9px; line-height: 1.1; }
.panel-logout { flex: 0 0 auto; color: #cbd5e1; background: rgba(148, 163, 184, .1); }
.panel-logout[hidden] { display: none; }

.icon-button,
.text-button,
.primary-button,
.secondary-button,
.account-run,
.panel-tabs button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.icon-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(148, 163, 184, .12);
  font-size: 22px;
}

.icon-button.small { width: 31px; height: 31px; font-size: 18px; }

.auth-view { padding: 22px 18px 20px; }
.auth-intro h2 { margin: 0 0 7px; font-size: 20px; }
.auth-intro p { margin: 0 0 20px; color: #94a3b8; font-size: 13px; line-height: 1.6; }

#xyzwLoginForm,
#xyzwSetupForm { display: grid; gap: 14px; }
#xyzwLoginForm[hidden],
#xyzwSetupForm[hidden] { display: none; }
#xyzwLoginForm label,
#xyzwSetupForm label { display: grid; gap: 7px; color: #cbd5e1; font-size: 12px; font-weight: 700; }
#xyzwSetupForm label small { color: #718096; font-size: 10px; font-weight: 500; line-height: 1.45; }
#xyzwLoginForm input,
#xyzwSetupForm input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #334155;
  border-radius: 11px;
  outline: none;
  color: #f8fafc;
  background: #0e1726;
}
#xyzwLoginForm input:focus,
#xyzwSetupForm input:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 11px;
  font-weight: 800;
}

.primary-button { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.secondary-button { width: 100%; margin-top: 5px; background: #1d4ed8; }
button:disabled { cursor: not-allowed; opacity: .48; }
.form-error { margin: -2px 0 0; color: #fca5a5; font-size: 12px; line-height: 1.5; }

.user-strip { justify-content: space-between; gap: 10px; padding: 9px 12px; }
.user-strip strong { display: block; font-size: 14px; }
.user-strip span { display: block; margin-top: 2px; color: #64748b; font-size: 10px; }
.text-button { padding: 7px 9px; border-radius: 8px; color: #94a3b8; background: transparent; font-size: 11px; }

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  margin: 0 12px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(148, 163, 184, .1);
}

.panel-tabs button { height: 36px; border-radius: 9px; background: transparent; font-size: 13px; font-weight: 800; }
.panel-tabs button[aria-selected="true"] { color: #fff; background: #2563eb; box-shadow: 0 4px 12px rgba(37, 99, 235, .28); }

.tab-panel { padding: 16px 12px 14px; }
.section-heading,
.script-heading { justify-content: space-between; gap: 12px; margin: 0 2px 10px; }
.section-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 6px; }
.account-upload {
  height: 31px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  color: #dbeafe;
  background: rgba(37, 99, 235, .72);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}
.section-heading h2,
.script-heading h2 { margin: 0; font-size: 15px; }
.section-heading p { margin: 4px 0 0; color: #64748b; font-size: 10px; }

.account-list { display: grid; gap: 8px; }
.account-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 14px;
  background: rgba(15, 23, 42, .72);
}
.account-card.is-active { border-color: rgba(59, 130, 246, .65); background: rgba(30, 64, 175, .17); }
.account-main { min-width: 0; gap: 10px; }
.account-avatar {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 50%;
  background: linear-gradient(145deg, #243451, #172033);
  color: #cbd7ea;
  font-size: 17px;
  font-weight: 850;
}
.account-avatar.has-image { color: transparent; }
.account-avatar-image { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.account-copy { min-width: 0; }
.account-name { display: block; overflow: hidden; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.account-server { display: block; margin-top: 3px; color: #7f8da3; font-size: 10px; }
.account-state { gap: 5px; margin-top: 5px; color: #94a3b8; font-size: 10px; }
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: #64748b; }
.state-dot.is-connected { background: #22c55e; box-shadow: 0 0 7px #22c55e; }
.state-dot.is-disconnected { background: #ef4444; }
.account-run { align-self: center; min-width: 58px; height: 34px; padding: 0 10px; border-radius: 9px; color: #dbeafe; background: #1d4ed8; font-size: 11px; font-weight: 800; }
.account-run.is-current { color: #86efac; background: rgba(22, 101, 52, .36); }
.empty-copy { padding: 22px 10px; color: #64748b; text-align: center; font-size: 12px; }

.script-kicker { display: block; margin-bottom: 3px; color: #64748b; font-size: 9px; text-transform: uppercase; }
.status-pill { padding: 5px 8px; border-radius: 999px; color: #cbd5e1; background: #1e293b; font-size: 10px; font-weight: 800; }
.status-pill.is-connected { color: #86efac; background: rgba(22, 101, 52, .4); }
.script-card { padding: 14px; border: 1px solid rgba(148, 163, 184, .16); border-radius: 14px; background: rgba(15, 23, 42, .72); }
.script-card h3 { margin: 0; font-size: 15px; }
.script-card > div > p { margin: 5px 0 14px; color: #7f8da3; font-size: 11px; }
.switch-row { justify-content: space-between; min-height: 42px; border-top: 1px solid rgba(148, 163, 184, .12); color: #cbd5e1; font-size: 12px; }
.switch-row input { width: 18px; height: 18px; accent-color: #3b82f6; }
.script-note { margin: 12px 0 0; color: #64748b; font-size: 10px; line-height: 1.55; }

#xyzwWorkspaceNotice {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  z-index: 2147483647;
  max-width: calc(100vw - 32px);
  padding: 9px 13px;
  transform: translateX(-50%);
  border-radius: 999px;
  color: #e2e8f0;
  background: rgba(15, 23, 42, .96);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .4);
  font-size: 12px;
}

@media (max-width: 520px) {
  #xyzwControlPanel {
    top: calc(env(safe-area-inset-top, 0px) + 62px);
    right: 6px;
    width: calc(100vw - 12px);
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 70px);
    border-radius: 18px;
  }
  #xyzwPortalLauncher { top: calc(env(safe-area-inset-top, 0px) + 8px); right: 8px; }
}
